Two-way synchronization keeps two PolarDB-X 2.0 instances in sync by running a pair of one-way tasks in opposite directions. Use it for active-active architectures where both instances serve writes concurrently.
This page walks through the full setup: configure the forward task first, then configure the reverse task after the forward task starts running.
Prerequisites
Before you begin, make sure that you have:
Source and destination PolarDB-X 2.0 instances (Standard Edition or Enterprise Edition). Multi-stream binary log engine instances are not supported.
Available storage on the destination instance that exceeds the storage used by the source instance.
Privileged database accounts on both instances. For details, see Manage database accounts.
The
binlog_row_imageparameter set tofullon the source instance. For details, see Parameter settings.Binary logs retained for the required duration:
Incremental-only tasks: more than 24 hours.
Tasks with full data synchronization + incremental synchronization: at least 7 days. After the initial full data synchronization completes, you can reduce retention to more than 24 hours.
Binary log retention violations are not covered by the Service-Level Agreement (SLA). If DTS cannot read the required logs, the task fails — and in extreme cases, data inconsistency or data loss may occur.
How it works
A two-way synchronization task consists of two one-way tasks:
Forward task: syncs from instance A to instance B.
Reverse task: syncs from instance B to instance A.
DTS marks records written by synchronization so that each task does not re-sync data received from the other task, preventing sync loops.
The two tasks are configured sequentially: complete and start the forward task first, then configure the reverse task.
The table below shows how key settings differ between the two tasks.
| Setting | Forward task | Reverse task |
|---|---|---|
| Synchronization types | Schema synchronization + Full data synchronization + Incremental data synchronization | Incremental data synchronization only |
| Synchronization topology | Two-way synchronization | Two-way synchronization |
| Exclude DDL operations | Yes | Yes |
| Processing mode of conflicting tables | Precheck and report errors (recommended) | Ignored for objects already synced by the forward task |
| Source | Instance A | Instance B |
| Destination | Instance B | Instance A |
Limitations
Source database
Tables must have a primary key or a unique constraint with unique field values. Without one, duplicate records may appear in the destination.
Read-only PolarDB-X 2.0 instances cannot be used as the source.
If you synchronize at the table level with column mapping and the task includes more than 5,000 tables, split the tables across multiple tasks or switch to database-level synchronization.
Tables with uppercase letters in their names support schema synchronization only.
Synchronization of table groups and databases or tables with the Locality property is not supported.
Tables named with reserved words (for example,
select) cannot be synchronized.Do not run DDL operations during schema synchronization or full data synchronization. DTS queries the source database during full synchronization, which creates metadata locks that can block DDL operations.
Database partitions in DRDS mode within a PolarDB-X 2.0 instance cannot be synchronized.
Two-way synchronization
DDL synchronization is not supported. Set Exclude DDL operations to Yesalert notifications when configuring the task.
Two-way synchronization is not supported if either instance is an Enterprise Edition instance that uses a multi-stream log engine.
Both instances must be at version
polarx-kernel_5.4.15-16774576_xcluster-20221223or later. See View and upgrade the instance version.Do not write data to the destination instance from sources other than DTS while synchronization is running. External writes cause data inconsistency.
Perform synchronization during off-peak hours. Initial full data synchronization consumes read and write resources on both instances and increases load.
After initial full data synchronization, the destination tablespace will be larger than the source due to fragmentation caused by concurrent INSERT operations.
DTS periodically updates the
ha_health_checktable in thedts_health_checkdatabase to advance the binary log offset.
Foreign keys
DTS synchronizes foreign keys from the source to the destination during schema synchronization.
DTS disables constraint checks and foreign key cascade operations at the session level during full and incremental synchronization. If cascade updates or deletes run on the source while the task is active, data inconsistency may occur.
Task failure recovery
If a task fails, DTS support staff will attempt to restore it within eight hours by restarting the task or adjusting DTS task parameters (not database parameters). For the list of parameters that may be adjusted, see Modify instance parameters.
Billing
| Synchronization type | Pricing |
|---|---|
| Schema synchronization and full data synchronization | Free |
| Incremental data synchronization | Charged. See Billing overview. |
SQL operations supported
| Operation type | SQL statement |
|---|---|
| DML | INSERT, UPDATE, DELETE |
Configure the forward task
Step 1: Open the data synchronization task list
Go to the data synchronization task list in the destination region using one of the following methods.
DTS console
Log on to the DTS console.
In the left navigation pane, click Data Synchronization.
In the upper-left corner, select the region where the synchronization instance is located.
DMS console
The actual steps may vary depending on the mode and layout of the DMS console. For more information, see Simple mode console and Customize the layout and style of the DMS console.
Log on to the DMS console.
In the top menu bar, choose Data + AI > DTS (DTS) > Data Synchronization.
To the right of Data Synchronization Tasks, select the region of the synchronization instance.
Step 2: Create the task
Click Create Task to open the task configuration page.
Step 3: Configure source and destination databases
After selecting the source and destination instances, review the Limits shown at the top of the page before proceeding.
| Category | Field | Value |
|---|---|---|
| N/A | Task name | DTS generates a name automatically. Enter a descriptive name for easy identification. Names do not need to be unique. |
| Source database | Select existing connection | Select a registered database instance from the list to auto-fill the fields below. In the DMS console, this field is labeled Select a DMS database instance. If no registered instance is available, fill in the fields manually. |
| Database type | Select PolarDB-X 2.0. | |
| Access method | Select Alibaba Cloud Instance. | |
| Instance region | Select the region of the source instance. | |
| Replicate data across Alibaba Cloud accounts | Select No (same-account synchronization). | |
| Instance ID | Select the source instance ID. | |
| Database account | Enter the privileged account of the source instance. | |
| Database password | Enter the password for the account. | |
| Destination database | Select existing connection | Select a registered database instance from the list to auto-fill the fields below. In the DMS console, this field is labeled Select a DMS database instance. If no registered instance is available, fill in the fields manually. |
| Database type | Select PolarDB-X 2.0. | |
| Access method | Select Alibaba Cloud Instance. | |
| Instance region | Select the region of the destination instance. | |
| Instance ID | Select the destination instance ID. | |
| Database account | Enter the privileged account of the destination instance. | |
| Database password | Enter the password for the account. |
Click Test Connectivity and Proceed.
DTS servers must be allowed to connect to both instances. Add the DTS IP address blocks to the security settings of both databases, either automatically or manually. See Add the IP address whitelist of DTS servers.
Step 4: Select objects to synchronize
On the Configure Objects page, configure the following settings.
| Setting | Description |
|---|---|
| Synchronization types | DTS always selects Incremental Data Synchronization. Also select Schema Synchronization and Full Data Synchronization for the forward task. After the precheck, DTS initializes the destination with the full source data as the baseline for incremental synchronization. |
| Processing mode of conflicting tables | Precheck and Report Errors: DTS checks for identically named tables in the destination. If any are found, the precheck fails and the task does not start. To resolve naming conflicts without deleting the destination table, map the object to a different name. See Database Table Column Name Mapping. Ignore Errors and Proceed: Skips the check. Use with caution — this can cause data inconsistency. During full data synchronization, DTS skips source records that conflict with destination records on the primary or unique key. During incremental synchronization, DTS overwrites the conflicting destination record. |
| Synchronization topology | Select Two-way Synchronization. |
| Exclude DDL operations | Select Yes. DDL operations cannot be synchronized in this scenario. |
| Conflict resolution policy | Select a policy: TaskFailed — the task stops and enters a failed state when a conflict occurs. Manual recovery is required. Ignore — DTS skips the conflicting statement and keeps the existing record in the destination. Overwrite — DTS overwrites the destination record with the source record. |
| Source objects | Click the objects in the Source Objects box, then click the arrow icon to move them to the Selected Objects box. Select objects at the database, table, or column level. If you select only tables or columns, DTS does not synchronize other object types such as views, triggers, and stored procedures. |
| Selected objects | To rename a single object in the destination, right-click it in the Selected Objects box. See Map a single object name. To rename multiple objects in bulk, click Batch Edit. See Map multiple object names in bulk. To filter rows, right-click a table and set a WHERE clause. See Set filter conditions. To select which SQL operations to synchronize for a specific object, right-click it and choose the desired operations. If you use object name mapping, other objects that depend on the mapped object may fail to synchronize. |
Click Next: Advanced Settings.
Step 5: Configure advanced settings
| Setting | Description |
|---|---|
| Dedicated cluster for task scheduling | DTS uses a shared cluster by default. For greater stability, purchase a dedicated cluster. See What is a DTS dedicated cluster?. |
| Retry time for failed connections | If the connection to the source or destination fails after the task starts, DTS retries immediately. Default: 720 minutes. Range: 10–1,440 minutes. Set to 30 minutes or more. If the connection is restored within the retry window, the task resumes automatically; otherwise it fails. If multiple DTS instances share a source or destination, DTS uses the shortest configured retry duration across all instances. DTS charges for task runtime during retries. |
| Retry time for other issues | If a non-connectivity issue (for example, a DDL or DML execution error) occurs, DTS retries immediately. Default: 10 minutes. Range: 1–1,440 minutes. Set to more than 10 minutes. This value must be less than Retry time for failed connections. |
| Enable throttling for full data synchronization | Limit the full synchronization rate by setting Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s). Available only when Full Data Synchronization is selected. You can also adjust the rate while the task is running. See Enable throttling for data migration. |
| Enable throttling for incremental data synchronization | Limit the incremental synchronization rate by setting RPS of Incremental Data Synchronization and Data synchronization speed for incremental synchronization (MB/s). |
| Environment tag | Select a tag to identify the instance, or leave blank. |
| Whether to delete SQL operations on heartbeat tables of forward and reverse tasks | Choose whether DTS writes heartbeat SQL to the source database. Yes: DTS does not write heartbeat SQL. The instance may show synchronization latency. No: DTS writes heartbeat SQL. This may interfere with source database operations such as physical backups and cloning. |
| Monitoring and alerting | No: No alerts configured. Yes: Configure an alert threshold and notification contacts. If the task fails or synchronization latency exceeds the threshold, DTS sends a notification. See Configure monitoring and alerting during task configuration. |
Step 6: Configure data verification (optional)
Click Data Verification to set up a data verification task. See Configure data verification.
Step 7: Save and run the precheck
To preview API parameters before saving, hover over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters.
Click Next: Save Task Settings and Precheck.
DTS runs a precheck before the task starts. If the precheck fails, click View Details next to the failed item, fix the issue, and run the precheck again. If the precheck returns warnings: for non-ignorable warnings, fix the issue and rerun; for ignorable warnings, click Confirm Alert Details > Ignore > OK, then click Precheck Again. Ignoring warnings may cause data inconsistency.
Step 8: Purchase the instance
When Success Rate reaches 100%, click Next: Purchase Instance.
On the Purchase page, select the billing method and instance class:
| Setting | Description |
|---|---|
| Billing method | Subscription: pay upfront for a fixed duration. Cost-effective for long-running tasks. Pay-as-you-go: billed hourly. Suitable for short-term or test tasks. |
| Resource group settings | The resource group for the instance. Defaults to default resource group. See What is Resource Management?. |
| Instance class | Select a class based on your throughput requirements. See Data synchronization link specifications. |
| Subscription duration | Appears only for the Subscription billing method. Monthly options: 1–9 months. Yearly options: 1, 2, 3, or 5 years. |
Read and select the checkbox for Data Transmission Service (Pay-as-you-go) Service Terms.
Click Buy and Start, then click OK.
Monitor the task on the data synchronization page.
Configure the reverse task
Wait until the forward task Status is Running — this means the initial full data synchronization is complete.
Locate the reverse synchronization task in the list and click Configure Task.
Follow steps 3–6 above to configure the reverse task.
Keep the following constraints in mind for the reverse task:
The source of the reverse task is the destination of the forward task, and the destination of the reverse task is the source of the forward task. Confirm that the instance information — database name, account, and password — is correct before proceeding.
Instance region cannot be changed for the reverse task.
For Synchronization types, select Incremental Data Synchronization only. Do not include Schema Synchronization or Full Data Synchronization.
The Processing mode of conflicting tables setting for the reverse task automatically ignores tables that the forward task has already synced to the destination.
The reverse task cannot synchronize objects listed in the Selected objects of the forward task.
Do not use the object name mapping feature for the reverse task. Mapping may cause data inconsistency.
When Success Rate reaches 100%, click Back.
Verify
Wait until the Status of both synchronization tasks is Running. The configuration of two-way data synchronization is complete.
What's next
Enable throttling for data migration — adjust the synchronization rate while tasks are running.
Configure monitoring and alerting — set up alerts for task failures and synchronization latency.
Configure data verification — verify data consistency between the two instances.