全部產品
Search
文件中心

Tablestore:生命週期管理

更新時間:Aug 08, 2026

使用 Tablestore Go SDK 為建立或已有多元索引設定資料生命週期,並按需調整資料表生命週期。

前提條件

安裝Tablestore Go SDK並初始化用戶端。

注意事項

多元索引生命週期取值為 -1 或不小於 86400 的 int32 整數,單位為秒。-1 表示資料永不到期。設定非 -1 值時,必須禁止通過 UpdateRow 更新資料,且多元索引生命週期不能大於資料表生命週期。生命週期到期的資料由後台非同步清理。

操作步驟

完整操作包括禁止通過 UpdateRow 更新資料、設定多元索引生命週期,以及在需要時調整資料表生命週期。調整順序取決於目標值:如果要將多元索引生命週期調大到超過當前資料表生命週期,必須先調巨量資料表生命週期;其他情況下可在設定多元索引後按需調整資料表。

1. 禁止通過 UpdateRow 更新資料

更新資料表配置,將 AllowUpdate 設定為 false。具體操作請參見更新表配置。

2. 設定多元索引生命週期

建立多元索引

ttl := int32(7 * 24 * 60 * 60)
request := &tablestore.CreateSearchIndexRequest{
    TableName:  "example_table",
    IndexName:  "example_index",
    TimeToLive: &ttl,
    IndexSchema: &tablestore.IndexSchema{
        FieldSchemas: []*tablestore.FieldSchema{
            {
                FieldName: proto.String("category"),
                FieldType: tablestore.FieldType_KEYWORD,
                Index:     proto.Bool(true),
            },
        },
    },
}

_, err := client.CreateSearchIndex(request)
if err != nil {
    log.Fatal(err)
}

已有多元索引

ttl := int32(7 * 24 * 60 * 60)
_, err := client.UpdateSearchIndex(&tablestore.UpdateSearchIndexRequest{
    TableName:  "example_table",
    IndexName:  "example_index",
    TimeToLive: &ttl,
})
if err != nil {
    log.Fatal(err)
}

3. 按需調整資料表生命週期

如果業務需要同步修改資料表生命週期,請確保其值不小於多元索引生命週期。具體操作請參見更新表配置。

參數說明

名稱

類型

說明

TimeToLive(可選)

*int32

多元索引資料生命週期,單位為秒。取值為 -1 或不小於 86400 的 int32 整數,-1 表示資料永不到期。建立多元索引時預設值為 -1。