Data synchronization and migration share the same problem

Updated at:
  • Q: What is the impact of modifying data in the destination database while a data synchronization or migration task is running?

    • Modifying data in the destination database may cause the DTS task to fail. During data migration or synchronization, performing operations on the objects that are being migrated or synchronized in the destination database may cause issues such as primary key conflicts or missing update records, which ultimately cause the DTS task to fail. However, you can perform operations that do not interrupt the DTS task. For example, if you create a table in the destination instance and write data to it, the DTS task is not affected because the table is not included in the migration or synchronization objects.

    • Because DTS reads information from the source instance database and migrates or synchronizes its full data, schema data, and incremental data to the destination instance, data modifications made to the destination database during the task may be overwritten by data migrated or synchronized from the source database.

  • Q: Does DTS support cross-account data migration or data synchronization?

    A: Yes. For information about how to configure it, see Configure a cross-account DTS task.

  • Q: Can data be written to the source database and the destination database at the same time while a data synchronization or migration task is running?

    A: Yes. However, while the DTS instance is running, if data sources other than DTS write data to the destination database, exceptions may occur in the destination database data or in the DTS instance.

  • Q: Does DTS support sampling data synchronization or migration by time range?

    A: No.

  • Q: When synchronizing or migrating data, do I need to manually create tables in the destination database?

    A: For DTS instances that support schema tasks (schema synchronization or schema migration), if you have configured a schema task (Synchronization Types with Schema Synchronization selected, or Migration Types with Schema Migration selected), you do not need to manually create tables in the destination database.

  • Q: When synchronizing or migrating data, do the source database and the destination database need to be connected over the network?

    A: No.

  • Q: How do I use the API to configure the ETL feature for a synchronization or migration task?

    A: You can configure it in the Reserve parameter of the API by using common parameters such as etlOperatorCtl and etlOperatorSetting. For more information, see Configure a DTS migration or synchronization task and Reserve parameter reference.

  • Q: Is data in the source database retained after DTS synchronization or migration ends?

    A: Yes. DTS does not delete data in the source database. If you do not need to retain the data in the source database, delete it manually.

  • Q: Can I adjust the rate after a synchronization or migration instance is running?

    A: Yes. For more information, see Enable throttling for data migration.

  • Q: An incremental synchronization error indicates that the packet is too large or the max_allowed_packet value at the destination is insufficient. How do I resolve this?

    • Cause:

      The source contains a row with a large amount of data that exceeds the limit of the max_allowed_packet parameter at the destination during incremental synchronization, causing the synchronization error.

    • Solution:

      1. Log on to the source database and query the current value of the max_allowed_packet parameter:

        SHOW VARIABLES LIKE 'max_allowed_packet';

        Record the value (for example, 1073741824, which is 1 GB).

      2. Log on to the ApsaraDB RDS console (or the PolarDB console if the destination is PolarDB for MySQL). On the Parameters page of the destination database instance, set the max_allowed_packet parameter to a value that is no less than the value at the source.

      3. After the parameter modification is complete, restart the synchronization task in the DTS console and verify whether synchronization returns to normal.

  • Q: The synchronization task has been interrupted for several hours, and I suspect that an MDL lock exists at the destination. How do I resolve this?

    • Cause:

      A metadata lock (MDL lock) at the destination, caused by a long-running DDL operation (such as adding a column to a large table or rebuilding an index), is blocking the incremental data writes from DTS, causing the synchronization link to be interrupted for a long time.

    • Solution:

      1. Log on to the ApsaraDB RDS console, go to the destination database instance, and run SHOW FULL PROCESSLIST to locate the abnormal session that holds the MDL lock. Then, kill the session.

      2. Log on to the DTS console and modify the synchronization objects to remove the tables that are affected by the MDL lock from the synchronization scope.

      3. Drop the table in the destination database (before this operation, make sure that the data has been backed up or can be cleared).

      4. After the DTS synchronization task returns to normal and the synchronization latency drops to zero, modify the synchronization objects again to add the table back to the synchronization scope and complete the re-migration.

  • Q: An incremental synchronization error indicates that a temporary table is missing in the destination database or that a SELECT INTO conflict occurs. How do I resolve this?

    • Cause:

      This issue is not actually caused by a missing temporary table in the destination database. Instead, after Change Data Capture (CDC) is enabled in the source database, the triggers created by DTS intercept the implicit table creation performed by SELECT INTO, which causes conflicts during data synchronization.

    • Solution:

      1. Verify that the transaction log file at the source exists and is intact.

      2. Disable the CDC feature in the source database.

      3. Log on to the DTS console, reconfigure the synchronization task, select Parse source database logs as the incremental synchronization method, and then restart the task.

  • Q: When you use DTS for data synchronization or migration, is existing data at the destination overwritten?

    A: Taking data synchronization as an example, the default behavior and related parameters of DTS are as follows:

    Default behavior of DTS: If a primary key or unique key conflict occurs while the synchronization task is running:

    • If the table schemas are consistent and a record in the destination database has the same primary key or unique key value as a record in the source database:

      • During full data synchronization, DTS retains the destination record and skips the source record.

      • During incremental synchronization, DTS overwrites the destination record with the source record.

    • If the table schemas are inconsistent, data initialization may fail. This can result in only partial data synchronization or a complete synchronization failure. Use with caution.

    Related parameters: When you configure a task, you can use the Processing Mode of Conflicting Tables parameter to manage how the related data is processed.

    • Precheck and Report Errors: Checks for tables with the same names in the destination database. If any tables with the same names are found, an error is reported during the precheck and the data synchronization task does not start. Otherwise, the precheck is successful.

      Note

      If you cannot delete or rename the table with the same name in the destination database, you can map it to a different name in the destination. For more information, see Object name mapping.

    • Ignore Errors and Proceed: Skips the check for tables with the same name in the destination database.

      Warning

      Selecting Ignore Errors and Proceed may cause data inconsistency and put your business at risk. For example:

      • If the table schemas are consistent and a record in the destination database has the same primary key or unique key value as a record in the source database:

        • During full data synchronization, DTS retains the destination record and skips the source record.

        • During incremental synchronization, DTS overwrites the destination record with the source record.

      • If the table schemas are inconsistent, data initialization may fail. This can result in only partial data synchronization or a complete synchronization failure. Use with caution.

    Recommendation: To ensure data consistency, we recommend that you delete the destination table before configuring the DTS task, if your business allows.

  • Q: What if DTS has synchronized the data, but the data in the destination database is incomplete or inconsistent with the source database?

    A: Please investigate the following four possible causes:

    • Triggers in the destination database: Triggers in the destination database (such as BEFORE INSERT or AFTER UPDATE) may modify the data again while DTS is writing it, causing inconsistency between the destination and source databases. It is recommended to delete triggers in the destination database after schema migration is complete and then restart the DTS task. Check for triggers: `SELECT TRIGGER_NAME, EVENT_OBJECT_TABLE, ACTION_TIMING FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA = 'destination_database_name';` Delete triggers: `DROP TRIGGER IF EXISTS trigger_name;`

    • Tables lacking primary keys or unique keys: Tables in the source database that lack primary keys or unique keys may result in duplicate data in the destination database during incremental migration. It is recommended to add a primary key or unique key to the table or enable "Exactly-Once" writing when configuring the DTS task.

    • Concurrent writes from other applications: If other applications write data to the destination database simultaneously during DTS synchronization, data inconsistency will occur. It is recommended to pause writes from other applications to the destination database during DTS synchronization.

    • Destination database not cleared: If the destination database already contains existing data that overlaps with the migrated data, mixing the two will lead to inconsistency. It is recommended to clear the destination database before configuring the DTS task and select the migration type that includes schema migration, full data migration, and incremental data migration.