Use Data Transmission Service (DTS) to migrate data between two AnalyticDB for PostgreSQL instances. This topic covers migration type selection, configuration, precheck, and monitoring.
Prerequisites
Before you begin, make sure that you have:
A destination AnalyticDB for PostgreSQL instance with storage space larger than the amount of data to migrate from the source instance. See Create an instance
A database created in the destination instance to receive the migrated data. See SQL syntax
Choose a migration type
Select a migration type based on whether your business can tolerate downtime.
| Migration type |
|---|
| Schema migration + full data migration |
| Schema migration + full data migration + incremental data migration |
Schema migration + full data migration: Do not write to the source database during migration. Incremental migration is not included.
Schema migration + full data migration + incremental data migration: The destination stays synchronized until you cut over. Incremental migration is charged; requires logical replication enabled on the source.
Billing
| Migration type | Task configuration fee | Data transfer fee |
|---|---|---|
| Schema migration and full data migration | Free | Free, unless the destination database uses a public IP address. See Billing overview |
| Incremental data migration | Charged. See Billing overview | — |
Database account permissions
| Database | Required permissions | How to create and grant |
|---|---|---|
| Source AnalyticDB for PostgreSQL | Read permissions on the objects to be migrated, and the REPLICATION permission | Create and manage users |
| Destination AnalyticDB for PostgreSQL | Read and write permissions on the destination database | Create and manage users |
Grant the REPLICATION permission to the source database account:
ALTER USER <username> WITH REPLICATION;For the destination database, use the initial account or an account with RDS_SUPERUSER permissions.
Supported objects
SCHEMA, TABLE — includes PRIMARY KEY, UNIQUE KEY, built-in data types (DATATYPE), and DEFAULT CONSTRAINT
VIEW, INDEX, PROCEDURE, FUNCTION, RULE, SEQUENCE, AGGREGATE, OPERATOR, DOMAIN
Supported SQL operations for incremental migration
| Operation type | SQL statement |
|---|---|
| DML | INSERT, UPDATE, DELETE |
Limitations
Source database requirements
Bandwidth: The source database server must have at least 100 Mb/s of outbound bandwidth. Lower bandwidth reduces migration speed.
Version: The source AnalyticDB for PostgreSQL instance must be version 7.2.1.4 or later.
Logical replication: Set the
wal_levelparameter tologicalto enable logical replication. See Configure parameters.High-availability Edition: If the source instance uses the High-availability Edition, set
hot_standby,hot_standby_feedback, andsync_replication_slotstoon. This prevents logical subscription interruptions caused by primary/secondary failovers.Database name: Database names cannot contain hyphens (
-), for example,dts-testdata.Primary key or UNIQUE constraint: Tables to be migrated must have a primary key or a UNIQUE constraint with unique fields. Otherwise, duplicate data may appear in the destination database.
Unsupported objects: DTS cannot migrate tables with cross-schema inheritance relationships, temporary tables, internal triggers, C language functions, internal PROCEDURE and FUNCTION functions, or extensions. DTS can migrate custom data types of COMPOSITE, ENUM, or RANGE, and primary key, UNIQUE, and CHECK constraints.
Partitioned tables: DTS does not migrate partitioned table schemas. All partitioned tables are created as non-partitioned tables in the destination.
Table-level editing limit: When migrating at the table level with object edits such as name mapping, a single task supports a maximum of 5,000 tables. Exceeding this limit causes an error when submitting the task. Split the tables across multiple tasks or migrate the entire database instead.
Operational constraints
During schema migration and full data migration, do not run DDL operations on the source database. DDL changes will cause the migration task to fail.
If you run only full data migration (without incremental migration), do not write new data to the source database during migration. To maintain real-time consistency between source and destination, select schema migration, full data migration, and incremental data migration.
Long-running transactions in the source database during incremental migration can prevent Write-Ahead Logging (WAL) data from being cleared, causing WAL to accumulate and potentially exhausting disk space.
Other limitations
A single migration task can migrate data from only one database. To migrate multiple databases, create a separate task for each database.
DDL operations on the source database are not migrated.
After schema migration, the owner of the migrated schema becomes the destination database account used for the task.
The distribution key is unchanged by default during schema migration. If the source table has a primary key, the destination table uses the same primary key column. If there is no primary key, the distribution key is used as the primary key column.
If a table contains a SERIAL type field, the source database automatically creates a Sequence for that field. When configuring Source Objects, if you select Schema Migration for Migration Types, also select Sequence or migrate the entire schema. Otherwise, the migration instance may fail.
For incremental data migration, run
ALTER TABLE schema.table REPLICA IDENTITY FULL;on the source tables before writing data to them. Do not lock tables when running this command — locking can cause a deadlock. If you skip the relevant precheck item, DTS automatically runs this command during instance initialization in these cases:When the instance runs for the first time.
When the migration object granularity is set to Schema and a new table is created or an existing table is rebuilt using the RENAME command.
Note Replaceschemaandtablewith the actual schema and table names. Run this command during off-peak hours.DTS validates data content but does not validate metadata such as Sequences. Validate Sequences manually.
After switching your business to the destination instance, the initial value of a new Sequence does not automatically continue from the maximum value of the corresponding Sequence in the source. Before switching, query the maximum Sequence values in the source and set them as initial values in the destination. Run the following command on the source database to get the
setvalstatements for all Sequences:do language plpgsql $$ declare nsp name; rel name; val int8; begin for nsp,rel in select nspname,relname from pg_class t2 , pg_namespace t3 where t2.relnamespace=t3.oid and t2.relkind='S' loop execute format($_$select last_value from %I.%I$_$, nsp, rel) into val; raise notice '%', format($_$select setval('%I.%I'::regclass, %s);$_$, nsp, rel, val+1); end loop; end; $$;The output contains
setvalstatements for all Sequences in the source database. Run the relevant statements on the destination database as needed.DTS adds a heartbeat table named
dts_postgres_heartbeatto the source database to track incremental migration latency accurately.DTS creates the following temporary tables in the source database during migration. Do not delete them — deleting them causes the DTS task to fail. These tables are automatically removed after the DTS instance is released:
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, andpublic.aliyun_dts_instance.During incremental data migration, DTS creates a replication slot with the prefix
dts_sync_in the source database. DTS uses this slot to retrieve incremental logs from the last 15 minutes. When the migration fails or the migration instance is released, DTS attempts to clean up the replication slot.Note If you change the source database account password or remove the DTS IP address from the whitelist during migration, the replication slot cannot be cleaned up automatically. Clean up the replication slot manually in the source database to prevent it from accumulating and consuming disk space — excessive replication slots can make the source database unavailable. If a primary/secondary failover occurs, log in to the secondary database to perform the cleanup.Full data migration uses concurrent INSERT operations, which causes table fragmentation in the destination. After full data migration, the destination tables occupy more storage space than the source tables.
During full data migration, DTS consumes read and write resources on both source and destination databases, increasing the database load. Evaluate the performance of both databases before migrating. Run migrations during off-peak hours — for example, when CPU load is below 30% on both databases.
While the migration instance is running:
Do not change the endpoint or zone of the AnalyticDB for PostgreSQL instance. Such changes cause the migration instance to fail.
Do not write to the destination database from a data source other than DTS. This can cause data inconsistency and may cause the migration instance to fail.
If a migration instance fails, DTS will attempt recovery within 8 hours. During recovery, DTS may restart the instance or adjust its parameters.
Note Only DTS instance parameters are modified during recovery — database parameters are not changed. For details on which parameters may be modified, see Modify instance parameters.
Migrate data
Step 1: Go to the Data Migration page
Use either the DTS console or the DMS console.
DTS console
Log on to the DTS console.DTS console
In the left-side navigation pane, click Data Migration.
In the upper-left corner, select the region where the migration instance resides.
DMS console
Log on to the DMS console.DMS console
In the top navigation bar, move the pointer over Data + AI > DTS (DTS) > Data Migration.
From the drop-down list to the right of Data Migration Tasks, select the region where the migration instance resides.
Step 2: Configure source and destination databases
Click Create Task.
On the task configuration page, configure the parameters described in the following table.
| Category | Parameter | Description |
|---|---|---|
| (None) | Task Name | The name of the DTS task. DTS generates a name automatically. Specify a descriptive name to identify the task easily. The name does not need to be unique. |
| Source Database | Select Existing Connection | If the source instance is registered with DTS, select it from the drop-down list — DTS fills in the connection parameters automatically. See Manage database connections. Otherwise, configure the following parameters manually. In the DMS console, select the instance from Select a DMS database instance. |
| Database Type | Select AnalyticDB for PostgreSQL. | |
| Access Method | Select Alibaba Cloud Instance. | |
| Instance Region | Select the region where the source instance resides. | |
| Replicate Data Across Alibaba Cloud Accounts | Select No to use an instance under the current Alibaba Cloud account. | |
| Instance ID | Select the ID of the source instance. | |
| Database Name | Enter the name of the database to migrate. | |
| Database Account | Enter the database account. | |
| Database Password | Enter the account password. | |
| Destination Database | Select Existing Connection | If the destination instance is registered with DTS, select it from the drop-down list. Otherwise, configure the following parameters manually. |
| Database Type | Select AnalyticDB for PostgreSQL. | |
| Access Method | Select Alibaba Cloud Instance. | |
| Instance Region | Select the region where the destination instance resides. | |
| Instance ID | Select the ID of the destination instance. | |
| Database Name | Enter the name of the database to receive the migrated data. | |
| Database Account | Enter the database account. | |
| Database Password | Enter the account password. |
Click Test Connectivity and Proceed.
Step 3: Configure migration objects
On the Configure Objects page, configure the following parameters.
| Parameter | Description |
|---|---|
| Migration Types | Select the migration types. See Choose a migration type for guidance. Note If you do not select Schema Migration, create the target tables in the destination database manually and enable object name mapping in Selected Objects. If you do not select Incremental Data Migration, do not write to the source database during migration. |
| DDL and DML Operations to Be Synchronized | Select the SQL operations for incremental migration at the instance level. To configure at the schema or table level, right-click a migration object in Selected Objects and select the operations. |
| Processing Mode of Conflicting Tables | Precheck and Report Errors (default): Reports an error if the source and destination databases have tables with identical names. The task cannot start until the conflict is resolved. Use object name mapping to rename tables in the destination if they cannot be deleted or renamed. Ignore Errors and Proceed: Skips the precheck for duplicate table names. Warning This option can cause data inconsistency. During full data migration, duplicate primary key records are not migrated — the existing destination record is retained. During incremental data migration, duplicate records overwrite existing records. If source and destination schemas differ, only some columns may be migrated or the task may fail. |
| Storage Engine Type | The storage engine for destination tables. Default: Beam. Available only when the destination instance minor version is v7.0.6.6 or later and Schema Migration is selected. |
| Capitalization of Object Names in Destination Instance | Controls the capitalization of database, table, and column names in the destination. Default: DTS default policy. See Specify the capitalization of object names. |
| Source Objects | Select objects from the Source Objects section and click the arrow icon to move them to Selected Objects. Migration objects can be selected at the schema or table level. |
| Selected Objects | Right-click an object to map its name or configure WHERE filter conditions. Click an object and then click the remove icon to remove it from the selection. Note If you use object name mapping, other objects that depend on the renamed object may fail to migrate. To filter rows, right-click a table to specify WHERE conditions. See Specify filter conditions. |
Click Next: Advanced Settings and configure the following parameters.
| Parameter | Description |
|---|---|
| Dedicated Cluster for Task Scheduling | By default, DTS schedules tasks to the shared cluster. Purchase a dedicated cluster for improved task stability. See What is a DTS dedicated cluster. |
| Retry Time for Failed Connections | How long DTS retries after a connection failure. Valid values: 10–1,440 minutes. Default: 720 minutes. Set a value above 30. If DTS reconnects within this period, the task resumes. Otherwise, the task fails. Note If multiple tasks share the same source or destination database, the most recently set retry time takes precedence. DTS charges for the instance during retries. |
| Retry Time for Other Issues | How long DTS retries after DDL or DML operation failures. Valid values: 1–1,440 minutes. Default: 10 minutes. Set a value above 10. This value must be smaller than Retry Time for Failed Connections. |
| Enable Throttling for Full Data Migration | Controls read/write throttling during full data migration 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 when Full Data Migration is selected. |
| Enable Throttling for Incremental Data Migration | Controls throttling during incremental data migration. Configure RPS of Incremental Data Migration and Data migration speed for incremental migration (MB/s). Available only when Incremental Data Migration is selected. |
| Environment Tag | An optional tag to identify the instance. |
| Configure ETL | Whether to enable extract, transform, and load (ETL). Select Yesalert notification settings to enter data processing statements in the code editor. See Configure ETL. Default: No. |
| Monitoring and Alerting | Whether to configure alerts for task failures or latency exceeding a threshold. Select Yes to configure alert thresholds and notification settings. See Configure monitoring and alerting. |
(Optional) Click Next: Configure Database and Table Fields to set Type, Primary Key Column, and Distribution Key for destination tables.
Note This step is available only when Schema Migration is selected. Set Definition Status to All to edit all tables. The Primary Key Column can be a composite primary key composed of multiple columns. Select one or more columns from the Primary Key Column as the Distribution Key. See Data table management and Table distribution definition.
Step 4: Run the precheck
Click Next: Save Task Settings and Precheck. DTS runs a precheck before the migration task starts. Results appear as one of three states:
Note To preview API parameters for calling the relevant API operation, hover over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters.State Meaning Action Passed No issues found Proceed to purchase the instance Failed Errors that will cause migration to fail Click View Details, fix the issues, then rerun the precheck Alert Warnings that may affect migration Click View Details to review. If the alert can be ignored, click Ignore, confirm, then click Precheck Again. Ignoring alerts may cause data inconsistency
Step 5: Purchase and start the instance
After Success Rate reaches 100%, click Next: Purchase Instance.
On the Purchase Instance page, configure the following parameters.
| Section | Parameter | Description |
|---|---|---|
| New Instance Class | Resource Group | The resource group for the migration instance. Default: default resource group. See What is Resource Management? |
| Instance Class | The migration speed varies by instance class. Select a class based on your requirements. See Instance classes of data migration instances. |
Read and select the Data Transmission Service (Pay-as-you-go) Service Terms check box.
Click Buy and Start, then click OK in the confirmation dialog.
Monitor the task on the Data Migration page:
Tasks without incremental data migration stop automatically when complete. The status shows Completed.
Tasks with incremental data migration run continuously. The status shows Running.