A method for aggregation and optimization of time-series data, comprising the following steps: writing time-series data records into a database, forming a time-series database file, wherein the time-series database file comprises a data file and an index file, the data file comprises multiple data blocks, the index file comprises index blocks, and each index block corresponds to one data block and contains an offset of the corresponded one data block in the data file; scanning an index file according to a start-end time period, extracting all index blocks of the time series that need to be aggregated that meet the start-end time period conditions, storing the extracted all index blocks in a cache area of RAM, and then sorting the index blocks stored in the cache area of RAM according to the offset of data block recorded by the index block in the data file; and scanning the data file according to a data block order corresponding to the sorted index blocks, performing specified reading and calculating on each data block, and aggregating calculation results; the method further comprising writing the time-series data records to RAM before writing them to the database; when RAM occupation rate reaches a certain proportion or every certain time, time-series data cached by the RAM is written to a disk; a step of writing time-series data cached by the RAM to a disk comprises: sorting the data of each time series by time in the RAM; for each time-series data, writing data in RAM to a data file in an appended mode according to a setting of the data block size to generate one or more data blocks; and for each new data block, including data block information containing a start time, an end time, and the number of records into one new index block, and writing it to the index file. regenerating a new block index file each time when the data in RAM is written to the disk. writing time-series data records into a database, forming a time-series database file, wherein the time-series database file comprises a data file and an index file, the data file comprises multiple data blocks, the index file comprises index blocks, and each index block corresponds to one data block and contains an offset of the corresponded one data block in the data file; scanning an index file according to a start-end time period, extracting all index blocks of the time series that need to be aggregated that meet the start-end time period conditions, storing the extracted all index blocks in a cache area of RAM, and then sorting the index blocks stored in the cache area of RAM according to the offset of data block recorded by the index block in the data file; and scanning the data file according to a data block order corresponding to the sorted index blocks, performing specified reading and calculating on each data block, and aggregating calculation results; the method further comprising writing the time-series data records to RAM before writing them to the database; when RAM occupation rate reaches a certain proportion or every certain time, time-series data cached by the RAM is written to a disk; a step of writing time-series data cached by the RAM to a disk comprises: sorting the data of each time series by time in the RAM; for each time-series data, writing data in RAM to a data file in an appended mode according to a setting of the data block size to generate one or more data blocks; and for each new data block, including data block information containing a start time, an end time, and the number of records into one new index block, and writing it to the index file. regenerating a new block index file each time when the data in RAM is written to the disk. sorting the data of each time series by time in the RAM; for each time-series data, writing data in RAM to a data file in an appended mode according to a setting of the data block size to generate one or more data blocks; and for each new data block, including data block information containing a start time, an end time, and the number of records into one new index block, and writing it to the index file. regenerating a new block index file each time when the data in RAM is written to the disk.