Data Transmission Service (DTS) supports two-way data synchronization between PolarDB for MySQL clusters. This feature is suitable for scenarios such as active geo-redundancy and geo-disaster recovery. This topic describes how to configure two-way data synchronization between PolarDB for MySQL clusters.
Prerequisites
- The source and destination Apsara PolarDB for MySQL clusters are created. For more information, see Purchase a pay-as-you-go cluster.
- The binary logging feature is enabled for the source and destination Apsara PolarDB for MySQL clusters. For more information, see Enable binary logging.
Precautions
- DTS uses read and write resources of the source and destination databases during initial full data synchronization. This may increase the loads of the database servers. If the database performance or specifications are unfavorable, or the data volume is large, database services may become unavailable. For example, DTS occupies a large amount of read and write resources in the following cases: a large number of slow SQL queries are performed on the source database, the tables have no primary keys, or a deadlock occurs in the destination database. Before you synchronize data, evaluate the impact of data synchronization on the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours. For example, you can synchronize data when the CPU utilization of the source and destination databases is less than 30%.
- During initial full data synchronization, concurrent INSERT operations cause fragmentation in the tables of the destination cluster. After the initial full data synchronization is completed, the tablespace of the destination cluster is larger than that of the source cluster.
- The source cluster must have PRIMARY KEY or UNIQUE constraints and all fields must be unique. Otherwise, the destination cluster may contain duplicate data records.
- If the source or destination instance is located in a region outside the Chinese mainland, two-way data synchronization is supported only between instances located within the same region. For example, two-way data synchronization is supported between instances within the Japan (Tokyo) region. Two-way data synchronization between an instance in the Japan (Tokyo) region and another instance in the Germany (Frankfurt) region is not supported.
Billing
Synchronization type | Task configuration fee |
---|---|
Schema synchronization and full data synchronization | Free of charge. |
Incremental data synchronization | Charged. For more information, see Billing overview. |
Limits
- DTS supports two-way data synchronization between two PolarDB clusters, but not between multiple PolarDB clusters.
- We recommend that you do not use gh-ost or pt-online-schema-change to perform DDL operations on objects during data synchronization. Otherwise, data synchronization may fail.
- Incompatibility with triggers
If you select a database as the object to synchronize and the database contains a trigger that updates a table, data inconsistency may occur. For more information about how to solve this issue, see Configure a data synchronization task for a source database that contains a trigger.
- Limits on RENAME TABLE operations
RENAME TABLE operations may cause data inconsistency between the source and destination databases. For example, if you select a table as the object and rename the table during data synchronization, the data of this table is not synchronized to the destination database. To prevent this situation, you can select the database to which this table belongs as the object when you configure the data synchronization task.
- Limits on DDL synchronization direction
To ensure the stability of two-way data synchronization, you can synchronize DDL operations only in one direction. If DDL synchronization in a direction is configured, DDL synchronization in the reverse direction is not supported. Only DML operations can be synchronized in the reverse direction.
SQL operations that can be synchronized
Operation type | SQL statement |
---|---|
DML | INSERT, UPDATE, DELETE, and REPLACE |
DDL |
|
Conflict detection
To ensure data consistency, make sure that data records with the same primary key, business primary key, or unique key are updated only on a single PolarDB cluster. If data records are updated on both two PolarDB clusters, a synchronization conflict occurs.
DTS checks and fixes conflicts to maximize the stability of two-way synchronization instances. DTS can detect the following types of conflicts:
- Uniqueness conflicts caused by INSERT operations
INSERT operations that do not comply with the UNIQUE constraint cannot be synchronized. For example, if data records with the same primary key are inserted into two synchronization nodes at almost the same time, one of the inserted records fails to be synchronized. The synchronization fails because a record with the same primary key already exists on the other node.
- Inconsistent records caused by UPDATE operations
- If the records to update do not exist in the destination cluster, DTS converts the UPDATE operation into an INSERT operation. However, uniqueness conflicts may occur.
- The primary keys or unique keys of the records to insert may conflict with those of existing records in the destination instance.
- Non-existent records to be deleted
The records to be deleted do not exist in the destination cluster. In this case, DTS ignores the DELETE operation regardless of the conflict resolution policy that you specify.
- During two-way synchronization, the system time of the source and destination instances may be different. Synchronization latency may occur. For these reasons, DTS does not ensure that the conflict detection mechanism can prevent all data conflicts. To perform two-way synchronization, make sure that records with the same primary key, business primary key, or unique key are updated only on one of the synchronization nodes.
- DTS provides conflict resolution policies to prevent conflicts that may occur during data synchronization. You can select a conflict resolution policy when you configure two-way data synchronization.
Procedure
- Purchase a data synchronization instance. For more information, see Purchase a DTS instance. Important On the buy page, set both Source Instance and Destination Instance to PolarDB and set Synchronization Topology to Two-way Synchronization.
- Log on to the DTS console. Note If you are redirected to the Data Management (DMS) console, you can click the icon in the lower-right corner to go to the previous version of the DTS console.
- In the left-side navigation pane, click Data Synchronization.
- In the upper part of the Data Synchronization Tasks page, select the region in which the destination instance resides.
- Configure the data synchronization task in the forward direction.
- Wait until initial synchronization is complete and the data synchronization task is in the Synchronizing state. You can view the status of the data synchronization task on the Synchronization Tasks page.
- Configure the data synchronization task in the reverse direction.