Same-database archiving
When tables in a database become too large, query performance can suffer. If you do not want to migrate data to another database, you can archive historical or infrequently accessed data to other tables within the same database. Data Management (DMS) also provides a feature to clean up the source table after archiving, which improves database performance and query speed. This topic describes how to archive data within the same database.
Data archiving is currently in public preview.
Prerequisites
The database type is a MySQL-family database: ApsaraDB RDS for MySQL, PolarDB for MySQL, or AnalyticDB for MySQL 3.0.
NoteThe MySQL database account must have the REPLICATION CLIENT privilege.
The instance has been added to Data Management (DMS). For more information, see Add a cloud database and Add a database that is not deployed on Alibaba Cloud.
The source table must have a primary key or a unique key.
NoteWe recommend that the table includes a column that records the business modification time. You can use this column as a filter condition for data archiving.
Usage notes
This feature is available for instances in any control mode.
-
Each source table must have a primary or unique key.
NoteYour source tables should contain a timestamp field that indicates when the data was last modified. You can use this field as a filter condition for archiving.
To run scheduled data archiving tasks, the instance must be in the Secure Collaboration or Stable Change control mode. If you only need to run a one-time archiving task, no specific control mode is required.
NoteIf the instance is in Stable Change control mode, we recommend that you enable Secure Agent Access or change the control mode to Secure Collaboration before running a scheduled archiving task to prevent failures caused by an expired instance logon. For more information, see Enable Secure Agent Access and Change the control mode of an instance.
Billing
Archiving data within the same database is free because you do not need to purchase a destination database.
Archive data
Log in to DMS 5.0.
-
In the top navigation bar, choose .
NoteIf you use the DMS console in simple mode, move the pointer over the
icon in the upper-left corner of the DMS console and choose . In the upper-right corner of the page, click Create Data Archiving Ticket.
On the Create Data Archiving Ticket page, configure the following parameters:
Parameter
Required
Description
Task Name
Yes
Enter a descriptive name to easily identify the task later.
Archive Destination
Yes
Select Archive data in the same database.
Source Database
Yes
Search for and select the database.
Archive Configuration
Yes
Table Name: Select the table from which you want to archive data.
Filter Condition (Optional): Enter a condition to filter the data to be archived. For example,
gmt_modified<='${6_month_ago}'.NoteIf you need to use time variables, for example, to archive data older than six months, you must first configure them in the Variable Configuration section.
Click Add (Optional) to add multiple source tables.
Archived Table Mapping
No
You can view information about the archived table in the Archived Table Mapping section, such as the table name, columns, and sharding key.
Variable Configuration
No
If you use custom variables in the Archive Configuration section, you must define them here.
For example, if the time variable is
6_month_ago, the format is yyyy-MM-dd, and the offset is -6 months, the variable${6_month_ago}resolves to 2021-02-11 if the current date is 2021-08-12. For more information about how to configure time variables, see Configure time variables.Post-archive Action
No
Whether to delete archived data from the source tables.
Clean up the archived data of the original table (delete-No Lock): DMS automatically deletes the archived data from the source tables by using the
DELETEstatement. Temporary backup tables are created in the source database to store the archived data. Make sure the source database has enough storage space. After verifying that the archived data is correct, create a Normal Data Modify ticket to clear the temporary backup tables.If you do not select the cleanup option, the archived data remains in the source tables. To delete the data manually:
Create a regular data change ticket to delete the archived data. For more information, see Normal Data Modify.
Create a lock-free change ticket to optimize storage usage. For more information, see Perform lock-free DDL operations.
Execution Mode
Yes
Select an execution mode. The following modes are supported:
One-time: The archive task runs only once after the ticket is approved.
Scheduled: After the ticket is approved, the archive task runs based on the configured schedule. For more information, see Scheduled Execution.
Click Submit Ticket.
After the ticket is approved, the system automatically runs the data archiving task.
If the task fails, go to the execution section of the ticket and click Details in the Actions column to view the task logs and identify the cause of the failure. If the failure is caused by an intermittent issue, such as a network or database connection error, you can click Resume to retry the task.
A status of Task Completed indicates that the data has been successfully archived. You can then query the archived data.
Querying archived data
During the data archiving process, DMS automatically creates a table in the current database to store the archived data. The table name is prefixed with tmp_ and suffixed with the ticket ID.
For example, after data from the orders_test table is archived in the same database, a table named tmp_orders_test_121**** is automatically created.
After the data archive task runs successfully, on the current Ticket Details page, in the Basic Information section, click View on the right side of Destination Database.
After you enter the SQL Console page, in the table list on the left, select and double-click the destination table name, and then click Execute to view the archived data.
NoteThe system automatically creates databases and tables in the archive instance based on the database and table names in the source database. Therefore, the destination database name is the same as the source database name.
Four new columns are added to the archived table without affecting the use of the original data:
Archive information (ticket ID and archive time)
Database name
Table name
Instance ID (the ID assigned when the instance is added to DMS, corresponding to the actual instance ID)