全部產品
Search
文件中心

Tablestore:更新表配置

更新時間:Aug 05, 2026

使用 Python SDK 更新資料表的資料生命週期、版本、更新方式和預留讀寫輸送量。

前提條件

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

功能說明

調用 update_table 方法更新表配置。table_options 和 reserved_throughput 至少設定一項。

def update_table(
    self,
    table_name,
    table_options=None,
    reserved_throughput=None,
)

以下樣本將 example_table 的資料生命週期更新為 7 天,並禁止通過 update_row 方法更新資料。

table_options = TableOptions(
    time_to_live=604800,
    max_version=1,
    max_time_deviation=86400,
    allow_update=False,
)

client.update_table(
    "example_table",
    table_options=table_options,
)

參數說明

update_table 方法包含以下參數。

名稱

類型

說明

table_name(必選)

str

資料表名稱。

table_options(可選)

TableOptions

待更新的表配置。與 reserved_throughput 至少設定一項。

reserved_throughput(可選)

ReservedThroughput

待更新的預留讀寫輸送量。與 table_options 至少設定一項。

表配置

table_options 的類型為 TableOptions,包含以下參數。

名稱

類型

說明

time_to_live(可選)

int

資料生命週期,單位為秒。設定為 -1 表示資料永不到期;設定為其他值時,最小值為 86400(1 天),超出生命週期的資料將被自動清除。使用多元索引或二級索引時,必須設定為 -1,或將 allow_update 設定為 False。

max_version(可選)

int

每個屬性列最多保留的版本數。使用多元索引或二級索引時,必須設定為 1。

max_time_deviation(可選)

int

有效版本偏差,單位為秒。寫入資料的時間戳記與系統目前時間的差值必須在有效版本偏差範圍內。屬性列資料的有效版本範圍為 [max(資料寫入時間-有效版本偏差, 資料寫入時間-資料生命週期), 資料寫入時間+有效版本偏差)。

allow_update(可選)

bool

是否允許通過 update_row 方法更新資料。設定為 False 時,無法通過 update_row 方法更新資料。

預留讀寫輸送量

reserved_throughput 的類型為 ReservedThroughput,包含以下參數。

名稱

類型

說明

capacity_unit(必選)

CapacityUnit

預留讀寫輸送量,單位為 CU。僅 CU 模式的高效能型執行個體支援設定非零值。

傳回值

UpdateTableResponse 包含以下商務資訊。

欄位

類型

說明

table_options

TableOptions

更新後的表配置。

reserved_throughput_details

ReservedThroughputDetails

當前預留讀寫輸送量,以及最近一次上調和下調的時間。

情境樣本

更新預留讀寫輸送量

以下樣本將 example_table 的預留讀寫輸送量設定為 0 CU。

reserved_throughput = ReservedThroughput(
    CapacityUnit(read=0, write=0)
)

client.update_table(
    "example_table",
    reserved_throughput=reserved_throughput,
)