All Products
Search
Document Center

Tablestore:Lifecycle management

Last Updated:Jun 20, 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. Prohibit the UpdateRow operation on a data table.

    The following sample code provides an example on how to prohibit the UpdateRow operation on a data table:

    public static void disableTableUpdate(SyncClient client) {
        UpdateTableRequest updateTableRequest = new UpdateTableRequest("<TABLE_NAME>");
        TableOptions options = new TableOptions();
        // Prohibit the UpdateRow operation on a data table to prevent impacts on your business. 
        options.setAllowUpdate(false);
        updateTableRequest.setTableOptionsForUpdate(options);
        client.updateTable(updateTableRequest);
    }
  2. Specify the TTL for the search index.

    After the UpdateRow operation on a data table is prohibited, you can specify the TTL for an existing search index or when you create a search index.

    Specify the TTL when you create a search index

    The following sample code provides an example on how to create a search index with the TTL specified. In this example, the search index consists of the following columns: the Col_Keyword column of the String type and the Col_Long column of the Long type. The TTL of the search index is seven days.

    // Use Tablestore SDK for Java V5.12.0 or later. 
    public static void createIndexWithTTL(SyncClient client) {
        int days = 7;
        CreateSearchIndexRequest createRequest = new CreateSearchIndexRequest();
        // Specify the name of the data table. 
        createRequest.setTableName("<TABLE_NAME>");
        // Specify the name of the search index. 
        createRequest.setIndexName("<SEARCH_INDEX_NAME>");
        IndexSchema indexSchema = new IndexSchema();
        indexSchema.setFieldSchemas(Arrays.asList(
                // Specify the names and types of the fields. 
                new FieldSchema("Col_Keyword", FieldType.KEYWORD), 
                new FieldSchema("Col_Long", FieldType.LONG)));
        createRequest.setIndexSchema(indexSchema);
        // Specify the TTL for the search index. 
        createRequest.setTimeToLiveInDays(days);
        // Create the search index. 
        client.createSearchIndex(createRequest);
    }

    Change the TTL of an existing search index

    The following sample code provides an example on how to set the TTL of an existing search index to 7 days:

    // Use Tablestore SDK for Java V5.12.0 or later. 
    public static void updateIndexWithTTL(SyncClient client) {
        int days = 7;
        UpdateSearchIndexRequest updateSearchIndexRequest = new UpdateSearchIndexRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>");
        // Change the TTL of a search index. 
        updateSearchIndexRequest.setTimeToLiveInDays(days);
        client.updateSearchIndex(updateSearchIndexRequest);
    }
  3. The TTL of a data table is independent of the TTL of the search index that is created for the data table. You can specify the TTL for a data table.

    The following sample code provides an example on how to set the TTL of a data table to 7 days:

    public static void updateTableTTL(SyncClient client) {
        int days = 7;
        UpdateTableRequest updateTableRequest = new UpdateTableRequest("<TABLE_NAME>");
        TableOptions options = new TableOptions();
        options.setTimeToLiveInDays(days);
        updateTableRequest.setTableOptionsForUpdate(options);
        client.updateTable(updateTableRequest);
    }