Use Data Transmission Service (DTS) to synchronize data from a self-managed PostgreSQL database to a PolarDB for PostgreSQL (Compatible with Oracle) cluster. DTS supports schema synchronization, full data synchronization, and incremental data synchronization, so you can migrate to PolarDB with minimal downtime.
Prerequisites
Before you begin, make sure you have:
A running self-managed PostgreSQL database and a PolarDB for PostgreSQL (Compatible with Oracle) cluster
More available disk space in the destination cluster than the source database currently occupies
A source database account with superuser permission and a destination database account with database owner permission (see Required permissions)
To create a PolarDB for PostgreSQL (Compatible with Oracle) cluster, see Create a PolarDB for PostgreSQL (Compatible with Oracle) cluster. For supported source and destination database versions, see Overview of data synchronization solutions.
Limitations
Review these limitations before starting. Workarounds are noted inline where available.
Source database limits
| Limitation | Detail |
|---|---|
| Primary key or UNIQUE constraint required | Tables must have a primary key or a UNIQUE constraint with unique fields. Without one, the destination database may contain duplicate data. If the destination table is not created by DTS (that is, Schema Synchronization is not selected), the table must have the same primary key or non-null UNIQUE constraint as the source table. |
| Table limit for column mapping tasks | If you synchronize at the table level with column name mapping and the task includes more than 5,000 tables, split them into multiple tasks. Alternatively, configure the task to synchronize the entire database. |
| Database name cannot contain hyphens | The source database name must not contain hyphens (-). For example, dts-testdata is invalid. |
| WAL logs must be enabled | Set wal_level to logical. Retain WAL logs for at least 24 hours for incremental-only tasks, or at least 7 days for tasks that include both full and incremental synchronization. You can reduce the retention period to more than 24 hours after the full synchronization phase completes. If DTS cannot obtain WAL logs or the retention period is shorter than required, any resulting data loss or inconsistency is not covered by the DTS Service-Level Agreement (SLA). |
| Replication slot parameters | max_wal_senders and max_replication_slots must each be greater than the sum of currently used replication slots and the number of DTS instances that use this database as the source. |
| Primary/secondary failover | If a primary/secondary failover occurs in the source database, the synchronization task fails. |
| Long-running transactions | Long-running transactions prevent WAL log cleanup and can cause disk space exhaustion on the source. Run long-running transactions during off-peak hours. |
| Google Cloud SQL for PostgreSQL | The source database account must have cloudsqlsuperuser permission. Select only objects that this account can manage, or grant it owner permission on the objects to sync: GRANT <owner of the object> TO <source database account>. A cloudsqlsuperuser account cannot manage data owned by another cloudsqlsuperuser. |
| Incremental change size | If a single incremental change exceeds 256 MB, the sync instance fails and cannot recover. Reconfigure the instance. |
| No DDL during initial synchronization | Do not run DDL operations that change the schema during initial schema synchronization or full data synchronization. DTS queries the source during full synchronization, which creates metadata locks that block DDL operations. |
| Major version upgrade | If you perform a major version upgrade on the source while the sync instance is running, the instance fails and cannot recover. Reconfigure the instance. |
Other limits
| Limitation | Detail |
|---|---|
session_replication_role | For full or incremental synchronization tasks with foreign keys, triggers, or event triggers, DTS temporarily sets session_replication_role to replica at the session level. This requires a privileged destination database account. If the account does not have this permission, set session_replication_role to replica manually before starting the task. After the task is released, reset it to origin. During this period, cascade update or delete operations on the source may cause data inconsistency. |
| SERIAL type fields | If a source table contains SERIAL type fields, the source database automatically creates a sequence for those fields. When configuring Source Objects, if you select Schema Synchronization, also select Sequence or synchronize the entire schema to avoid task failures. |
| One database per task | A single sync task can synchronize only one database. For multiple databases, create a separate task for each. |
| Unsupported table types | Synchronization of TimescaleDB extension tables and tables with cross-schema inheritance is not supported. |
REPLICA IDENTITY FULL requirement | Run ALTER TABLE schema.table REPLICA IDENTITY FULL; on tables before writing data in any of these cases: when the instance runs for the first time; when a new table is created or rebuilt (using RENAME) during schema-level synchronization; or when you modify the synchronization objects. Run this command during off-peak hours and do not hold table locks while running it. If you skip the related precheck item, DTS runs this command automatically during initialization. |
| Sequence validation | DTS validates data content but does not validate metadata such as sequences. Validate sequences yourself. After switching traffic to the destination, new sequences do not continue from the maximum source sequence value. Update sequence values in the destination before switching. See Update sequence values in the destination database. |
| Temporary tables in the source | DTS creates the following temporary tables in the source database: public.dts_pg_class, public.dts_pg_attribute, public.dts_pg_type, public.dts_pg_enum, public.dts_postgres_heartbeat, public.dts_ddl_command, public.dts_args_session, and public.aliyun_dts_instance. DTS also adds a heartbeat table named dts_postgres_heartbeat. Do not delete these tables during synchronization. They are removed automatically when the DTS instance is released. |
| Replication slot | DTS creates a replication slot with the prefix dts_sync_ in the source database. This slot retains incremental logs for the past 15 minutes. DTS attempts to clean up the slot when the sync task fails or the instance is released. If you change the source database account password or remove DTS IP addresses from the source during synchronization, the slot cannot be cleaned up automatically — clean it up manually to prevent disk exhaustion. If a primary/secondary failover occurs, log on to the secondary database to perform the cleanup. ![]() |
| Source performance | Full data synchronization runs concurrent INSERT operations, which consumes read and write resources on both databases. Perform synchronization during off-peak hours. After initialization, the destination tablespace may be larger than the source due to fragmentation. |
| Writes to destination during sync | Do not write data from sources other than DTS to the destination database during synchronization. Doing so causes data inconsistency. |
| Instance recovery | If a DTS instance fails, DTS attempts to recover it within 8 hours. During recovery, DTS may restart the instance or adjust its parameters (DTS instance parameters only — source and destination database parameters are not changed). |
| Online DDL via DMS | For table-level synchronization with no non-DTS writes to the destination, you can use Data Management (DMS) to perform online DDL operations without locking tables. See Change schemas without locking tables. Do not allow other sources to write to the destination while running DMS online DDL — doing so can cause data loss. |
During schema synchronization, DTS synchronizes foreign keys from the source to the destination. During full and incremental synchronization, DTS temporarily disables foreign key constraint checks and cascade operations at the session level. Cascade update or delete operations on the source during this period may cause data inconsistency.
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 cascade synchronization
One-way many-to-one synchronization
For topology details and usage notes, see Synchronization topologies.
Supported objects
| Objects | Details |
|---|---|
SCHEMA, TABLE | Includes PRIMARY KEY, UNIQUE KEY, FOREIGN KEY, DATATYPE (built-in data types), and DEFAULT CONSTRAINT. |
| Other objects | VIEW, PROCEDURE (PostgreSQL 11 or later), FUNCTION, RULE, SEQUENCE, EXTENSION, TRIGGER, AGGREGATE, INDEX, OPERATOR, DOMAIN |
Supported SQL operations
| Type | Operations |
|---|---|
| DML | INSERT, UPDATE, DELETE |
| DDL | See below |
DDL synchronization is available only for tasks created after DDL support was introduced. The source database account must be a superuser, and the self-managed PostgreSQL minor version must be 20210228 or later.
Supported DDL statements:
CREATE TABLE,DROP TABLEALTER TABLE(includingRENAME TABLE,ADD COLUMN,ADD COLUMN DEFAULT,ALTER COLUMN TYPE,DROP COLUMN,ADD CONSTRAINT,ADD CONSTRAINT CHECK,ALTER COLUMN DROP DEFAULT)TRUNCATE TABLE(PostgreSQL 11 or later)CREATE INDEX ON TABLE
The following DDL statements are not synchronized:
Statements with
CASCADEorRESTRICToptionsStatements in sessions using
SET session_replication_role = replicaDDL executed inside a function call
Transactions that mix DML and DDL in the same commit
DDL for objects outside the synchronization scope
DDL executed through the Server Programming Interface (SPI)
For tasks created before May 12, 2023, in the Singapore region, you must create triggers and functions in the source database to capture DDL information before you configure the sync task. For more information, see Use triggers and functions to implement DDL incremental migration for PostgreSQL.
Synchronization of data of the
BITtype is not supported during incremental data synchronization.
Permissions required for database accounts
| Database | Required permission | How to create and authorize |
|---|---|---|
| Self-managed PostgreSQL | Superuser | Use CREATE USER and User Permission Management. |
| PolarDB for PostgreSQL (Compatible with Oracle) | Database owner | See Create a database account. The database owner is set when the database is created. |
Prepare the source database
The following steps use a self-managed PostgreSQL database running on Linux as an example.
All PostgreSQL versions
Log on to the server where the source PostgreSQL database is running.
Query the number of currently used replication slots:
SELECT count(1) FROM pg_replication_slots;Edit
postgresql.confand set the following parameters.max_wal_sendersandmax_replication_slotsmust each be greater than the sum of the replication slot count from step 2 and the number of DTS instances you plan to create with this source database. Examplepostgresql.confconfiguration:Parameter Required value wal_levellogicalmax_wal_sendersGreater than (current replication slots + DTS instances to create) max_replication_slotsGreater than (current replication slots + DTS instances to create) wal_level = logical max_wal_senders = 10 max_replication_slots = 10Restart the database after saving the file for the changes to take effect.
Add DTS server CIDR blocks to
pg_hba.conf. Add only the CIDR blocks for DTS servers in the same region as the destination database. For the full list, see Add DTS server IP addresses to a whitelist. After savingpg_hba.conf, reload the configuration:SELECT pg_reload_conf();Alternatively, restart the database. Skip this step if
pg_hba.confalready allows connections from0.0.0.0/0. For reference, see The pg_hba.conf file.
In the destination cluster, create the databases and schemas that correspond to the objects you plan to synchronize.
PostgreSQL 9.4.8 to 10.0 (additional steps)
If your source PostgreSQL version is between 9.4.8 and 10.0, you must also install the ali_decoding extension.
Step 1: Compile and install PostgreSQL from source
Log on to the server where the source database is running.
Download the PostgreSQL source code from the PostgreSQL official website matching your database version.
Compile and install PostgreSQL:
ImportantThe OS version and GNU Compiler Collection (GCC) version must be compatible. If
sudo ./configurefails with a readline error, runsudo ./configure --without-readlineinstead. If you use a different PostgreSQL installation method, compileali_decodingin a test environment with the same OS and GCC version.sudo ./configure sudo make sudo make install
Step 2: Install the ali_decoding extension
Download ali_decoding.
Copy the
ali_decodingdirectory into thecontribdirectory of the PostgreSQL installation from Step 1.
Replace the contents of the
Makefilein theali_decodingdirectory with the following:# contrib/ali_decoding/Makefile MODULE_big = ali_decoding MODULES = ali_decoding OBJS = ali_decoding.o DATA = ali_decoding--0.0.1.sql ali_decoding--unpackaged--0.0.1.sql EXTENSION = ali_decoding NAME = ali_decoding #subdir = contrib/ali_decoding #top_builddir = ../.. #include $(top_builddir)/src/Makefile.global #include $(top_srcdir)/contrib/contrib-global.mk #PG_CONFIG = /usr/pgsql-9.6/bin/pg_config #pgsql_lib_dir := $(shell $(PG_CONFIG) --libdir) #PGXS := $(shell $(PG_CONFIG) --pgxs) #include $(PGXS) # Run the following commands to install the source code. ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) else subdir = contrib/ali_decoding top_builddir = ../.. include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endifFrom the
ali_decodingdirectory, compile and install the extension:sudo make sudo make installCopy the generated files to the specified directories.

