This topic describes how to migrate data from an Amazon RDS for PostgreSQL instance to an ApsaraDB RDS for PostgreSQL instance using DTS. DTS supports schema migration, full data migration, and incremental data migration. Combining these migration types allows you to migrate your database without interrupting your self-managed applications.
Prerequisites
-
The Amazon RDS for PostgreSQL instance must be version 10.4 or later.
-
To allow DTS to connect to the Amazon RDS for PostgreSQL instance over the internet, set Publicly accessible to Yes.
-
To allow DTS to read incremental data from the Amazon RDS for PostgreSQL instance, set the rds.logical_replication parameter to 1 in the parameter group.
-
You must have an ApsaraDB RDS for PostgreSQL instance. For more information, see Create an ApsaraDB RDS for PostgreSQL instance.
Note-
We recommend that the major version of the ApsaraDB RDS for PostgreSQL instance is the same as that of the Amazon RDS for PostgreSQL instance. To migrate data between different major versions, create a pay-as-you-go instance to verify compatibility.
-
The ApsaraDB RDS for PostgreSQL instance must have more available storage space than the storage space used by the database on the Amazon RDS for PostgreSQL instance.
-
Considerations
-
During a full data migration, DTS consumes read and write resources on the source and destination databases, increasing their load. If your databases have poor performance, low specifications, or high workloads (for example, if the source database has many slow SQL queries or tables without primary keys, or if deadlocks occur in the destination database), the increased load can strain your databases or even cause service interruptions. Perform the data migration during off-peak hours, such as when the CPU utilization of both databases is below 30%.
-
If a table being migrated lacks a primary key or unique constraint, duplicate data might be created in the destination database, causing the migration to fail.
-
A data migration task can migrate only one database. To migrate multiple databases, you must create a separate data migration task for each.
-
Only DML operations (INSERT, DELETE, and UPDATE) are supported.
-
During data migration, DTS creates a replication slot in Amazon RDS for PostgreSQL. This replication slot is prefixed with
dts_sync_. To prevent the replication slot from consuming excessive disk space, DTS automatically cleans up historical replication slots every 90 minutes.NoteDTS automatically cleans up the replication slot if the data migration task is released or fails. If a primary/secondary switchover occurs on the Amazon RDS for PostgreSQL instance, you must manually log on to the secondary database to clean up the slot.
You can run the
SELECT * FROM pg_replication_slots;command in a PostgreSQL client to query information about replication slots. Verify that the logical replication slot created by DTS with the prefix dts_sync_ and a slot_type of logical is active (its active column is true). -
A primary/secondary switchover on the Amazon RDS for PostgreSQL instance causes the DTS task to fail, and it may not be resumable.
-
If a data migration task fails, DTS automatically triggers recovery. Before you switch your workloads to the destination instance, you must stop or release the task. Otherwise, if the task is automatically recovered, source data may overwrite data in the destination instance.
Billing
|
Migration type |
Task configuration fee |
Internet traffic fee |
|
Schema migration and full data migration |
Free of charge. |
DTS charges an Internet traffic fee when the Access Method of the destination database is set to Public IP Address. Billing overview. |
|
Incremental data migration |
Charged. Billing overview. |
Migration types
-
Schema migration
DTS migrates the schemas of the following object types to an ApsaraDB RDS for PostgreSQL instance:
table,trigger,view,sequence,function,user-defined type,rule,domain,operation, andaggregate.NoteDTS does not support migrating functions written in the C programming language.
-
Full data migration
DTS migrates all data from specified objects to the destination ApsaraDB RDS for PostgreSQL instance.
-
Incremental data migration
After a full data migration, DTS migrates incremental updates to the ApsaraDB RDS for PostgreSQL instance, which enables a seamless migration without application downtime.
Database account permissions
|
Database |
Schema migration |
Full data migration |
Incremental data migration |
|
Amazon RDS for PostgreSQL |
USAGE permission on the pg_catalog schema |
SELECT permission on the objects to migrate |
rds_superuser permission |
|
ApsaraDB RDS for PostgreSQL |
CREATE and USAGE permissions on the objects to migrate |
Schema owner permissions |
Schema owner permissions |
Data migration process
To resolve object dependencies and improve the migration success rate, DTS migrates the PostgreSQL schema and data in the following order:
-
Schema migration for tables, views, sequences, functions, user-defined types, rules, domains, operations, and aggregates.
-
Full data migration.
-
Schema migration for triggers and foreign keys.
-
Incremental data migration.
NoteDo not perform DDL operations on migration objects in the Amazon RDS for PostgreSQL instance before the incremental data migration. Doing so can cause the migration to fail.
Before you begin
-
Log on to the Amazon RDS Management Console.
-
In the upper-right corner of the page, select the region of your destination instance.
-
In the left-side navigation pane, click Database. Then, click the destination database's identifier to view the Basic Information page.
-
In the Security group rules section, click the security group name of the inbound rule.
-
On the Security group settings page, add the IP addresses of the DTS servers for the target region to the inbound rules. For details about the IP address ranges, see Add IP addresses of DTS servers to the IP allowlist of an on-premises database.
Click the Inbound rules tab, and then click Edit inbound rules. In the Edit inbound rules dialog box, set Type to custom TCP rule and Port range to 5432. For Source, select Custom and enter the IP addresses of the corresponding DTS servers. Click Save rules.
Note-
Add only the CIDR blocks for DTS servers in the destination database's region. For example, if your source database is in the Singapore region and your destination database is in the China (Hangzhou) region, you only need to add the CIDR blocks for DTS servers in the China (Hangzhou) region.
-
You can add multiple CIDR blocks to a single rule.
-
For more information, see the official AWS documentation or contact AWS Support.
-
Procedure (new console)
-
Navigate to the migration task list page for the destination region using one of the following methods.
From the DTS console
-
Log on to the Data Transmission Service (DTS) console.
-
In the navigation pane on the left, click Data Migration.
-
In the upper-left corner of the page, select the region where the migration instance is located.
From the DMS console
NoteThe actual operations may vary based 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 Data Management (DMS) console.
-
In the top menu bar, choose .
-
To the right of Data Migration Tasks, select the region where the migration instance is located.
-
-
Click Create Task to navigate to the task configuration page.
-
Configure the source and destination databases.
WarningAfter you select the source and destination instances, we recommend that you carefully read the limits displayed at the top of the page. Otherwise, the task may fail or data inconsistency may occur.
Category
Parameter
Description
N/A
Task Name
DTS automatically generates a task name. We recommend that you specify a descriptive name for easy identification. The name does not need to be unique.
Source Database
Select a DMS database instance.
You can choose whether to use an existing instance, as needed.
-
If you use an existing instance, the database information below is automatically filled in. You do not need to enter it again.
-
If you do not use an existing instance, you must configure the database information below.
Note-
In the DMS console, you can click Add DMS Database Instance to register a database with DMS. For more information, see ApsaraDB Data Ingestion and Register a database hosted on a third-party cloud service or a self-managed database.
-
In the DTS console, you can register a database with DTS on the Database Connections page or the new configuration page. For more information, see Manage database connections.
Database Type
Select PostgreSQL.
Connection Type
Select Public IP Address.
Instance Region
Select the region where the Amazon RDS for PostgreSQL database is located.
NoteIf the region of the Amazon RDS for PostgreSQL database is not in the drop-down list, you can select the region that is geographically closest to the database.
Domain Name or IP
Enter the endpoint of the Amazon RDS for PostgreSQL instance.
NoteYou can find the endpoint on the Basic Information page of your Amazon RDS for PostgreSQL instance.
Port Number
Enter the service port of the Amazon RDS for PostgreSQL instance. The default value is 5432.
Database Name
Enter the name of the database on the Amazon RDS for PostgreSQL instance that you want to migrate.
Database Account
Enter the database account of the Amazon RDS for PostgreSQL instance. For information about the required permissions, see Database account permissions.
Database Password
Enter the password for the database account.
Encryption
Select a connection method. In this example, Non-encrypted is selected.
If you need to connect to the database by using SSL encryption, select SSL-encrypted, and then upload the CA Certificate, Client Certificate, and Private Key of Client Certificate as needed. Then, enter the Private Key Password of Client Certificate.
Note-
If you select SSL-encrypted for a self-managed PostgreSQL database, you must upload the CA Certificate.
-
If you need to use a client certificate, you must upload both the Client Certificate and the Private Key of Client Certificate, and then enter the Private Key Password of Client Certificate.
-
For information about the SSL encryption feature for an RDS for PostgreSQL instance, see SSL connection encryption.
Destination Database
Select a DMS database instance.
You can choose whether to use an existing instance, as needed.
-
If you use an existing instance, the database information below is automatically filled in. You do not need to enter it again.
-
If you do not use an existing instance, you must configure the database information below.
Note-
In the DMS console, you can click Add DMS Database Instance to register a database with DMS. For more information, see ApsaraDB Data Ingestion and Register a database hosted on a third-party cloud service or a self-managed database.
-
In the DTS console, you can register a database with DTS on the Database Connections page or the new configuration page. For more information, see Manage database connections.
Database Type
Select PostgreSQL.
Connection Type
Select Alibaba Cloud Instance.
Instance Region
Select the region where the destination ApsaraDB RDS for PostgreSQL instance is located.
Instance ID
Select the instance ID of the destination ApsaraDB RDS for PostgreSQL instance.
Database Name
Enter the name of the database in the ApsaraDB RDS for PostgreSQL instance where you want to migrate data. The name can be different from that of the source database.
NoteMake sure that this database is created in the destination ApsaraDB RDS for PostgreSQL instance. For more information, see Create a database.
Database Account
Enter the database account of the destination ApsaraDB RDS for PostgreSQL instance. For information about the required permissions, see Database account permissions.
Database Password
Enter the password for the database account.
Encryption
Select a connection method. In this example, Non-encrypted is selected.
If you need to connect to the database by using SSL encryption, select SSL-encrypted, and then upload the CA Certificate, Client Certificate, and Private Key of Client Certificate as needed. Then, enter the Private Key Password of Client Certificate.
Note-
If you select SSL-encrypted for a self-managed PostgreSQL database, you must upload the CA Certificate.
-
If you need to use a client certificate, you must upload both the Client Certificate and the Private Key of Client Certificate, and then enter the Private Key Password of Client Certificate.
-
For information about the SSL encryption feature for an RDS for PostgreSQL instance, see SSL connection encryption.
-
-
After you complete the configuration, click Test Connectivity and Proceed at the bottom of the page. In the CIDR Blocks of DTS Servers dialog box that appears, click Test Connectivity.
NoteEnsure that the IP address segments of the DTS service are automatically or manually added to the security settings of the source and destination databases to allow access from DTS servers. For more information, see Add DTS server IP addresses to a whitelist.
-
Configure the task objects.
-
On the Configure Objects page, configure the objects that you want to migrate.
Parameter
Description
Migration Types
Select both Schema Migration and Incremental Data Migration. We recommend that you also select Full Data Migration.
Processing Mode of Conflicting Tables
-
Precheck and Report Errors: Checks whether tables with the same names exist in the destination database. If no tables with the same names exist, the precheck is passed. If tables with the same names exist, an error is reported during the precheck, and the data migration task does not start.
NoteIf a table in the destination database has the same name but cannot be easily deleted or renamed, you can change the name of the table in the destination database. For more information, see Object name mapping.
-
Ignore Errors and Proceed: Skips the check for tables with the same names.
WarningSelecting Ignore Errors and Proceed may cause data inconsistency and business risks. For example:
-
If the table schemas are consistent and a record in the destination database has the same primary key value as a record in the source database:
-
During full migration, DTS keeps the record in the destination database. The record from the source database is not migrated.
-
During incremental migration, DTS does not keep the record in the destination database. The record from the source database overwrites the record in the destination database.
-
-
If the table schemas are inconsistent, only some columns of data may be migrated, or the migration may fail. Proceed with caution.
-
Capitalization of Object Names in Destination Instance
You can configure the case sensitivity policy for the names of migrated objects, such as databases, tables, and columns, in the destination instance. By default, DTS default policy is selected. You can also choose to keep the case sensitivity consistent with the default policy of the source or destination database. For more information, see Case sensitivity of object names in the destination database.
Source Objects
Select one or more objects from the Source Objects section. Click the
icon and add the objects to the Selected Objects section. NoteThe granularity for selecting migration objects is schema, table, and column. If you select only tables or columns as migration objects, other objects such as views, triggers, and stored procedures are not migrated to the destination database.
Selected Objects
-
To change the name of a single migration object in the target instance, right-click the object in the Selected Objects box. For more information, see Map individual schema, table, and column names.
-
To change the names of multiple migration objects in the target instance, click Selected Objects in the upper-right corner of the Batch Edit box. For more information, see Map multiple schema, table, and column names.
Note-
If you use the object name mapping feature, other objects that depend on the renamed object may fail to migrate.
-
To filter data by using WHERE conditions, right-click the table to migrate in the Selected Objects box, and specify the filter conditions in the dialog box that appears. For more information, see Filter data by using SQL conditions.
-
To select the SQL operations to migrate at the database or table level, right-click the object in the Selected Objects box, and select the desired SQL operations in the dialog box that appears.
-
-
Click Next: Advanced Settings to configure advanced parameters.
Parameter
Description
Dedicated Cluster for Task Scheduling
By default, DTS schedules tasks on a shared cluster. You do not need to select one. If you want more stable tasks, you can purchase a dedicated cluster to run DTS migration tasks.
Retry Time for Failed Connections
After the migration task starts, if the connection to the source or destination database fails, DTS reports an error and immediately begins to retry the connection. The default retry duration is 720 minutes. You can customize the retry time to a value from 10 to 1440 minutes. We recommend that you set the duration to more than 30 minutes. If DTS reconnects to the source and destination databases within the specified duration, the migration task automatically resumes. Otherwise, the task fails.
Note-
For multiple DTS instances that share the same source or destination, the network retry time is determined by the setting of the last created task.
-
Because you are charged for the task during the connection retry period, we recommend that you customize the retry time based on your business needs, or release the DTS instance as soon as possible after the source and destination database instances are released.
Retry Time for Other Issues
After the migration task starts, if a non-connectivity issue, such as a DDL or DML execution exception, occurs in the source or destination database, DTS reports an error and immediately begins to retry the operation. The default retry duration is 10 minutes. You can customize the retry time to a value from 1 to 1440 minutes. We recommend that you set the duration to more than 10 minutes. If the related operations succeed within the specified retry duration, the migration task automatically resumes. Otherwise, the task fails.
ImportantThe value of Retry Time for Other Issues must be less than the value of Retry Time for Failed Connections.
Enable Throttling for Full Data Migration
During full migration, DTS consumes read and write resources on the source and destination databases, which may increase the database load. If required, you can enable throttling for the full migration task. You can set Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s) to reduce the load on the destination database.
Note-
This configuration item is available only if you select Full Data Migration for Migration Types.
-
You can also adjust the full migration speed after the migration instance is running.
Enable Throttling for Incremental Data Migration
If required, you can also choose to set speed limits for the incremental migration task. You can set RPS of Incremental Data Migration and Data migration speed for incremental migration (MB/s) to reduce the load on the destination database.
Note-
This configuration item is available only if you select Incremental Data Migration for Migration Types.
-
You can also adjust the incremental migration speed after the migration instance is running.
Environment Tag
You can select an environment tag to identify the instance based on your requirements. This parameter is optional.
Configure ETL
Choose whether to enable the extract, transform, and load (ETL) feature. For more information, see What is ETL? Valid values:
-
Yes: Enables the ETL feature. Enter data processing statements in the code editor. For more information, see Configure ETL in a data migration or data synchronization task.
-
No: Disables the ETL feature.
Monitoring and Alerting
Select whether to set alerts and receive alert notifications based on your business needs.
-
No: Does not set an alert.
-
Yes: Configure alerts by setting an alert threshold and an alert notifications. If a migration fails or the latency exceeds the threshold, the system sends an alert notification.
-
-
Click Next: Data Validation to configure a data validation task.
For more information about the data validation feature, see Configure data validation.
-
-
Save the task and run a precheck.
-
To view the parameters for configuring this instance when you call the API operation, move the pointer over the Next: Save Task Settings and Precheck button and click Preview OpenAPI parameters in the bubble that appears.
-
If you do not need to view or have finished viewing the API parameters, click Next: Save Task Settings and Precheck at the bottom of the page.
Note-
Before the migration task starts, DTS performs a precheck. The task starts only after it passes the precheck.
-
If the precheck fails, click View Details next to the failed check item, fix the issue based on the prompt, and then run the precheck again.
-
If a warning is reported during the precheck:
-
For check items that cannot be ignored, click View Details next to the failed item, fix the issue based on the prompt, and then run the precheck again.
-
For check items that can be ignored, you can click Confirm Alert Details, Ignore, OK, and Precheck Again to skip the alert item and run the precheck again. If you choose to ignore a warning, it may cause issues such as data inconsistency and pose risks to your business.
-
-
-
Purchase the instance.
-
When the Success Rate is 100%, click Next: Purchase Instance.
-
On the Purchase page, select the link specification for the data migration instance. For more information, see the following table.
Category
Parameter
Description
New Instance Class
Resource Group Settings
Select the resource group to which the instance belongs. The default value is default resource group. For more information, see What is Resource Management?
Instance Class
DTS provides migration specifications with different performance levels. The link specification affects the migration speed. You can select a specification based on your business scenario. For more information, see Data migration link specifications.
-
After the configuration is complete, read and select Data Transmission Service (Pay-as-you-go) Service Terms.
-
Click Buy and Start. In the OK dialog box that appears, click OK.
You can view the progress of the migration task on the Data Migration Tasks list page.
Note-
If the migration task does not include incremental migration, it stops automatically after the full migration is complete. After the task stops, its Status changes to Completed.
-
If the migration task includes incremental migration, it does not stop automatically. The incremental migration task continues to run. While the incremental migration task is running, the Status of the task is Running.
-
-
Procedure (old console)
-
Log on to the DTS console.
NoteIf you are automatically redirected to the Data Management (DMS) console, you can click the
icon in the lower-right corner and then click
to return to the classic DTS console. -
In the left-side navigation pane, click Data Migration.
-
At the top of the Migration Tasks page, select the region of the destination cluster.
-
In the upper-right corner of the page, click Create Data Migration Task.
-
Configure the source and destination databases.
Category
Parameter
Description
N/A
Task name
DTS automatically generates a task name. We recommend specifying a descriptive name for easy identification. Task names do not need to be unique.
Source instance information
Instance type
Select User-created database with public IP address.
Instance region
Select the region of the source instance. This parameter is not required if you set Instance type to User-created database with public IP address.
Database type
Select PostgreSQL.
Hostname or IP address
Enter the connection endpoint of the Amazon RDS for PostgreSQL instance.
NoteYou can find the database connection information on the Basic Information page of Amazon RDS for PostgreSQL.
In the Amazon RDS console, go to the instance's details page. In the Connectivity & security section, copy the value from the Endpoint field. This is your database connection endpoint (for example, xxx.rds.amazonaws.com).
Port
Enter the service port of the Amazon RDS for PostgreSQL instance. The default is 5432.
Database name
Enter the name of the database to be migrated from the Amazon RDS for PostgreSQL instance.
Database account
Enter the account for the Amazon RDS for PostgreSQL database. For information about account permissions, see Database account permissions.
Database password
Enter the password for the database account.
NoteAfter you configure the source database, click Test Connectivity next to Database Password to test the connection. If the test passes, Passed is displayed. If Failed is displayed, click Diagnose next to Failed and adjust the settings based on the results.
Destination instance information
Instance type
Select RDS Instance.
Instance region
Select the region of the ApsaraDB RDS for PostgreSQL instance.
RDS instance ID
Select the ID of the destination ApsaraDB RDS for PostgreSQL instance.
Database name
Enter the name of the destination database in the ApsaraDB RDS for PostgreSQL instance. The name can be different from the source database name.
NoteThe database must exist in the ApsaraDB RDS for PostgreSQL instance. If it does not exist, create a database.
Database account
Enter the account for the ApsaraDB RDS for PostgreSQL database. For information about account permissions, see Database account permissions.
Database password
Enter the password for the database account.
NoteAfter you configure the destination database, click Test Connectivity next to Database Password to test the connection. If the test passes, Passed is displayed. If Failed is displayed, click Diagnose next to Failed and adjust the settings based on the results.
-
After completing the configuration, click Set Whitelist and Next in the lower-right corner of the page.
If the source or destination is an Alibaba Cloud database instance, such as ApsaraDB for MySQL or ApsaraDB for MongoDB, DTS automatically adds the IP addresses of its servers in the corresponding region to the instance's whitelist. If the source or destination is a self-managed database on an ECS instance, DTS automatically adds its IP addresses to the security rules of the ECS instance. You must also ensure that the self-managed database does not restrict access from the ECS instance. If the database is a cluster deployed across multiple ECS instances, you must manually add the DTS IP addresses to the security rules for each ECS instance. If the source or destination is a database in an on-premises data center or on another cloud, you must manually add the DTS IP addresses for the corresponding region to allow access from DTS servers. For a list of DTS server IP addresses, see DTS server IP addresses.
WarningAdding the public CIDR blocks of DTS servers, whether automatically or manually, may introduce security risks. By using this product, you acknowledge and accept these potential risks. You are responsible for implementing basic security measures, including but not limited to using strong passwords, restricting open ports, using authentication for internal API calls, regularly reviewing and restricting unnecessary network segments, or connecting through private networks such as Express Connect, VPN Gateway, or Smart Access Gateway.
-
Select migration types and migration objects.
Parameter
Description
Migration types
Select the Schema Migration, Full Data Migration, and Incremental Data Migration checkboxes.
Migration objects
In the Available section, select the objects you want to migrate, and then click the
icon to move them to the Selected Objects section.Note-
You can select migration objects at the schema, table, or column level.
-
By default, the names of migration objects remain unchanged after migration. To rename a migration object in the destination instance, you can use the object name mapping feature. For more information, see Object name mapping.
-
If you use object name mapping, other objects that depend on the renamed object might fail to migrate.
Map or rename objects
To rename migration objects in the destination instance, use the object name mapping feature. For more information, see Object name mapping.
Connection retries
The default retry duration is 12 hours. You can specify a custom duration. If DTS loses connection to the source or destination database, it attempts to reconnect. If it reconnects within the specified duration, the migration task automatically resumes. Otherwise, the task fails.
NoteDTS charges for instance runtime, including the time spent on connection retries. We recommend setting a reasonable retry duration based on your business needs, or release the DTS instance as soon as possible after the source and destination instances are released.
-
After you complete the configuration, click Precheck and Start in the lower-right corner of the page.
Note-
Before the migration task starts, DTS runs a precheck. The task can start only after it passes the precheck.
-
If the precheck fails, click the
icon next to the failed item to view details.-
Fix the issues as prompted and run the precheck again.
-
If you do not need to fix the warning items, you can select Ignore and then click Ignore Warnings and Rerun Precheck to run the precheck again.
-
-
-
After the task passes the precheck, click Next.
-
In the Confirm Settings dialog box that appears, select a Instance Class and select the Data Transmission Service (pay-as-you-go) Service Terms checkbox.
-
Click Buy and Start to start the migration task.
NoteThe migration task does not stop automatically. You must stop it manually. Choose an appropriate time to stop the task, such as during off-peak hours or when you are ready to switch your business to the destination instance.
-
Wait for the task to enter the Incremental Data Migration phase with a status of Undelayed. Then, stop write operations on the source database for a few minutes. The Incremental Data Migration status may now show a latency.
-
Wait for the Incremental Data Migration status to return to Undelayed. To stop the task, select its checkbox and click Stop in the batch operations bar at the bottom of the page.
-
-
Switch your business applications to the ApsaraDB RDS for PostgreSQL instance.