All Products
Search
Document Center

Tablestore:Lifecycle management

Last Updated:Sep 22, 2026

The time to live (TTL) is an attribute of a search index that specifies the data retention period. Tablestore automatically deletes data that exceeds its retention period to reduce storage usage and lower storage costs.

Usage notes

To use the lifecycle management feature, you must disable the UpdateRow write operation for the data table.

  • This requirement prevents data inconsistency between the data table and the search index.

    A data table's TTL is applied per attribute column, but a search index's TTL is applied to the entire row. If you use an UpdateRow operation, Tablestore might delete some columns from the data table while the corresponding row remains in the search index, causing them to become out of sync.

    If you need to update data, use the PutRow operation to overwrite the entire row instead.

  • The TTL for a search index, specified in seconds, can be -1 or a positive 32-bit integer. A value of -1 means the data is stored permanently. The maximum value is approximately 68 years.

  • The TTL of a search index is independent of the data table's TTL. The TTL value of the search index must be less than or equal to the TTL value of the data table. When decreasing both TTLs, reduce the search index TTL first, and then reduce the data table TTL.

  • Tablestore automatically cleans up expired data from search indexes daily. You can still query data that has expired until it is removed during this cleanup process.

  • After you update the TTL for a data table and a search index, Tablestore removes any newly expired data during the next cleanup cycle.

Procedure

You can set the time to live (TTL) for a search index by using the console or an SDK. The UpdateRow operation must remain disabled on the data table to use this feature.

Console

  1. Disable the UpdateRow write operation for the data table.

    1. On the Basic Information tab of the data table, click Modify Attributes.

    2. In the Modify Attributes dialog box, set No to No, select the check box for the risk notification, and then click OK.

  2. Set the time to live (TTL) for the search index.

    After disabling the UpdateRow operation for the data table, you can set the TTL on a new or existing search index.

    New index

    1. On the Indexes tab of the data table, click Create Search Index.

    2. In the Create Index dialog box, set the index name and schema generation method.

    3. Turn on the Advanced Settings switch, set the Time to Live, and then click OK.

      Set Time to Live to -1 to prevent data from expiring.

    Existing index

    1. On the Indexes tab of the data table, find the target search index and click Index Details in the Actions column.

    2. In the Index Details dialog box, click Modify, update the Time to Live value, and then click Modify.

      The Time to Live value is in seconds. The minimum is 86,400 (one day), or you can set it to -1 to prevent data from expiring. The search index TTL must not exceed the data table TTL.

  3. To expire data from the data table itself, you must set its TTL separately.

    1. On the Basic Information tab of the data table, in the Description section, click Modify Attributes.

    2. In the Modify Attributes dialog box, set the time to live as needed, and then click OK.

SDK

You can use the Java SDK or Go SDK to manage the data lifecycle. The following example uses the Java SDK.

  1. Disable table updates with UpdateRow.

    The following example disables UpdateRow updates for example_table.

    String tableName = "example_table";
    UpdateTableRequest request = new UpdateTableRequest(tableName);
    TableOptions tableOptions = new TableOptions();
    tableOptions.setAllowUpdate(false);
    request.setTableOptionsForUpdate(tableOptions);
    
    client.updateTable(request);
  2. Configure the search index TTL.

    Choose an option based on whether the search index exists.

    New index

    Set a seven-day TTL when you create a search index.

    String tableName = "example_table";
    String indexName = "example_index";
    IndexSchema indexSchema = new IndexSchema();
    indexSchema.setFieldSchemas(Arrays.asList(
            new FieldSchema("category", FieldType.KEYWORD),
            new FieldSchema("price", FieldType.LONG)));
    
    CreateSearchIndexRequest request = new CreateSearchIndexRequest();
    request.setTableName(tableName);
    request.setIndexName(indexName);
    request.setIndexSchema(indexSchema);
    request.setTimeToLiveInDays(7);
    
    client.createSearchIndex(request);

    Existing index

    Update the TTL of an existing search index to seven days.

    String tableName = "example_table";
    String indexName = "example_index";
    UpdateSearchIndexRequest request =
            new UpdateSearchIndexRequest(tableName, indexName);
    request.setTimeToLiveInDays(7);
    
    client.updateSearchIndex(request);
  3. Configure the table TTL if needed.

    The following example sets the TTL of example_table to seven days. Run this operation before or after configuring the search index TTL based on the TTL constraint described above.

    String tableName = "example_table";
    UpdateTableRequest request = new UpdateTableRequest(tableName);
    TableOptions tableOptions = new TableOptions();
    tableOptions.setTimeToLiveInDays(7);
    request.setTableOptionsForUpdate(tableOptions);
    
    client.updateTable(request);