The standard data change feature in Data Management Service (DMS) lets you run SQL statements to modify data in a database. You can run statements such as INSERT, UPDATE, DELETE, and TRUNCATE immediately or on a schedule. This topic describes how to submit a standard data change ticket.
Operation overview
-
Configure and submit a standard data change ticket
Select the database or instance that you want to change. Enter the SQL statements for the change or upload an SQL attachment.
-
Precheck
During the precheck phase, DMS verifies the SQL statements that you submitted. DMS checks whether the SQL type is valid for a standard data change and whether you have the required permissions.
-
Approve the ticket
During the approval phase, DMS checks whether the SQL statements will affect database performance. DMS also checks whether the user who submitted the ticket is allowed to run the SQL statements.
-
Execute the data change
The submitted SQL statements for the change are run. If the change is incorrect or you need to roll back the SQL statements for business reasons, DMS lets you create a rollback ticket. This helps you quickly restore the original data after the change is complete.
Prerequisites
The control mode of the instance must be Stable Change or Security Collaboration. For more information, see Control modes.
Notes
-
You can close a ticket regardless of its approval status. This prevents the accidental execution of a task after the ticket is approved.
-
You can manage data changes in the staging environment using tickets. Tickets provide safeguards such as data backups and row count checks. If an operation does not produce the expected result, you can quickly restore the data.
NoteIf you are concerned that ticket approval may affect development efficiency, you can configure approval-free settings. For more information, see SQL change.
-
If you have configured logical databases, logical tables, and routing algorithms, you can submit a single ticket for sharding changes. You do not need to submit separate tickets for each physical database and table.
-
If you use a routing algorithm and the update condition includes a routing field, the statement is automatically routed to the correct physical database and table for execution.
-
The SQL statement runs on each shard one by one in the following scenarios, which can increase the running time: no routing algorithm is configured, the change condition does not include a routing field, or the type or structure definition of the routing field is incorrect.
-
-
DMS automatically generates a backup script attachment only before it executes
UPDATEorDELETEstatements.
Procedure
Step 1: Configure and submit the ticket
Log in to DMS 5.0.
Move the pointer over the
icon in the upper-left corner of the DMS console and choose . NoteIf you use the DMS console in normal mode, choose in the top navigation bar.
-
On the Data Change Ticket Request page, configure the ticket parameters. The following table describes some of the parameters.
Note-
The following example shows how to configure parameters for an instance in Security Collaboration mode. The parameters may vary if you select an instance in Stable Change mode.
-
The feature to change data source instances is being rolled out in phases.
Configuration item
Required
Description
Change Target
Yes
You can select Database or Data Source Instance.
NoteCurrently, you can only select MySQL instances of the following types for data source instance changes: RDS MySQL, PolarDB for MySQL, and AnalyticDB for MySQL.
Database or Data Source Instance
Yes
Search for and select a database or instance for which you have change permissions.
NoteCurrently, you can select only one instance for a data source instance change.
Reason Category
Yes
Select a reason for the data change to make it easier to find later.
NoteAdministrators can configure the list of reason categories in the section. For more information, see Configuration management.
Business Background
Yes
Provide a detailed description of the reason or goal for the change to reduce communication overhead.
Execution Method
Yes
Select an execution method for the ticket:
-
After approval, the submitter executes the operation.
-
Execute automatically after approval.
-
Execute by last approver.
NoteAdministrators can modify the list of execution methods in the section. For more information, see Configuration management.
Affected Rows
Yes
Estimate the number of data rows that this change will affect.
Change SQL
Yes
You can select Text or Attachment.
SQL Text
Yes
This configuration item appears only if you set Change SQL to Text. In the SQL text box, enter the SQL statements that can be directly executed.
Note-
Separate multiple SQL statements with a semicolon (;).
-
If the change target is an instance, you must add the database name before each table name in the SQL statements. Use the format
${dbName}.${tableName}. -
When you submit the ticket, the system automatically checks the SQL syntax. If the syntax is incorrect, you cannot submit the ticket.
Attachment
Yes
This configuration item appears only if you set Change SQL to Attachment. Upload the SQL attachment for the change.
NoteThe attachment can be a .txt, .zip, or .sql file. The maximum file size is 15 MB.
Rollback SQL
No
You can select Text or Attachment.
NoteDMS automatically fills in the rollback SQL information when creating a rollback ticket only if you enter the rollback SQL or upload a rollback file. Otherwise, you must enter the information yourself.
SQL Text
No
This configuration item appears only if you set Rollback SQL to Text. Enter the rollback SQL statements. The rollback SQL is the reverse script of the change SQL.
Attachment
No
This configuration item appears only if you set Rollback SQL to Attachment. Click Upload File to upload the rollback SQL attachment.
NoteThe attachment can be a .txt, .zip, or .sql file. The maximum file size is 15 MB.
Stakeholders
No
The specified stakeholders can view the ticket and collaborate on it. Users who are not stakeholders cannot view the ticket, except for administrators and DBAs.
Ticket Attachment
No
Upload an attachment to provide additional information for the current ticket.
-
-
Click Submit Request.
Step 2: Precheck the SQL
After you submit the ticket, the system automatically performs a precheck. If the precheck fails, modify the SQL statements based on the prompt and try again.
After the precheck passes, the status of each check item (SQL Splitting, Type Check, Permission Check, SQL Review, and Check Scanned Rows) is Passed. The Affected Rows are also displayed. The actual number of affected rows depends on the SQL execution behavior.
Step 3: Approve the ticket
After the precheck passes, click Submit for Approval. In the Notice dialog box, click OK.
The approver in the default approval template for data changes is a DBA. To change the default approval template, see Modify the default approval template.
The Notice dialog box displays validation information, such as the number of physical databases, the number of SQL statements, and the estimated number of affected rows. If the number of affected rows verified by the system is different from the number you entered, a red warning message appears. Confirm the information before you submit the ticket.
Step 4: Execute the change
Execute changes during off-peak hours if possible.
-
After the ticket is approved, click Execute Change. In the Task Settings dialog box, set the task execution parameters, and click Execute.
Note-
When you create the ticket, if you set Execution Method to Execute automatically after approval, the system skips this step.
-
If you restart a paused task, the script resumes execution from where it was paused.
Configuration item
Description
Execution Policy
Select an execution policy:
-
Execute Immediately: The task starts immediately after you click Execute.
-
Scheduled Execution: Specify a start time for the task. For example, run the task at 00:00:00 on May 22, 2024.
NoteThe actual execution time of a scheduled task may have a margin of error of ±1 minute.
Specify End Time
Specify an end time for the task. If the task is not complete by the specified end time, the system stops running the remaining SQL tasks. This prevents tasks from running during peak hours and affecting business operations.
NoteThe actual end time of the task may have a margin of error of ±1 minute.
Enable Global Transaction
Select whether to enable global transactions. This feature is disabled by default.
-
Enable: If the execution fails, all changes are rolled back. This applies only to DML statements, not DDL statements.
-
Disable: SQL tasks are submitted one by one. If a task fails, the execution stops, but no changes are rolled back.
Enable Backup
Select whether to enable backups. This feature is enabled by default. If you enable this feature, you can use the backup file to quickly restore data later.
Note-
Data backup is supported only when you execute UPDATE and DELETE statements.
-
Data backup is not supported for MongoDB and Redis.
-
Enable: Before executing
UPDATEorDELETEstatements, the system automatically generates a backup script attachment.-
If the database is MySQL or MariaDB, a
REPLACE INTObackup statement is generated.NoteMySQL includes: RDS MySQL, PolarDB for MySQL, PolarDB-X, and other MySQL sources.
-
If the database is an engine other than MySQL or MariaDB, an
INSERTbackup statement is generated.
-
-
Disable: No backup attachment is generated.
Enable Primary/Standby Check
After you enable the primary/standby check for the database, you can ensure real-time data synchronization between the primary and standby instances. This improves database high availability and fast disaster recovery.
Grayscale Type
The policy for executing SQL statements in batches.
-
No Grayscale: DMS automatically executes all SQL statements in the task.
-
Pause after the first SQL statement succeeds: After the first SQL statement is successfully executed, DMS automatically pauses the execution. To continue, click Retry. The remaining SQL statements will be executed at once without any further pauses.
-
Pause after each SQL statement succeeds: The execution pauses after each SQL statement. You must manually click Retry to execute the next SQL statement.
NoteThe execution of SQL tasks is monitored by the Security Rules module, specifically the SQL Execution Control section. This includes mechanisms such as database lock timeout before SQL execution, database load checks, and sleep policies after SQL execution. To modify the default detection point settings, see Configure SQL execution control.
-
After the ticket is successfully executed, in the Actions column, click Details to view details such as the execution status, number of executions, number of affected rows, execution script, and logs.
-
After the ticket is successfully executed, you can navigate to the SQL window of the target database to check whether the data change meets your expectations.
-
-
Optional: Create a rollback ticket to quickly restore the original data.
If the data change does not meet your expectations, you can create a rollback ticket or manually submit a standard data change ticket to quickly restore the original data. The following steps show how to create a rollback ticket:
-
In the Execution area of the ticket, click Generate Rollback Ticket to the right of the target task.
-
Select a rollback Source and click OK. The following three rollback sources are supported:
-
Rollback text: The rollback text that you entered when you configured the ticket.
-
Rollback attachment: The rollback attachment that you uploaded when you configured the ticket.
-
Backup file: The backup attachment generated during ticket execution.
NoteTo restore original data using a backup file, you must enable backups before executing the change.
-
-
(Optional): You can modify the rollback text, attachment, or backup file as needed.
-
Rollback text: You can modify it directly in the SQL text box.
-
Rollback attachment or backup file: You can download the attachment to your local computer, modify it, and then re-upload it to the rollback ticket.
-
-
After you confirm that the rollback information is correct, click Submit Request. The subsequent ticket process is the same as that for a standard data change ticket.
-
-
Download the backup file.
You can download the backup file to save it or modify it before you upload it to DMS.
-
In the Actions column, click Download Backup. The backup file contains the following main parts:
-
The original SQL statement for the change.
-
The query SQL statement for the data change.
-
The data change backup SQL.
For example:
/* [Database]: rds@rm-bp144d5ky4l4rli0417****.mysql.rds.aliyuncs.com:3306[rds mysql] */ /* [SQL]: UPDATE t_order SET product_id = 88 WHERE id = 10054 [BACKUP SQL]: SELECT * FROM t_order WHERE id = 10054 */ REPLACE INTO `t_order`(`id`,`product_id`,`gmt_create`,`gmt_modified`,`customer_id`,`price`,`status`,`province`) VALUES (10054,81,'2021-12-14 09:44:44','2021-12-14 09:44:44',71,63.45,'Success','Hangzhou'); -
-
Extract the backup statement from the backup file. After you confirm that the backup statement is correct, submit a new standard data change ticket to restore the data as needed.
NoteIf an
UPDATEstatement was executed by mistake and the backup statement is anINSERTstatement, you must determine the recovery method yourself.
-
-
(Optional) Verify that the change meets expectations.
-
On the ticket details page, in the Basic Information area, move the mouse pointer over the database name and click Query.
-
You are redirected to the SQL Console. Query the table data to check whether it meets your expectations.
-
FAQ
-
Q: When I submit a data change in DMS, the submission fails with the error message: "The topology of the published database XXX is inconsistent with the topology of the change baseline database. Please correct the topology and try again."
A: For a logical database change, the sharding structure of the baseline database and the production database must be consistent. For example, if the baseline database has 8 shards and 256 tables, the production database must also have 8 shards and 256 tables. This consistency is required because the script for online changes is generated by comparing the production database with the baseline database.
-
Q: When I create a data change ticket in DMS, I cannot find the Redis DB.
A: The drop-down list of databases may not show all available databases. It typically shows only the databases that you have recently used. If a database is not in the drop-down list, you must search for it. You can copy the connection string from the SQL Console window and use it for the search.