To automatically clean up historical data in a time series table, you can use the data lifecycle (TTL) feature. This helps you efficiently manage your time series data, reduce storage usage, and lower storage costs. After you configure a TTL, you can modify its value if you want to extend the data retention period.
Precautions
-
Deleted data cannot be recovered. Proceed with caution.
Before you configure a TTL to clean up historical data, back up the data if needed. You can use the Data Integration service in DataWorks to export time series data to OSS. For more information, see Synchronize data to OSS.
-
Before you modify the TTL, you can call the DescribeTimeseriesTable operation to view the current data lifecycle setting.
Data lifecycle
In the time series model, data includes time series metadata and time series data, which are stored in a time series metadata table and a time series data table, respectively. Tablestore provides separate data lifecycles for time series metadata and time series data.
Time series table data lifecycle
The data lifecycle for a time series table is an attribute of the time series data table. It specifies the data retention period in seconds. When the age of the time series data exceeds the configured TTL, the system automatically and asynchronously deletes the expired data.
For example, if a table's TTL is set to 86400 (one day), then at 2016-07-21 00:00:00 UTC+8, all time series data from before 2016-07-20 00:00:00 UTC+8 expires. The system then automatically and asynchronously deletes the expired data.
When you create a time series table, if you do not set a TTL, the system uses the default value of -1, which means the data never expires. You can also define a custom TTL. After you create the table, you can call the UpdateTimeseriesTable operation to modify the TTL.
Expired data is considered invalid and cannot be queried, even if the system has not yet physically deleted it.
-
If you decrease the TTL, some data in the time series table may immediately expire. The system asynchronously deletes this expired data.
-
If you increase the TTL, data that had expired under the old TTL but is still within the new TTL's retention period may become queryable again, provided the system has not yet deleted it.
Time series metadata lifecycle
The data lifecycle for time series metadata is an attribute of the time series metadata table. It specifies the retention period for the metadata in seconds. When the age of the time series metadata exceeds the configured TTL, the system automatically and asynchronously deletes the expired metadata. This process does not delete the corresponding time series data.
If time series metadata expires but the corresponding time series data has not, you can still query the time series data by specifying its time series identifier in a GetTimeseriesData API call.
When you create a time series table, if you do not set a TTL for its metadata, the system uses the default value of -1, which means the metadata never expires. You can also define a custom TTL. After you create the table, you can call the UpdateTimeseriesTable operation to modify the TTL.
The time series metadata includes an updatable attribute column named _attributes. However, you can update this attribute only when the data lifecycle for the time series metadata is set to -1, which means the metadata never expires.
If you change the data lifecycle for time series metadata from -1 to a value of 7 days or more, ensure your business logic does not require updating time series metadata attributes. You must also set Whether to Update Attributes of Time Series Metadata to No.
To set Whether to Update Attributes of Time Series Metadata to Yes, you must set the TTL of Time Series Metadata to -1.
Expired metadata is considered invalid and cannot be searched, even if the system has not yet physically deleted it.
-
If you decrease the TTL, some metadata in the time series metadata table may immediately expire. The system asynchronously deletes this expired metadata.
-
If you increase the TTL, metadata that had expired under the old TTL but is still within the new TTL's retention period may become searchable again, provided the system has not yet deleted it.
Methods
You can configure the data lifecycle when you create a time series table or modify it after the table is created. This section shows how to modify the data lifecycle for an existing table by using the console, CLI, or an SDK.
-
For information about how to configure the data lifecycle when you create a table, see Manage time series tables.
-
The supported features may vary based on the method that you use.
Console
CLI
SDK
FAQ
Related documents
The analytical store is a low-cost storage engine optimized for time series scenarios. You can use the analytical store to store time series data cost-effectively and perform fast queries and analysis.
icon next to Data Lifecycle.
icon next to TTL of Time Series Metadata.