If you want the historical data in a time series table to be automatically deleted, you can configure the time to live (TTL) to manage time series data. This helps you save storage space and reduce storage costs. After you configure the TTL for time series data, you can modify the TTL to extend the data retention period.
Usage notes
The data cannot be recovered after it is deleted. Proceed with caution.
If you need to back up historical data before you configure the TTL to automatically delete the data, you can use the Data Integration service of DataWorks to export time series data to Object Storage Service (OSS). For more information, see Overview.
Before you modify the TTL, you can call the DescribeTimeseriesTable operation to view the TTL of time series data.
TTL
In the TimeSeries model, data consists of the time series metadata and the data of time series tables. The time series metadata is stored in time series metadata tables and the data of time series tables is stored in time series data tables. Tablestore allows you to manage the time series metadata and the data of time series tables by configuring the TTL for the data.
TTL of data in a time series table
As an attribute of a time series data table, the TTL indicates the retention period of data in the time series table. The TTL of data is specified in seconds. When data in the time series table is retained for a period of time that exceeds the specified TTL value, Tablestore automatically deletes the data in asynchronous mode.
For example, you set the TTL for data in a time series data table to 86400 (1 day). At 00:00:00 UTC+8 on July 21, 2016
, the data that was written to the table before 00:00:00 UTC+8 on July 20, 2016
expires. Tablestore automatically deletes the expired data in asynchronous mode.
If you do not specify a TTL value when you create a time series table, the default value -1 is used, which indicates that the data in the time series table never expires. You can also specify a custom TTL value. After a time series table is created, you can call the UpdateTimeseriesTable operation to modify the TTL of data.
If data is retained for a period of time that exceeds the TTL value, the data becomes invalid and you cannot query the data even if the data is not deleted by Tablestore.
When you decrease the TTL value, the retention period of some data in the time series table may exceed the new TTL value. Tablestore asynchronously deletes the expired data.
When you increase the TTL value, you can query the data in the time series table if Tablestore does not delete the data in the table and the data is retained for a period of time that is within the new TTL value.
TTL of time series metadata
As an attribute of a time series metadata table, the TTL indicates the retention period of time series metadata. The TTL of the metadata is specified in seconds. When time series metadata is retained for a period of time that exceeds the specified TTL value, Tablestore automatically deletes the metadata in asynchronous mode. The data in time series tables is not deleted.
If the metadata of a time series expires and the data of the time series does not expire, you can call the GetTimeseriesData operation to query the data in the time series table by specifying the time series identifier.
If you do not specify a TTL value when you create a time series table, the default value -1 is used, which indicates that the data in the time series table never expires. You can also specify a custom TTL value. After a time series table is created, you can call the UpdateTimeseriesTable operation to modify the TTL.
The attributes of time series metadata are stored in the _attributes column. You can update the attributes of time series metadata whose TTL is set to -1. The value -1 indicates that the metadata never expires.
If you want to change the TTL of time series metadata from -1 to a value that is greater than or equal to 604800 (7 days), make sure that you do not need to update the attributes of the time series metadata. In addition, you need to set Whether to Update Attributes of Time Series Metadata to No.
If you set Whether to Update Attributes of Time Series Metadata to Yes, you must set TTL of Time Series Metadata to -1.
If time series metadata is retained for a period of time that exceeds the TTL value, the metadata becomes invalid and you cannot query the metadata even if the metadata is not deleted by Tablestore.
When you decrease the TTL value, the retention period of some time series metadata in the time series metadata table may exceed the new TTL value. Tablestore asynchronously deletes the expired metadata.
When you increase the TTL value, you can query the time series metadata if Tablestore does not delete the metadata and the metadata is retained for a period of time that is within the new TTL value.
Methods
When you create a time series table, you can configure the TTL for the data in the table. You can also modify the TTL after you create a time series table. This topic provides an example on how to modify the TTL after you create a time series table. You can modify the TTL by using the Tablestore console, CLI, or SDKs.
For more information about how to configure TTL when you create a data table, see Operations on a time series table.
The features that are supported vary based on the method that you use to modify the TTL.