All Products
Search
Document Center

Tablestore:Update the configurations of a table

Last Updated:Nov 14, 2024

This topic uses parameters and sample code to describe how to use Tablestore SDK for Python to update the configurations of a table. You can update the time to live (TTL), max versions, and max version offset of a data table. You can also update the reserved read and write throughput of a data table in a high-performance instance.

Prerequisites

API operation

"""
Update the configurations of a data table by using table_options or reserved_throughput. 
"""
def update_table(self, table_name, table_options, reserved_throughput):

Parameters

For more information, see Parameters.

Examples

Update the configurations of a data table

The following sample code provides an example on how to update the configurations of a data table.

# Create a table_options instance. Set the TTL of data in the table to 31,536,000 seconds. If the retention period of data in the table exceeds the TTL value, the data is automatically deleted. Specify that up to five versions of data in each attribute column of the table can be retained and the maximum difference between the current system time and the specified data version when the data is written is one day. 
table_options = TableOptions(31536000, 5, 86400)

try:
    # Call the UpdateTable operation to update the reserved read or write throughput of the table. 
    ots_client.update_table('SampleTable', table_options, None)
    # If no exception is thrown, the update is successful. 
    print("update table succeeded")
except Exception:
    # If an exception is thrown, the update fails. Handle the exception. 
    print("update table failed")

Update the reserved throughput of a data table in a high-performance instance

The following sample code provides an example on how to update the reserved throughput of a data table in a high-performance instance.

# Set the new reserved read throughput to 1 and the new reserved write throughput to 1. You can set the reserved read and write throughput only to 0 for a data table in a capacity instance. 
reserved_throughput = ReservedThroughput(CapacityUnit(1, 1))

try:
    client.update_table('<TABLE_NAME>', None, reserved_throughput)
    print("update table succeeded.")
except Exception:
    print("update table failed.")

References

  • For more information about the API operation, see UpdateTable.

  • After you update the configurations of a table, you can perform the following operations: