As tables accumulate cold data, keeping it in PolarStore consumes expensive local storage without meaningful query benefit. Cold data archiving moves table data from PolarStore to Object Storage Service (OSS) in CSV or ORC format, freeing local storage while keeping the data queryable through standard SQL — no changes to your application queries are required.
This page covers how to archive standard tables and partitioned tables, enable encryption for archived data, restore data to PolarStore, and delete OSS files.
Prerequisites
Before you begin, make sure you have:
Enabled cold data archiving on your cluster
A cluster version that meets the format requirements:
CSV format
Cluster type Minimum version Cluster Edition MySQL 8.0.1 revision 8.0.1.1.47, or MySQL 8.0.2 revision 8.0.2.2.10 Multi-master Cluster (Limitless) Edition Kernel version 8.0.1.0.13 ORC format
Cluster type Minimum version Cluster Edition Revision 8.0.2.2.30 Multi-master Cluster (Limitless) Edition Revision 8.0.2.2.30
Manual archiving is not recorded in binary logs on clusters running PolarDB for MySQL 8.0.1 (revision 8.0.1.1.33 or later) or 8.0.2 (revision 8.0.2.2.11.1 or later).
Archive a standard table
Archiving a standard table is a table-level operation. The table becomes read-only with the OSS engine, its data files are stored in OSS, and the space it occupied in PolarStore is released. After archiving, query the table using the same SQL statements as before — no changes to your access patterns are required.
Limitations
Supported engines: InnoDB and X-Engine.
InnoDB tables must have a primary key.
Tables with an In-Memory Column Index (IMCI) can only be archived in ORC format, not CSV.
DDL and DML statements cannot run on the table during archiving.
Archiving to a user-created OSS server is not supported.
After archiving, the table is read-only and query performance may decrease. Test query performance after archiving to confirm it meets your requirements.
Syntax
CSV format
Format 1:
ALTER TABLE table_name ENGINE = CSV CONNECTION = 'default_oss_server';Format 2: Your cluster must meet one of the following requirements.
Archiving in CSV format
If the product edition is Cluster Edition, the Milvus version must be one of the following:
MySQL 8.0.1, minor version 8.0.1.1.47 or later.
MySQL 8.0.2, revision version 8.0.2.2.10 or later.
For the Multi-master Cluster (Limitless) Edition, the kernel version must be 8.0.1.0.13 or later.
Archiving in ORC format
For the Cluster Edition, the revision version must be 8.0.2.2.30 or later.
For the Multi-master Cluster (Limitless) Edition, the revision version must be 8.0.2.2.30 or later.
Archiving in X-Engine format
Archiving standard tables:
MySQL 8.0.1 with revision 8.0.1.1.31 or later.
MySQL 8.0.2 with revision 8.0.2.2.12 or later.
Archiving partitioned tables: MySQL 8.0.2 with revision 8.0.2.2.12 or later.
Archiving as an X-Engine column-oriented table: MySQL 8.0.2 with revision 8.0.2.2.33 or later.
ALTER TABLE table_name ENGINE = CSV STORAGE OSS;
ORC format
ALTER TABLE table_name ENGINE = ORC STORAGE OSS;If a file with the same name already exists in OSS, the operation fails with the error:Target file for archived table exists on oss.On clusters running revision 8.0.2.2.29 or later, addFORCE STORAGE OSSto theDROP TABLEstatement to delete the corresponding OSS files when dropping the table schema:
DROP TABLE table_name FORCE STORAGE OSS;Parameters
| Parameter | Description |
|---|---|
table_name | The name of the table to archive to OSS |
Example
Archive table t in the oss_test database to OSS in CSV or ORC format.
Create an InnoDB table with a primary key.
CREATE TABLE t(a int, b int, c int, primary key(a)) ENGINE = INNODB;Insert data.
INSERT INTO t VALUES (1,2,3);Archive the table. CSV format:
ALTER TABLE t ENGINE = CSV CONNECTION = 'default_oss_server';ORC format:
ALTER TABLE t ENGINE = ORC STORAGE OSS;After archiving completes, verify the result:
In the console: Log in to the PolarDB console. On the target cluster page, go to Settings and Management > Data Lifecycle > Data Archive (Cold Data).
With SQL: Query the archived table directly — access patterns remain unchanged. ``
sql SELECT * FROM t;``
Archive partitions to an OSS external table
This approach archives specific partitions of a partitioned table to a new OSS external table. The source InnoDB table continues to hold non-archived partitions, and the archived data can be queried from the OSS external table.
Prerequisites
Cluster version: PolarDB for MySQL 8.0.2 revision 8.0.2.2.25 or later.
Set the cluster parameter
partition_level_mdl_enabledtoONto enable partition-level metadata lock (MDL). For instructions, see Set cluster and node parameters.Set the cluster parameter
loose_use_oss_metatoON. For instructions, see Set cluster and node parameters.
Limitations
The destination OSS table supports CSV format only.
After archiving a partition, the source table must retain at least one InnoDB partition.
Archived data loses its partition information and cannot be directly restored. Use
INSERT INTO ... SELECTto restore the data if needed.Subpartitions cannot be archived individually. Archive the entire first-level partition instead.
Supported first-level partition types:
First-level partition type Second-level partition type Supported LIST Any Yes RANGE Any Yes KEY Any Yes HASH Any No LIST DEFAULT Any Yes, except the DEFAULT partition
Syntax
CALL dbms_dlm.archive_partition2table(
'source_db',
'source_tb',
'source_part',
'archive_db',
'archive_table',
'oss_file_filter'
);Parameters
| Parameter | Description |
|---|---|
source_db | The database containing the source table |
source_tb | The name of the source table |
source_part | The partitions to archive. Separate multiple partition names with commas |
archive_db | The database for the destination OSS table |
archive_table | The name of the destination OSS table |
oss_file_filter | The columns to create an OSS_FILE_FILTER on for query acceleration. See OSS_FILE_FILTER query acceleration |
Behavior based on destination table state:
Destination table does not exist: The table is created automatically. An
OSS_FILE_FILTERis created on the specified columns, with the primary key and partition key added automatically.Destination table exists: Column names and types must match the source table. If they differ, align the schemas using DDL statements before archiving. See DDL for cold data. If the destination table already has an
OSS_FILE_FILTERwith a different definition, the existing one is used.Destination table does not exist but a same-name file exists in OSS: The operation fails with:
ERROR 8181 (HY000): [Data Lifecycle Management] errmsg: Target file for archived table exists on oss, please remove it first, or use flag 'FORCE' to overwrite on existing files.If the residual OSS files are no longer needed, delete them and retry:
-- Delete the residual OSS files. CALL dbms_oss.delete_table_file('test', 'sales_history'); -- Query OK, 0 rows affected (0.76 sec) -- Retry the archiving operation. CALL dbms_dlm.archive_partition2table('test', 'sales', 'p0', 'test', 'sales_history', 'id'); -- Query OK, 0 rows affected (4.24 sec)
Example
Archive the p0 partition of a partitioned sales table to a new OSS table named sales_history.
Create an InnoDB partitioned table and insert data.
DROP TABLE IF EXISTS `sales`; -- Create a RANGE-partitioned table. CREATE TABLE `sales` ( `id` int DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `order_time` datetime NOT NULL, primary key (order_time) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 PARTITION BY RANGE COLUMNS(order_time) INTERVAL(month, 1) (PARTITION p0 VALUES LESS THAN ('2022-01-01') ENGINE = InnoDB, PARTITION p1 VALUES LESS THAN ('2023-01-01 00:00:00') ENGINE = InnoDB, PARTITION p2 VALUES LESS THAN ('2024-01-01 00:00:00') ENGINE = InnoDB); -- Insert 1,000 rows using a batch insert procedure. DROP PROCEDURE IF EXISTS proc_batch_insert; delimiter $$ CREATE PROCEDURE proc_batch_insert(IN begin INT, IN end INT, IN name VARCHAR(20)) BEGIN SET @insert_stmt = concat('INSERT INTO ', name, ' VALUES(? , ?, ?);'); PREPARE stmt from @insert_stmt; WHILE begin <= end DO SET @ID1 = begin; SET @NAME = CONCAT(begin+begin*281313, '@stiven'); SET @TIME = from_days(begin + 738368); EXECUTE stmt using @ID1, @NAME, @TIME; SET begin = begin + 1; END WHILE; END; $$ delimiter ; CALL proc_batch_insert(1, 1000, 'sales');Check the current schema of the
salestable.SHOW CREATE TABLE sales;Expected output:
*************************** 1. row *************************** Table: sales Create Table: CREATE TABLE `sales` ( `id` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `order_time` datetime NOT NULL, PRIMARY KEY (`order_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci /*!50500 PARTITION BY RANGE COLUMNS(order_time) */ /*!99990 800020200 INTERVAL(MONTH, 1) */ /*!50500 (PARTITION p0 VALUES LESS THAN ('2022-01-01') ENGINE = InnoDB, PARTITION p1 VALUES LESS THAN ('2023-01-01 00:00:00') ENGINE = InnoDB, PARTITION p2 VALUES LESS THAN ('2024-01-01 00:00:00') ENGINE = InnoDB, ...) */ 1 row in set (0.03 sec)Archive the
p0partition to the OSS tablesales_history, with anOSS_FILE_FILTERon theidcolumn.CALL dbms_dlm.archive_partition2table('test', 'sales', 'p0', 'test', 'sales_history', 'id'); -- Query OK, 0 rows affected (1.86 sec)Verify the schema of the created
sales_historytable.SHOW CREATE TABLE sales_history;Expected output:
*************************** 1. row *************************** Table: sales_history Create Table: CREATE TABLE `sales_history` ( `id` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `order_time` datetime DEFAULT NULL, PRIMARY KEY (`order_time`) ) /*!99990 800020213 STORAGE OSS */ ENGINE=CSV DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci /*!99990 800020204 NULL_MARKER='NULL' */ /*!99990 800020223 OSS META=1 */ /*!99990 800020224 OSS_FILE_FILTER='id,order_time' */ 1 row in set (0.00 sec)Query the archived data.
Enable OSS_FILE_FILTER query acceleration to improve query performance on the OSS table.
SELECT * FROM sales_history WHERE id = 100;Expected output:
+------+-----------------+---------------------+ | id | name | order_time | +------+-----------------+---------------------+ | 100 | 28131400@stiven | 2021-11-09 00:00:00 | +------+-----------------+---------------------+ 1 row in set (0.24 sec)
Archive partitions in place (hybrid partitioned table)
This feature is in canary release. To enable it, go to Quota Center, find the quota with ID polardb_mysql_hybrid_partition, and click Request.Archiving partitions in place converts specific partitions of an InnoDB table to OSS-backed storage, creating a hybrid partitioned table. The non-archived partitions remain in PolarStore, and the space used by the archived partitions is released automatically.
Prerequisites
Cluster version: PolarDB for MySQL 8.0.2 revision 8.0.2.2.14 or later.
Limitations
Only InnoDB engine partitioned tables are supported.
At least one InnoDB partition must remain in the table. The last InnoDB partition cannot be archived.
DDL operations cannot be performed on a hybrid partitioned table. See Create a hybrid partitioned table for full details.
Archived partition data is read-only. Write operations are not supported on archived partitions.
Subpartitions cannot be archived individually.
The DEFAULT partition of a LIST DEFAULT HASH partitioned table cannot be archived.
HASH and KEY partitioned tables cannot be archived.
An entire partitioned table cannot be archived manually. Archive partitions individually.
Syntax
-- Archive as CSV:
ALTER TABLE table_name CHANGE PARTITION part_name ENGINE = CSV;
-- Archive as ORC:
ALTER TABLE table_name CHANGE PARTITION part_name ENGINE = ORC;If a file with the same name already exists in OSS, the operation fails with:Target file for archived table exists on oss.To overwrite the existing OSS file, addFORCEto the statement: On clusters running revision 8.0.2.2.29 or later,FORCE STORAGE OSSis also supported:
ALTER TABLE table_name CHANGE PARTITION part_name ENGINE = CSV/ORC FORCE;ALTER TABLE table_name CHANGE PARTITION part_name ENGINE = CSV FORCE STORAGE OSS;Parameters
| Parameter | Description |
|---|---|
table_name | The name of the partitioned table |
part_name | The name of the partition to archive |
Example
Archive the p1 and p2 partitions of table t to OSS in CSV format.
Create an InnoDB RANGE-partitioned table.
CREATE TABLE t(a int, b int, c int, primary key(a)) PARTITION BY RANGE(a) (PARTITION p1 VALUES LESS THAN (100), PARTITION p2 VALUES LESS THAN (200), PARTITION p3 VALUES LESS THAN MAXVALUE );Insert data.
INSERT INTO t VALUES (1,1,1), (10,10,10), (100,100,100), (150,150,150), (200,200,200), (1000,1000,1000);Archive the
p1andp2partitions. CSV format:ALTER TABLE t CHANGE PARTITION p1 ENGINE = CSV; ALTER TABLE t CHANGE PARTITION p2 ENGINE = CSV;ORC format:
ALTER TABLE t CHANGE PARTITION p1 ENGINE = ORC; ALTER TABLE t CHANGE PARTITION p2 ENGINE = ORC;After archiving completes, verify the result:
In the console: Log in to the PolarDB console. On the target cluster page, go to Settings and Management > Data Lifecycle > Data Archive (Cold Data).
With SQL: Query the hybrid partitioned table. See Querying hybrid partitions for details.
Enable TDE encryption for archived data
Transparent Data Encryption (TDE) encrypts the data files written to OSS during archiving. The OSS server performs the encryption and decryption transparently — query archived data using SQL as usual, with no extra steps required.
For more information about OSS-side encryption, see Data encryption.
Prerequisites
Manual archiving in CSV or ORC format only.
Cluster version: PolarDB for MySQL 8.0.1 revision 8.0.1.1.47 or later, or 8.0.2 revision 8.0.2.2.27 or later. If your cluster does not meet this requirement, upgrade the minor version.
Syntax
Add ENCRYPTION="Y" to the archiving statement:
ALTER TABLE t1 ENGINE = CSV ENCRYPTION="Y" STORAGE OSS;Restore data from OSS to PolarStore
Restore a standard archived table
Restoring converts the OSS table back to a read-write InnoDB table in PolarStore. The archived data in OSS is deleted after restoration.
An archived OSS table is read-only.INSERT,UPDATE, andDELETEoperations fail with:1036 - Table 't1' is read only. Restore the table to PolarStore before making any modifications.
Syntax
ALTER TABLE table_name ENGINE = engine_name;Parameters
| Parameter | Description |
|---|---|
table_name | The name of the archived OSS table to restore |
engine_name | The engine type to restore to (for example, InnoDB) |
Example
Restore OSS table t in the oss_test database to PolarStore.
ALTER TABLE `oss_test`.`t` ENGINE = InnoDB;After restoration, modify the data as needed, then re-archive the table using either format:
-- Format 1:
ALTER TABLE t ENGINE = CSV CONNECTION = 'default_oss_server';
-- Format 2:
ALTER TABLE t ENGINE = CSV STORAGE OSS;Restore an archived partition
Restoring an archived partition moves its data from OSS back to PolarStore. The cold data in OSS is deleted after restoration.
Syntax
ALTER TABLE table_name REORGANIZE PARTITION part_name INTO (partition_definition);Parameters
| Parameter | Description |
|---|---|
table_name | The name of the table containing the archived partition |
part_name | The name of the partition to restore |
partition_definition | The partition definition, which must match the original definition of the partition being restored |
Example
Restore the p1 partition of partitioned table t from OSS to PolarStore.
ALTER TABLE t REORGANIZE PARTITION p1 INTO (PARTITION p1 VALUES LESS THAN (100));Delete OSS files
This feature requires PolarDB for MySQL 8.0.1 revision 8.0.1.1.42 or later, or 8.0.2 revision 8.0.2.2.23 or later. If your cluster does not meet this requirement, upgrade the minor version.
Dropping an archived table or restoring it to PolarStore does not automatically delete the underlying files in OSS. Once you confirm the data is no longer needed, delete the files manually:
CALL dbms_oss.delete_table_file('database_name', 'table_name');OSS file deletion is asynchronous — files are fully removed only after all cluster nodes stop depending on them. If the command fails with OSS files are still in use, wait a moment and retry.
What's next
To query archived data faster, enable OSS_FILE_FILTER query acceleration.
To manage archived data with DDL, see DDL for cold data.
To work with hybrid partitioned tables, see Create a hybrid partitioned table.