Use Data Transmission Service (DTS) to synchronize data from an ApsaraDB RDS for MySQL instance to an ApsaraDB RDS for PostgreSQL instance in real time. DTS supports schema synchronization, full data synchronization, and incremental data synchronization, so you can migrate data with minimal downtime and keep the destination database continuously up to date.
Prerequisites
Before you begin, make sure you have:
An ApsaraDB RDS for MySQL source instance. For more information, see Create an ApsaraDB RDS for MySQL instance
An ApsaraDB RDS for PostgreSQL destination instance. For more information, see Create an ApsaraDB RDS for PostgreSQL instance
Enough available storage on the destination instance to hold all data from the source database
Billing
| Synchronization type | Fee |
|---|---|
| Schema synchronization and full data synchronization | Free |
| Incremental data synchronization | Charged. See Billing overview. |
Supported synchronization topologies
One-way one-to-one synchronization
One-way one-to-many synchronization
One-way many-to-one synchronization
SQL operations that can be synchronized
| Operation type | Supported operations |
|---|---|
| DML | INSERT, UPDATE, DELETE |
Limitations
Review these limitations before you configure the task.
Source database requirements
Tables must have PRIMARY KEY or UNIQUE constraints, with all fields unique. Otherwise, duplicate records may appear in the destination database.
If you select tables as synchronization objects and need to rename tables or columns, a single task supports up to 1,000 tables. For more than 1,000 tables, configure multiple tasks or synchronize the entire database in one task.
Do not run DDL statements during schema synchronization or full data synchronization. DDL changes during these phases cause the task to fail.
Data changes from physical backup restoration or cascade operations are not recorded or synchronized to the destination database while the data synchronization instance is running. If this occurs, you can remove the affected databases and tables from the synchronization objects and then re-add them. For more information, see Modify the objects to be synchronized.
MySQL 8.0.23 and later: If the data to be synchronized includes invisible columns, DTS cannot read those columns and data loss occurs. To make columns visible, run:
ALTER TABLE <table_name> ALTER COLUMN <column_name> SET VISIBLE;Tables without primary keys automatically generate invisible primary keys — make those visible as well. See Invisible Columns and Generated Invisible Primary Keys.
If the EncDB feature is enabled on the source instance, full data synchronization cannot be performed. Instances with Transparent Data Encryption (TDE) enabled support schema synchronization, full data synchronization, and incremental data synchronization.
Binary log requirements
ApsaraDB RDS for MySQL
Binary logging is enabled by default on ApsaraDB RDS for MySQL instances. Verify the following parameter:
| Parameter | Required value |
|---|---|
binlog_row_image | full |
Ifbinlog_row_imageis not set tofull, error messages are returned during the precheck and the data synchronization task cannot be started. Read-only ApsaraDB RDS for MySQL 5.6 instances, which do not record transaction logs, cannot be used as the source database.
Binary logs must be retained for at least seven days. If DTS cannot read the binary logs, the synchronization task may fail, and data inconsistency or loss may occur. See Manage binary log files.
Self-managed MySQL
If your source is a self-managed MySQL database, configure the following parameters before you start the task:
| Parameter | Required value | Notes |
|---|---|---|
binlog_format | row | |
binlog_row_image | full | |
log_slave_updates | ON | Required for dual-primary clusters only |
See Create an account for a self-managed MySQL database and configure binary logging.
If a primary/secondary switchover occurs on the source database while the task is running, the task fails.
Objects and data types
Only tables can be selected as synchronization objects. DTS does not synchronize views, triggers, or stored procedures.
The following data types are not supported: BIT, VARBIT, GEOMETRY, ARRAY, UUID, TSQUERY, TSVECTOR, TXID_SNAPSHOT, and POINT.
Prefix indexes cannot be synchronized. If the source database contains prefix indexes, the task may fail.
Do not use tools such as pt-online-schema-change for online DDL operations during table-level synchronization. Use Data Management (DMS) instead.
Foreign key handling
During schema synchronization, DTS synchronizes foreign keys from the source database to the destination database.
During full data synchronization and incremental data synchronization, DTS temporarily disables foreign key constraint checks and cascade operations at the session level. If you run cascade update or delete operations on the source database during synchronization, data inconsistency may occur.
If you use a privileged or superuser account for the destination database and the tables contain foreign keys, triggers, or event triggers, DTS temporarily sets session_replication_role to replica at the session level. If the account does not have the required permissions, set session_replication_role to replica manually. After the task is released, change the value back to origin.
Performance considerations
Evaluate the impact on source and destination database performance before starting. Run synchronization during off-peak hours.
During initial full data synchronization, DTS uses read and write resources of both databases, which increases server load.
Concurrent INSERT operations during initial full data synchronization cause fragmentation in destination tables. After full data synchronization completes, the destination tablespace will be larger than the source.
Do not write data to the destination database from other sources during synchronization, as this may cause data inconsistency or loss.
Synchronization latency
DTS calculates synchronization latency based on the timestamp of the latest synchronized record in the destination and the current timestamp in the source. If no DML operations run on the source for an extended period, the reported latency may be inaccurate. Run a DML operation on the source to refresh the latency reading.
Tip: If you synchronize an entire database, create a heartbeat table that receives updates every second to keep the latency accurate.
DTS also runs CREATE DATABASE IF NOT EXISTS 'test' on the source database on a schedule to advance the binary log file position.
DTS task failure recovery
If a DTS task fails, DTS technical support will attempt to restore it within 8 hours. During restoration, the task may be restarted and task parameters (not database parameters) may be modified.
Set up a data synchronization task
The setup has nine steps: open the Data Synchronization Tasks page, select the region, configure source and destination databases, test connectivity, configure synchronization objects and advanced settings, run the precheck, purchase the instance, and start the task.
Step 1: Open the Data Synchronization Tasks page
Log on to the Data Management (DMS) console.
In the top navigation bar, click Data + AI.
In the left-side navigation pane, choose DTS (DTS) > Data Synchronization.
Operations may vary based on the DMS console mode and layout. See Simple mode and Customize the layout and style of the DMS console. You can also go directly to the Data Synchronization Tasks page of the new DTS console.
Step 2: Select the region
On the right side of Data Synchronization Tasks, select the region where the data synchronization instance resides.
In the new DTS console, select the region in the top navigation bar.
Step 3: Configure source and destination databases
Click Create Task. In the Create Data Synchronization Task wizard, configure the following parameters.
Source Database
| Parameter | Description |
|---|---|
| Task Name | The name of the DTS task. DTS generates a name automatically. Specify a descriptive name to identify the task. The name does not need to be unique. |
| Database Type | Select MySQL. |
| Connection Type | Select Alibaba Cloud Instance. |
| Instance Region | The region where the source ApsaraDB RDS for MySQL instance resides. |
| Replicate Data Across Alibaba Cloud Accounts | Select No for same-account synchronization. |
| RDS Instance ID | The ID of the source ApsaraDB RDS for MySQL instance. |
| Database Account | The database account of the source instance. |
| Database Password | The password for the database account. |
| Encryption | Select Non-encrypted or SSL-encrypted. To use SSL encryption, enable SSL encryption on the source instance before configuring this task. See Use a cloud certificate to enable SSL encryption. |
Destination Database
| Parameter | Description |
|---|---|
| Database Type | Select PostgreSQL. |
| Connection Type | Select Alibaba Cloud Instance. |
| Instance Region | The region where the destination ApsaraDB RDS for PostgreSQL instance resides. |
| Instance ID | The ID of the destination ApsaraDB RDS for PostgreSQL instance. |
| Database Name | The name of the destination database. |
| Database Account | The database account of the destination instance. The account must have owner permissions on schemas. See Create an account. |
| Database Password | The password for the database account. |
Step 4: Test connectivity and proceed
Click Test Connectivity and Proceed.
DTS automatically adds its server CIDR blocks to the whitelist of Alibaba Cloud database instances such as ApsaraDB RDS for MySQL. For self-managed databases on Elastic Compute Service (ECS) instances, DTS adds the CIDR blocks to the ECS security group rules — make sure the ECS instance can access the database. For self-managed databases in data centers or from third-party cloud providers, manually add the DTS server CIDR blocks to the database whitelist. See Add the CIDR blocks of DTS servers.
Adding DTS server CIDR blocks to database whitelists or ECS security groups introduces security risks. Before using DTS, take preventive measures: strengthen username and password security, limit exposed ports, authenticate API calls, and regularly audit whitelist and security group rules. Remove unauthorized CIDR blocks. Alternatively, connect the database to DTS through Express Connect, VPN Gateway, or Smart Access Gateway.
Step 5: Configure synchronization objects and advanced settings
Basic settings
| Parameter | Description |
|---|---|
| Synchronization Types | Select Schema Synchronization, Full Data Synchronization, and Incremental Data Synchronization. After the precheck, DTS synchronizes historical data from the source to the destination, which serves as the basis for subsequent incremental synchronization. |
| Processing Mode of Conflicting Tables | Precheck and Report Errors: DTS checks whether the destination contains tables with the same names as those in the source. If identical table names exist, an error is returned during the precheck and the task cannot start. Use the object name mapping feature to rename conflicting tables. See Map object names. Ignore Errors and Proceed: Skips the precheck for identical table names. Warning This may cause data inconsistency. During full data synchronization, DTS does not overwrite existing records with the same primary key or unique key — the existing destination record is retained. During incremental data synchronization, DTS overwrites matching records. If the source and destination have different schemas, some columns may not be synchronized or the task may fail. |
| Capitalization of Object Names in Destination Instance | The capitalization policy for database, table, and column names. Default: DTS default policy. See Specify the capitalization of object names in the destination instance. |
| Source Objects | Select objects from Source Objects and click the arrow icon to move them to Selected Objects. You can select columns, tables, or databases. If you select tables or columns, DTS does not synchronize views, triggers, or stored procedures. |
| Selected Objects | To rename a single object, right-click it in the Selected Objects section. To rename multiple objects at once, click Batch Edit in the upper-right corner. See Map object names. Note The time field supports the TIMESTAMP data type. If a time field value is |
Advanced settings
| Parameter | Description |
|---|---|
| Monitoring and Alerting | Select Yes to configure alerts for task failures or when synchronization latency exceeds a threshold. See Configure monitoring and alerting. |
| Retry Time for Failed Connections | The time range within which DTS retries a failed connection. Valid values: 10–1,440 minutes. Default: 720 minutes. Set this to more than 30 minutes. If DTS reconnects within the specified time range, the task resumes. Otherwise, the task fails. Note When multiple tasks share the same source or destination database, the shortest retry time range takes precedence. DTS charges for the instance during retry attempts. |
| Configure ETL | Select Yes to enable the extract, transform, and load (ETL) feature and enter data processing statements. See Configure ETL in a data migration or data synchronization task and What is ETL? |
Step 6: Save settings and run the precheck
To view the API parameters for this task configuration, 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 can start. If the precheck fails, click View Details next to each failed item, resolve the issues based on the check results, and then click Precheck Again. If a precheck item triggers an alert that can be ignored, click Confirm Alert Details, click Ignore in the dialog box, click OK, and then click Precheck Again. Ignoring alert items may result in data inconsistency.
Step 7: Wait for the precheck to pass
Wait until Success Rate reaches 100%, then click Next: Purchase Instance.
Step 8: Purchase the synchronization instance
On the purchase page, configure the following parameters.
| Parameter | Description |
|---|---|
| Billing Method | Subscription: Pay upfront for a fixed period. More cost-effective for long-term use. Pay-as-you-go: Billed hourly. Suitable for short-term use. Release the instance when no longer needed to avoid ongoing charges. |
| Resource Group Settings | The resource group for the synchronization instance. Default: default resource group. See What is Resource Management? |
| Instance Class | The synchronization speed varies by instance class. See Instance classes of data synchronization instances. |
| Subscription Duration | Available only for the Subscription billing method. Options: 1–9 months, 1 year, 2 years, 3 years, or 5 years. |
Step 9: Start the task
Read and select Data Transmission Service (Pay-as-you-go) Service Terms, then click Buy and Start. In the dialog box, click OK.
The task appears in the task list. Track its progress from there.