Data Lifecycle Management (DLM) automatically archives cold data by transferring infrequently accessed partitions from PolarStore to Object Storage Service (OSS) in CSV format. This reduces storage costs while keeping archived data queryable.
Prerequisites
Before you begin, ensure that you have:
A PolarDB for MySQL 8.0.2 cluster with minor version 8.0.2.2.9 or later. To check your version, see Query the version number.
Cold data archiving enabled. If it is not enabled, the following error is reported when you create a DLM policy:
ERROR 8158 (HY000): [Data Lifecycle Management] DLM storage engine is not support. The value of polar_dlm_storage_mode is OFF.
On clusters running minor version 8.0.2.2.11.1 or later, DLM does not record binary logs.
Limitations
DLM supports only partitioned tables that use RANGE COLUMNS partitioning without subpartitions.
DLM cannot be used on tables with a global secondary index (GSI).
DLM policies cannot be modified. To change a policy, drop the existing policy and create a new one.
Avoid Data Definition Language (DDL) operations on a table that has an active DLM policy, such as adding or removing columns or modifying column types. Such operations make the schema of the archived table inconsistent with the source table, which prevents subsequent archiving jobs from parsing the data correctly. To perform DDL operations, drop the DLM policy first. When you create a new policy afterward, use a different archived table name.
DLM policies are not shown in
SHOW CREATE TABLEoutput. View all policies in the mysql.dlm_policies system table.Use the interval range partitioning feature together with DLM to automatically extend partitions while archiving data from older partitions to OSS.
Interval range partitioning requires minor version 8.0.2.2.0 or later.
Specify DLM settings in
CREATE TABLEorALTER TABLEstatements.
Usage notes
Archived data on OSS is read-only and has lower query performance than local data. Test query performance against your archived data before relying on it in production.
After a partition is archived to OSS, the data in that partition is read-only and DDL operations on the partitioned table are blocked.
Data transferred to OSS is not included in backups and does not support point-in-time restore (PITR).
Choose an archiving mode
DLM supports three archiving modes. Choose based on whether you need to retain and query the cold data.
| Mode | What happens | Data retained | Queryable after archiving |
|---|---|---|---|
TIER TO TABLE | Cold partitions are merged into a single OSS external table | Yes | Yes, as a single table |
TIER TO PARTITION | Each cold partition is moved to OSS individually, becoming a CSV partition in the same table | Yes | Yes, as part of a hybrid partitioned table |
TIER TO NONE | Cold partitions are deleted | No | No |
Use TIER TO TABLE when you want a consolidated archive table with optional query acceleration via OSS_FILE_FILTER. Use TIER TO PARTITION when you need to keep cold data accessible as part of the original table structure. Use TIER TO NONE to discard data that no longer needs to be retained.
TIER TO PARTITIONis in canary release. To use it, go to Quota Center, find the quotapolardb_mysql_hybrid_partition, and click Request in the Actions column. This mode requires minor version 8.0.2.2.17 or later, and the total number of partitions in the table must not exceed 8,192.
Partition design guidance
Align your partition granularity with your DLM threshold to get the most predictable archiving behavior.
Partition by year when your data retention window spans multiple years and your
PARTITIONS OVERthreshold is low (for example, 3–5 partitions). One partition per year keeps partition counts manageable and archives in year-sized chunks.Partition by month when you need finer-grained control — for example, to archive data that is 6 months old rather than 1–2 years old. Set your
PARTITIONS OVERthreshold to match the number of months you want to keep hot.
Combining interval range partitioning with DLM lets the system automatically create new partitions as data grows while archiving older ones, so you never need to manually manage partition boundaries.
Syntax
Create a DLM policy
Attach a DLM policy when creating or altering a table:
With CREATE TABLE:
CREATE TABLE [IF NOT EXISTS] tbl_name
(create_definition,...)
[table_options]
[partition_options]
[dlm_add_options]
dlm_add_options:
DLM ADD
[(dlm_policy_definition [, dlm_policy_definition] ...)]
dlm_policy_definition:
POLICY policy_name
[TIER TO TABLE | TIER TO PARTITION | TIER TO NONE]
[ENGINE [=] engine_name]
[STORAGE SCHEMA_NAME [=] storage_schema_name]
[STORAGE TABLE_NAME [=] storage_table_name]
[STORAGE [=] OSS]
[READ ONLY]
[COMMENT 'comment_string']
[EXTRA_INFO 'extra_info']
ON [(PARTITIONS OVER num)]With ALTER TABLE:
ALTER TABLE tbl_name
[alter_option [, alter_option] ...]
[partition_options]
[dlm_add_options]
dlm_add_options:
DLM ADD
[(dlm_policy_definition [, dlm_policy_definition] ...)]
dlm_policy_definition:
POLICY policy_name
[TIER TO TABLE | TIER TO PARTITION | TIER TO NONE]
[ENGINE [=] engine_name]
[STORAGE SCHEMA_NAME [=] storage_schema_name]
[STORAGE TABLE_NAME [=] storage_table_name]
[STORAGE [=] OSS]
[READ ONLY]
[COMMENT 'comment_string']
[EXTRA_INFO 'extra_info']
ON [(PARTITIONS OVER num)]Policy parameters:
| Parameter | Required | Description |
|---|---|---|
tbl_name | Yes | The table name. |
policy_name | Yes | The policy name. |
TIER TO TABLE | — | Archives cold partitions to a single OSS external table. |
TIER TO PARTITION | — | Moves each cold partition to OSS individually. Requires minor version 8.0.2.2.17 or later (Enterprise Edition clusters require 8.0.2.2.25 or later). See the note in Choose an archiving mode for additional requirements. |
TIER TO NONE | — | Deletes cold partitions without archiving. |
ENGINE [=] engine_name | No | The storage engine for archived data. Currently, only CSV is supported. |
STORAGE SCHEMA_NAME [=] storage_schema_name | No | The database where the archive table resides. Defaults to the current table's database. |
STORAGE TABLE_NAME [=] storage_table_name | No | The name of the archive table. Defaults to <current_table_name>_<policy_name>. |
STORAGE [=] OSS | No | Stores archived data in OSS. This is the default. |
READ ONLY | No | Makes archived data read-only. This is the default. |
COMMENT 'comment_string' | No | A comment for the policy. |
EXTRA_INFO 'extra_info' | No | Specifies OSS_FILE_FILTER settings for the destination OSS table. Format: {"oss_file_filter":"field_name[:filter_type][,field_name[:filter_type]]"}. The only supported filter_type is bloom. This setting takes effect only when the destination table does not yet exist — the system uses it to automatically create the FILE_FILTER property and generate filter data during archiving. If the destination table already exists, the existing file filter is used. |
ON (PARTITIONS OVER num) | Yes | Triggers archiving when the number of partitions exceeds num. |
Manage DLM policies
-- Enable a policy
ALTER TABLE table_name DLM ENABLE POLICY [(dlm_policy_name [, dlm_policy_name] ...)]
-- Disable a policy
ALTER TABLE table_name DLM DISABLE POLICY [(dlm_policy_name [, dlm_policy_name] ...)]
-- Drop a policy
ALTER TABLE table_name DLM DROP POLICY [(dlm_policy_name [, dlm_policy_name] ...)]table_name is the table with the policy. dlm_policy_name is the policy to act on. Specify multiple policy names to act on several policies at once.
Execute a DLM policy
Run a DLM policy on demand with a stored procedure call, or schedule it using a MySQL EVENT.
Run immediately:
-- Execute all DLM policies in the cluster
CALL dbms_dlm.execute_all_dlm_policies();
-- Execute policies on a specific table
CALL dbms_dlm.execute_table_dlm_policies('database_name', 'table_name');Schedule with a MySQL EVENT:
Use the MySQL EVENT feature to run DLM policies on a schedule during your cluster's O&M window. This avoids impacting performance during peak hours.
CREATE
EVENT
[IF NOT EXISTS]
event_name
ON SCHEDULE schedule
[COMMENT 'comment']
DO event_body;
schedule: {
EVERY interval
[STARTS timestamp [+ INTERVAL interval] ...]
}
interval:
quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}
event_body: {
CALL dbms_dlm.execute_all_dlm_policies();
| CALL dbms_dlm.execute_table_dlm_policies('database_name', 'table_name');
}| Parameter | Required | Description |
|---|---|---|
event_name | Yes | The EVENT name. |
schedule | Yes | When and how often the EVENT runs. |
comment | No | A comment for the EVENT. |
event_body | Yes | The DLM procedure call to execute. Use execute_all_dlm_policies() to run all cluster policies (create one EVENT per cluster). Use execute_table_dlm_policies() to run policies for a specific table (create one EVENT per table). |
interval | Yes | The time interval between EVENT executions. |
timestamp | Yes | The start time for the EVENT. |
database_name | Yes | The database where the target table resides. |
table_name | Yes | The table name. |
For the full EVENT syntax reference, see the MySQL EVENT documentation.
Examples
Handle execution errors
DLM policy failures are recorded in mysql.dlm_progress. Query for errors with:
SELECT * FROM mysql.dlm_progress WHERE Archive_stage = "ARCHIVE_ERROR";Check the Extra_info field for the error details. After identifying the cause, either delete the error record or update its Archive_stage to ARCHIVE_COMPLETE. Then run the policy manually:
CALL dbms_dlm.execute_all_dlm_policies();Or wait for the next scheduled execution cycle.
When a policy record has the status ARCHIVE_ERROR, the policy does not run again automatically. This prevents unsafe retries until you have confirmed the cause of the failure and updated the record.