In the destination cluster, create the databases and schemas that correspond to the objects you plan to synchronize.
Create a sync task
Step 1: Go to the Data Synchronization page
Use either the DTS console or the DMS console.
DTS console
Log on to the DTS console.
In the left-side navigation pane, click Data Synchronization.
In the upper-left corner of the page, select the region in which the data synchronization task resides.
DMS console
The actual operations may vary based on the mode and layout of the DMS console. For more information, see Simple mode and Customize the layout and style of the DMS console.
Log on to the DMS console.
In the top navigation bar, move the pointer over Data + AI and choose DTS (DTS) > Data Synchronization.
From the drop-down list to the right of Data Synchronization Tasks, select the region in which the data synchronization instance resides.
Step 2: Create a task
Click Create Task to open the task configuration page.
Step 3: Configure the source and destination databases
| Section | Parameter | Description |
|---|---|---|
| N/A | Task Name | A name for the DTS task. DTS generates one automatically. Specify a descriptive name for easier identification. The name does not need to be unique. |
| Source Database | Select Existing Connection | Select a registered database instance from the drop-down list. DTS auto-fills the following parameters. If no registered instance is available, fill in the parameters manually. In the DMS console, select from Select a DMS database instance. |
| Database Type | Select PostgreSQL. | |
| Connection Type | Select CEN (Cloud Enterprise Network). | |
| Instance Region | Select the region of the source self-managed PostgreSQL database. | |
| Cross-account | Select No if synchronizing within the same Alibaba Cloud account. | |
| Source Database VPC | Select the VPC connected to the source database. | |
| IP Address | Enter the IP address of the source database server. | |
| Port | Enter the port for the source database. Default: 5432. | |
| Database Name | Enter the name of the source database containing the objects to synchronize. | |
| Database Account | Enter the database account for the source database. See Required permissions. | |
| Database Password | Enter the password for the source database account. | |
| Encryption | Select Non-encrypted or SSL-encrypted based on your requirements. For SSL-encrypted connections, upload CA Certificate, Client Certificate, and Private Key of Client Certificate as needed, and specify Private Key Password of Client Certificate. For ApsaraDB RDS for PostgreSQL SSL configuration, see SSL encryption. | |
| Destination Database | Select Existing Connection | Select a registered database instance from the drop-down list. DTS auto-fills the following parameters. If no registered instance is available, fill in the parameters manually. |
| Database Type | Select PolarDB (Compatible with Oracle). | |
| Connection Type | Select Leased Line/VPN Gateway/Smart Gateway. | |
| Instance Region | Select the region of the destination PolarDB for PostgreSQL (Compatible with Oracle) cluster. | |
| VPC Connected To Source Database | Select the VPC connected to the destination cluster. | |
| DNS Or IP Address | Enter the endpoint of the primary node of the destination cluster. Run ping against the direct connection endpoint to get the IP address. | |
| Port | Enter the service port for the destination database. Default: 1521. | |
| Database Name | Enter the name of the destination database. | |
| Database Account | Enter the database account for the destination cluster. See Required permissions. | |
| Database Password | Enter the password for the destination database account. |
Step 4: Test connectivity
Click Test Connectivity and Proceed at the bottom of the page.
Make sure DTS server CIDR blocks are added to the security settings of both the source and destination databases. See Add DTS server IP addresses to a whitelist. If the source or destination is a self-managed database with an access method other than Alibaba Cloud Instance, click Test Connectivity in the CIDR Blocks of DTS Servers dialog box.
Step 5: Configure synchronization objects
In the Configure Objects step, configure the following:
| Configuration | Description |
|---|---|
| Synchronization Types | Incremental Data Synchronization is selected by default. Also select Schema Synchronization and Full Data Synchronization. DTS synchronizes the historical data of selected objects to the destination cluster as the baseline for subsequent incremental synchronization. |
| Processing Mode of Conflicting Tables | Precheck and Report Errors: Checks whether the destination database has tables with the same names as source tables. If identical names exist, the precheck fails and the task cannot start. To rename destination tables, use the object name mapping feature. See Map object names. Ignore Errors and Proceed: Skips the precheck for identical table names. Warning This option may cause data inconsistency. If the same primary key or unique key value exists in both databases: during full synchronization, the existing destination record is kept; during incremental synchronization, the destination record is overwritten. If schemas differ, initialization may fail or only partial columns are synchronized. |
| Source Objects | Select one or more objects and click the arrow icon to add them to Selected Objects. Select schemas or tables. If you select tables, non-table objects (views, triggers, stored procedures) are not synchronized. If a table contains SERIAL data type and Schema Synchronization is selected, also select Sequence or synchronize the entire schema. |
| Selected Objects | To rename an object in the destination, right-click it. See Map the name of a single object. To rename multiple objects at once, click Batch Edit. See Map multiple object names at a time. Right-click an object to select specific SQL operations or set a WHERE filter condition. See Set filter conditions. |
Click Next: Advanced Settings and configure the following:
| Configuration | Description |
|---|---|
| Dedicated Cluster for Task Scheduling | By default, DTS schedules the task to the shared cluster. To improve stability, purchase a dedicated cluster. See What is a DTS dedicated cluster. |
| Retry Time for Failed Connections | How long DTS retries when the source or destination connection fails after the task starts. Valid values: 10–1440 minutes. Default: 720 minutes. Set this to a value greater than 30 minutes. If DTS reconnects within this period, the task resumes; otherwise, it fails. If multiple tasks share the same source or destination, the shortest retry period applies. DTS charges for the instance during retries. |
| Retry Time for Other Issues | How long DTS retries when DDL or DML operations fail after the task starts. Valid values: 1–1440 minutes. Default: 10 minutes. Set this to a value greater than 10 minutes, and always less than Retry Time for Failed Connections. |
| Enable Throttling for Full Data Synchronization | Throttles the full synchronization phase to reduce database load. Configure Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s). Available only if Full Data Synchronization is selected. |
| Enable Throttling for Incremental Data Synchronization | Throttles the incremental synchronization phase. Configure RPS of Incremental Data Synchronization and Data synchronization speed for incremental synchronization (MB/s). |
| Environment Tag | Optional. Select an environment tag to label the instance. |
| Configure ETL | Select Yesalert notification settings to use the extract, transform, and load (ETL) feature and enter data processing statements. See Configure ETL in a data migration or data synchronization task. Select No to skip. |
| Monitoring and Alerting | Select Yes to configure alerts when the task fails or synchronization latency exceeds the threshold. Specify alert thresholds and notification contacts. See Configure monitoring and alerting when you create a DTS task. |
Click Next Step: Data Verification to configure data verification. See Configure a data verification task.
Step 6: Run the precheck
Click Next: Save Task Settings and Precheck.
To view the API parameters for this task configuration, hover over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters before proceeding.
DTS runs a precheck before the task can start. If any item fails:
Click View Details next to the failed item, fix the issue, then click Precheck Again.
If an alert item can be safely ignored, click Confirm Alert Details > View Details > Ignore > OK, then click Precheck Again. Ignoring alert items may cause data inconsistency.
Step 7: Purchase and start the instance
Wait for the Success Rate to reach 100%, then click Next: Purchase Instance.
On the purchase page, configure the following:
Section Parameter Description New Instance Class Billing Method Subscription: Pay upfront for a fixed term. 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 reduce costs. Resource Group Settings The resource group for the sync instance. Default: default resource group. See What is Resource Management?. Instance Class DTS provides instance classes with different synchronization speeds. Select based on your requirements. See Instance classes of data synchronization instances. Subscription Duration Available when Subscription is selected. Options: 1–9 months, 1 year, 2 years, 3 years, or 5 years. Read and accept Data Transmission Service (Pay-as-you-go) Service Terms.
Click Buy and Start, then click OK in the dialog box.
The task appears in the task list. Monitor its progress there.
What's next
Before switching traffic to the destination, update sequence values in the destination database. See Update sequence values in the destination database.
To monitor synchronization status and configure alerts, see Configure monitoring and alerting.
To modify the set of synchronized objects after the task starts, see Modify synchronization objects.
Release the instance promptly when synchronization is complete to avoid unnecessary charges.
