Use Data Transmission Service (DTS) to migrate data from a PolarDB for PostgreSQL cluster to a SelectDB instance for large-volume data analytics.
Choose a migration strategy
DTS supports three migration types that you can combine based on your requirements:
| Strategy | Migration types | When to use | Downtime |
|---|---|---|---|
| Full migration | Schema Migration + Full Data Migration | One-time migration; no new data writes during migration | Required |
| Online migration | Schema Migration + Full Data Migration + Incremental Data Migration | Zero-downtime migration; source continues to receive writes | None |
For most production workloads, use the online migration strategy. If you choose full migration only, stop all writes to the source database before starting — otherwise data inconsistency will occur between the source and destination.
Prerequisites
Before you begin, ensure that you have:
-
A destination SelectDB instance with storage space larger than the used storage space of the source PolarDB for PostgreSQL cluster. For setup instructions, see Create an instance
-
A privileged database account on the source PolarDB for PostgreSQL cluster (the account must be the database owner). For setup instructions, see Create a database account and Database management
-
A database account on the destination SelectDB instance with the following permissions: Usage_priv, Select_priv, Load_priv, Alter_priv, Create_priv, and Drop_priv. For setup instructions, see Cluster permission management and Basic permission management
-
For incremental data migration: the
wal_levelparameter of the source PolarDB for PostgreSQL cluster must be set tological. Verify and update this parameter in the cluster parameter settings -
For primary/secondary switchover during migration: the logical replication slot failover feature must be enabled on the source cluster. See Logical replication slot failover
If the source PolarDB for PostgreSQL cluster does not support the logical replication slot failover feature (for example, when Database Engine is set to PostgreSQL 14) and you trigger a primary/secondary switchover, the migration task will fail and cannot be recovered.
Limitations
Source database
-
Tables to be migrated must have a primary key or a UNIQUE NOT NULL index. Depending on your tables:
-
If all tables have a primary key or non-null unique index: ensure that table fields are unique; otherwise, duplicate data may exist in the destination database.
-
If some tables have neither a primary key nor a non-null unique index: when configuring the instance, select Schema Migration under Migration Types, then in the Configurations for Databases, Tables, and Columns step, set Engine to duplicate for these tables. Otherwise, the migration instance may fail or data may be lost.
-
-
During schema migration and full data migration, do not run DDL operations that change the database or table schema — the migration task will fail.
-
During incremental data migration, a single data change exceeding 256 MB causes the migration instance to fail unrecoverably. You must reconfigure the migration instance.
-
Long-running transactions during incremental migration can cause write-ahead logging (WAL) logs to accumulate, which may exhaust storage space on the source database.
Destination database
-
Tables in the destination SelectDB instance must use the Unique or Duplicate engine.
-
Database and table names must start with a letter. Use the object name mapping feature to rename objects that do not start with a letter, or objects with names containing Chinese characters.
-
Do not add backend (BE) nodes to the SelectDB instance during migration — the task will fail. Restart the migration instance to resume.
-
Do not create clusters in the destination SelectDB instance during migration — the task will fail. Restart the migration instance to resume.
Migration behavior
-
A migration instance can migrate only one database. To migrate multiple databases, create a separate migration instance for each database.
-
DTS does not support TimescaleDB extension tables or tables with cross-schema inheritance.
-
DTS does not validate metadata such as sequences. Verify metadata validity manually after migration.
-
When migrating partitioned tables, include both the parent table and all child partitions as migration objects. The parent table of a PostgreSQL partitioned table does not store data directly — all data resides in child partitions. Missing child partitions causes data inconsistency.
-
In a multi-table merge scenario (multiple source tables migrated to a single destination table), the schemas of all source tables must be identical.
-
You cannot run DDL operations that modify multiple columns simultaneously or modify the same table in succession.
-
DTS creates the following temporary tables in the source database during incremental migration. Do not delete them — deleting them causes the task to fail. DTS removes them automatically after the migration 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
Unique engine behavior
If the destination table uses the Unique engine, all unique keys in the destination table must exist in the source table and be included as migration objects — otherwise data inconsistency may occur.
Duplicate engine behavior
If the destination table uses the Duplicate engine:
-
DTS converts UPDATE and DELETE statements to INSERT statements.
-
Duplicate rows may appear in the destination in these cases: a retry occurred, the migration instance restarted, or two or more DML operations were performed on the same row after migration started. Use the additional columns (
_is_deleted,_version, and_record_id) to identify and remove duplicates.
Incremental data migration requirements
Before writing data to tables included in an incremental migration, run the following command on each table in the source database:
ALTER TABLE schema.table REPLICA IDENTITY FULL;
Replace schema and table with the actual schema name and table name. Run this command during off-peak hours and do not lock the tables — locking may cause a deadlock.
If you skip the related precheck item, DTS runs this command automatically during instance initialization — when the instance runs for the first time, or when the migration object granularity is set to Schema and a new table is created or rebuilt using the RENAME command.
Replication slot management
DTS creates a replication slot with the prefix dts_sync_ in the source database to replicate incremental data. The slot retains up to 15 minutes of incremental logs.
When a migration task fails or the migration instance is released, DTS attempts to clean up the replication slot automatically. Manual cleanup is required in these cases:
-
The source database account password was changed during migration.
-
The DTS IP address was removed from the whitelist during migration.
-
A primary/secondary failover occurred — log on to the secondary database to perform cleanup.
Replication slots that are not cleaned up accumulate and consume disk space, which may make the source database unavailable.
Billing
| Migration type | Link configuration cost | Data transfer cost |
|---|---|---|
| Schema migration + full data migration | Free | Free |
| Incremental data migration | Charged. See Billing overview. | — |
SQL operations supported for incremental migration
| Type | Operations |
|---|---|
| DML | INSERT, UPDATE, DELETE |
| DDL | ADD COLUMN, DROP COLUMN |
Migrate data from PolarDB for PostgreSQL to SelectDB
Step 1: Go to the Data Migration page
Use one of the following methods:
DTS console
-
Log on to the
-
In the left-side navigation pane, click Data Migration.
-
In the upper-left corner, select the region where the migration instance resides.
DMS console
The actual operation 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
-
In the top navigation bar, move the pointer over .
-
From the drop-down list to the right of Data Migration Tasks, select the region where the migration instance resides.
Step 2: Create a task
Click Create Task to go to the task configuration page.
Step 3: Configure source and destination databases
Configure the parameters described in the following table.
| Section | Parameter | Description |
|---|---|---|
| — | Task Name | A name for the DTS task. DTS generates a name automatically. Specify a descriptive name for easy identification — the name does not need to be unique. |
| Source Database | Select Existing Connection | If you have a database instance registered with DTS, select it from the drop-down list — DTS populates the remaining parameters automatically. See Manage database connections. Otherwise, configure the parameters below. |
| Database Type | Select PolarDB for PostgreSQL. | |
| Access Method | Select Alibaba Cloud Instance. | |
| Instance Region | Select the region where the source PolarDB for PostgreSQL cluster resides. | |
| Replicate Data Across Alibaba Cloud Accounts | Select No (this example uses an instance in the current account). | |
| Instance ID | Select the ID of the source PolarDB for PostgreSQL cluster. | |
| Database Name | Enter the name of the database containing the objects to migrate. | |
| Database Account | Enter the database account. See Prerequisites for required permissions. | |
| Database Password | Enter the password for the database account. | |
| Destination Database | Select Existing Connection | If you have a database instance registered with DTS, select it from the drop-down list. Otherwise, configure the parameters below. |
| Database Type | Select SelectDB. | |
| Access Method | Select Alibaba Cloud Instance. | |
| Instance Region | Select the region where the destination SelectDB instance resides. | |
| Replicate Data Across Alibaba Cloud Accounts | Select No (this example uses an instance in the current account). | |
| Instance ID | Select the ID of the destination SelectDB instance. | |
| Database Account | Enter the database account. See Prerequisites for required permissions. | |
| Database Password | Enter the password for the database account. |
After completing the configuration, click Test Connectivity and Proceed at the bottom of the page.
DTS server IP addresses must be added to the security settings of both the source and destination databases. DTS can add these IP addresses automatically, or you can add them manually. See Add DTS server IP addresses to a whitelist.
Step 4: Configure migration objects
On the Configure Objects page, set the following parameters.
| Parameter | Description |
|---|---|
| Migration Types | Select the migration types based on your strategy: <br>- Full migration (no downtime tolerance): Select Schema Migration and Full Data Migration. Stop all writes to the source before starting. <br>- Online migration (zero downtime): Select Schema Migration, Full Data Migration, and Incremental Data Migration. |
| Processing Mode of Conflicting Tables | - Precheck and Report Errors: DTS checks for tables with the same name in the destination. If duplicates exist, the precheck fails. To resolve, rename the destination table using the object name mapping feature. <br>- Ignore Errors and Proceed: DTS skips the duplicate-name check. Warning
This may cause data inconsistency — if schemas match, source records overwrite destination records with the same primary key; if schemas differ, migration may fail or produce incomplete data. Use with caution. |
| Capitalization of Object Names in Destination Instance | Controls the capitalization of database, table, and column names in the destination. The default is DTS default policy. See Specify the capitalization of object names in the destination instance. |
| Source Objects | Select the objects to migrate. Click the |
| Selected Objects | - To map an object to a different name or destination, right-click the object and select the mapping option. See Map object names. <br>- To remove an object, click it and then click the bucket_count parameter for a table (available when Schema Migration is selected and migration object granularity is table): right-click the table, set Enable Parameter Settings to Yes, enter the value, and click OK. <br>- To filter rows by SQL conditions, right-click a table and specify the conditions. See Specify filter conditions. <br>- To select which SQL operations to migrate incrementally, right-click an object and select the operations. |
-
If you do not select Schema Migration, create the destination tables manually with the Unique or Duplicate data model before starting migration. See Data type mappings, Additional columns, and Data models.
-
The
bucket_countparameter value must be a positive integer. The default value is auto. -
If you use object name mapping to rename an object, other objects that depend on it may fail to migrate.
-
Object name mapping applies to databases, tables, and columns. If a name contains Chinese characters, rename it to an ASCII-only name — otherwise the task may fail.
Step 5: Configure advanced settings
Click Next: Advanced Settings and configure the following parameters.
| Parameter | Description |
|---|---|
| Dedicated Cluster for Task Scheduling | By default, DTS uses a shared cluster. Purchase a dedicated cluster to improve migration task stability. See What is a DTS dedicated cluster. |
| Retry Time for Failed Connections | How long DTS retries after a connection failure. Valid range: 10–1,440 minutes. Default: 720 minutes. Set to a value greater than 30. If DTS reconnects within the retry window, the task resumes; otherwise, it fails. Note: If multiple tasks share the same source or destination database, the last-configured retry time takes precedence. DTS charges for the instance during retries. |
| Retry Time for Other Issues | How long DTS retries after non-connection failures (such as DDL or DML errors). Valid range: 1–1,440 minutes. Default: 10 minutes. Set to a value greater than 10. Must be less than Retry Time for Failed Connections. |
| Enable Throttling for Full Data Migration | Limits the read/write load on source and destination databases during full migration. 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 | Limits the load during incremental 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 | (Optional) Tag the instance with an environment label. |
| Configure ETL | Enables the extract, transform, and load (ETL) feature. Select Yes to enter data processing statements. See Configure ETL in a data migration or data synchronization task. |
| Monitoring and Alerting | Configures alerts for task failures or latency exceeding a threshold. Select Yes to configure alert thresholds and notification settings. See Configure monitoring and alerting. |
Step 6: Configure database and table fields (optional)
Click Next: Configure Database and Table Fields to set the Primary Key Column, Distribution Key, and Engine for destination tables.
This step is available only when Schema Migration is selected. To view all tables, set Definition Status to All.
Primary Key Column can be a composite primary key. Select one or more columns from Primary Key Column to use as the Distribution Key.
For tables without a primary key or UNIQUE constraint, set Engine to duplicate — otherwise migration may fail or data may be lost.
Step 7: Run the precheck
Click Next: Save Task Settings and Precheck.
To preview the API parameters for configuring this task, hover over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters before proceeding.
DTS runs a precheck before starting the migration. If the precheck fails:
-
For failed items: click View Details, analyze the results, resolve the issues, then click Precheck Again.
-
For alert items: if the alert can be ignored, click Confirm Alert Details > Ignore > OK > Precheck Again. Note that ignoring alerts may cause data inconsistency.
Step 8: Purchase the instance
-
Wait until Success Rate reaches 100%, then click Next: Purchase Instance.
-
On the Purchase Instance page, configure the instance class:
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 instance class determines migration speed. See Instance classes of data migration instances. -
Read and select the Data Transmission Service (Pay-as-you-go) Service Terms checkbox.
-
Click Buy and Start, then click OK in the confirmation dialog.
Monitor progress on the Data Migration page:
-
Full migration only: the task stops automatically when complete. Status shows Completed.
-
Incremental migration included: the task runs continuously and never stops automatically. Status shows Running.
During full data migration, DTS consumes read and write resources on both the source and destination databases, which increases database load. Run migration during off-peak hours when CPU load on both databases is below 30%.
Data type mappings
Data types are converted when migrating from PolarDB for PostgreSQL to SelectDB. Review the mappings before migration, especially for types with potential precision or semantic differences.
| Category | PolarDB for PostgreSQL type | SelectDB type |
|---|---|---|
| Numeric | SMALLINT | SMALLINT |
| INTEGER | INT | |
| BIGINT | BIGINT | |
| DECIMAL | DECIMAL | |
| NUMERIC | DECIMAL | |
| REAL | DOUBLE | |
| DOUBLE | DOUBLE | |
| SMALLSERIAL | SMALLINT | |
| SERIAL | INT | |
| BIGSERIAL | BIGINT | |
| Monetary | MONEY | STRING |
| Character | CHAR(n), VARCHAR(n) | VARCHAR |
| TEXT | STRING | |
| Binary | BYTEA | STRING |
| Date and time | TIMESTAMP [(P)] [WITHOUT TIME ZONE] | DATETIMEV2 |
| TIMESTAMP [(P)] WITH TIME ZONE | DATETIMEV2 | |
| DATE | DATEV2 | |
| TIME [(P)] [WITHOUT TIME ZONE] | VARCHAR(50) | |
| TIME [(P)] WITH TIME ZONE | VARCHAR(50) | |
| INTERVAL [FIELDS] [(P)] | STRING | |
| Boolean | BOOLEAN | BOOLEAN |
| Geometric | POINT, LINE, LSEG, BOX, PATH, POLYGON, CIRCLE | STRING |
| Network address | CIDR, INET, MACADDR, MACADDR8 | STRING |
| Text search | TSVECTOR | STRING |
| XML | XML | STRING |
| JSON | JSON | JSON |
Key conversion notes:
-
CHAR(n) and VARCHAR(n): Converted to
VARCHAR(4*n)to prevent data loss from multi-byte characters. If no length is specified, SelectDB uses the defaultVARCHAR(65533). If the resulting length exceeds 65,533, the data is converted toSTRING.
Additional columns
DTS automatically adds the following columns to destination tables that use the Duplicate engine. These columns let you identify and remove duplicate records.
| Column | Data type | Default | Value |
|---|---|---|---|
_is_deleted |
Int | 0 | INSERT or UPDATE: 0. DELETE: 1. |
_version |
Bigint | 0 | Full migration: 0. Incremental migration: timestamp in seconds from the source binary log. |
_record_id |
Bigint | 0 | Full migration: 0. Incremental migration: the record ID of the incremental log entry (unique and auto-incrementing). |
Usage notes
Incremental migration latency
DTS uses a batch synchronization policy to reduce load on the destination. By default, each synchronization object is written at most once every 5 seconds, resulting in a normal synchronization latency usually within 10 seconds.
To reduce latency, adjust the selectdb.reservoir.timeout.milliseconds parameter of the migration instance in the DTS console. The valid range is 1,000–10,000 milliseconds.
A lower batching time increases write frequency, which raises the load and response time on the destination. This can in turn increase synchronization latency. Adjust based on the destination's actual load.
Instance failure recovery
If a migration instance fails, DTS support will attempt recovery within 8 hours. During recovery, the instance may be restarted or its parameters adjusted (only DTS instance parameters are modified — database parameters are not changed). For the list of parameters that may be modified, see Modify instance parameters.
Off-peak migration
Run migration during off-peak hours when the CPU load on both the source and destination databases is below 30%. This reduces the risk of performance degradation on production workloads.