MaxCompute provides the lifecycle management function to facilitate the release of storage space and simplify data reclamation.
You can specify the lifecycle when you create a table. The lifecycle can only be set
for a table rather than a partition. For more information, see Table operations.
- In MaxCompute, once data in a table is modified, the
LastDataModifiedTime
value is updated. Therefore, MaxCompute determines whether to reclaim this table based on theLastDataModifiedTime
value and lifecycle. - For a non-partitioned table, if the data remains unchanged for
days
after the last data modification, MaxCompute automatically executes a statement such asDROP TABLE
to reclaim the table. - For a partitioned table, MaxCompute determines whether to reclaim a partition based
on its
LastDataModifiedTime
value. - Unlike non-partitioned tables, a partitioned table is not deleted after the last partition is reclaimed.
- Instead of deleting the lifecycle configured for a non-partitioned table, you can only modify the lifecycle setting. The lifecycle configured for a specific partition in a partitioned table can be deleted.
Change the lifecycle configured for a table
Syntax
ALTER TABLE table_name SET lifecycle days;
Description: used to change the lifecycle configured for a table.
Parameters
- table_name: the name of the table whose lifecycle setting you want to modify.
- days: the lifecycle duration, which must be a positive integer in days.
Example
-- Create a table named test_lifecycle with a lifecycle of 100 days.
CREATE TABLE test_lifecycle(key string) lifecycle 100;
-- Change the lifecycle of test_lifecycle to 50 days.
ALTER TABLE test_lifecycle SET lifecycle 50;
Disable or restore the lifecycle feature
Syntax
ALTER TABLE table_name [partition_spec] ENABLE|DISABLE LIFECYCLE;
Description: used to enable or disable the lifecycle feature for a table or a specific partition in a table.
Parameters
- table_name: the name of the table.
- partition_spec: the name of the partition.
- DISABLE LIFECYCLE: used to disable the lifecycle feature for the table or partition.
- It prevents the reclamation of a table and its partitions based on the lifecycle feature.
This parameter has a higher priority than
partition_spec enable lifecycle
. - After the lifecycle feature of a table is disabled, the table lifecycle setting and the ENABLE and DISABLE tags of partitions in the table are retained.
- After the lifecycle feature of a table is disabled, you can still modify the lifecycle settings of the table and its partitions.
- It prevents the reclamation of a table and its partitions based on the lifecycle feature.
This parameter has a higher priority than
- ENABLE LIFECYCLE: used to enable the lifecycle feature for the table or partition.
- After the lifecycle feature is enabled again, a table and its partitions can be reclaimed based on the lifecycle feature. By default, the lifecycle settings of the current table and its partitions are used.
- Before you enable the lifecycle feature for a table, you can modify the lifecycle settings of the table and its partitions as needed. This prevents data from being mistakenly reclaimed due to the use of previous settings.
Example
-- Disable the lifecycle feature for table trans.
ALTER TABLE trans DISABLE LIFECYCLE;
-- Disable the lifecycle feature for the dt='20141111' partition in table trans.
ALTER TABLE trans PARTITION(dt='20141111') DISABLE LIFECYCLE;