Incremental migration from Amazon RDS for PostgreSQL to Alibaba Cloud

更新时间:
复制 MD 格式

Use Data Transmission Service (DTS) to migrate a database from Amazon RDS for PostgreSQL to ApsaraDB RDS for PostgreSQL. DTS supports schema migration, full data migration, and incremental data migration, which you can combine to minimize application downtime.

Prerequisites

  • The source Amazon RDS for PostgreSQL instance must be running version 10.4 or later.

  • To allow DTS to connect to the Amazon RDS for PostgreSQL instance over the Internet, set Public accessibility 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 its parameter group.

  • Create a destination ApsaraDB RDS for PostgreSQL instance. Create an ApsaraDB RDS for PostgreSQL instance.

    Note
    • The destination instance major version should match the source. To migrate across major versions, create a pay-as-you-go instance to verify compatibility.

    • The destination instance must have more storage than the source databases being migrated.

Notes

  • A full data migration consumes read and write resources on both the source and destination databases, increasing their server load. This added load can degrade performance or cause service unavailability, especially if your databases have poor performance, low specifications, or are already busy (for example, with many slow SQL queries, tables without primary keys, or deadlocks in the destination database). Before you start the migration, evaluate the performance of both databases and perform the migration during off-peak hours, for example, when CPU utilization is below 30%.

  • Tables without a primary key, unique constraint, or other uniqueness guarantee may produce duplicate data or cause migration failure.

  • Each migration task handles one database. Create separate tasks for multiple databases.

  • Only DML operations (INSERT, DELETE, and UPDATE) are replicated.

  • DTS creates a replication slot prefixed with dts_sync_ in Amazon RDS for PostgreSQL. Stale slots are cleaned up every 90 minutes to prevent disk space consumption.

    Note

    DTS automatically cleans up the replication slot when a task is released or fails. After a primary/secondary switchover, manually clean up the replication slot on the secondary database.

    Amazon replication slot query

  • A primary/secondary switchover on the Amazon RDS for PostgreSQL instance causes the migration task to fail. Recovery may not be possible.

  • DTS automatically recovers failed migration tasks. Stop or release the task before switching workloads to the destination instance to prevent automatic recovery from overwriting destination data.

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. For more information, see Billing overview.

Incremental data migration

Charged. For more information, see Billing overview.

Migration types

  • Schema migration

    DTS migrates the following object types to ApsaraDB RDS for PostgreSQL: TABLE, TRIGGER, VIEW, SEQUENCE, FUNCTION, USER DEFINED TYPE, RULE, DOMAIN, OPERATION, and AGGREGATE.

    Note

    DTS does not migrate functions written in C.

  • Full data migration

    DTS migrates all data from the source objects to ApsaraDB RDS for PostgreSQL.

  • Incremental data migration

    After full data migration, DTS replicates ongoing changes to ApsaraDB RDS for PostgreSQL, minimizing application downtime.

Database account permissions

Database

Schema migration

Full data migration

Incremental data migration

Amazon RDS for PostgreSQL

USAGE permission on pg_catalog

SELECT permission on migration objects

rds_superuser permission

ApsaraDB RDS for PostgreSQL

CREATE and USAGE permissions on migration objects

schema owner permission

schema owner permission

Data migration process

To avoid failures caused by object dependencies, DTS migrates schema and data in the following order.

  1. Migrate the schemas for TABLE, VIEW, SEQUENCE, FUNCTION, USER DEFINED TYPE, RULE, DOMAIN, OPERATION, and AGGREGATE.

  2. Run the full data migration.

  3. Migrate the schemas for TRIGGER and FOREIGN KEY.

  4. Run the incremental data migration.

    Note

    Before starting the incremental data migration, do not perform DDL operations on the migration objects. Otherwise, the migration may fail.

Prerequisites

  1. Log on to the Amazon RDS Management Console.

  2. In the upper-right corner of the page, select the region where the destination instance is located.

  3. In the left-side navigation pane, click Database. Click the database identifier of the destination database to open its Basic Information page.

    Click database identifier

  4. In the Security group rules section, click the name of the security group.

    安全组规则

  5. 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 DTS server CIDR blocks for the region where your destination database is located. For example, if your source database is in Singapore and your destination database is in China (Hangzhou), add only the DTS server CIDR blocks for the China (Hangzhou) region.

    • You can add all the required CIDR blocks at once instead of adding a separate inbound rule for each.

    • If you have other questions, refer to the official Amazon documentation or contact Amazon technical support.

Procedure (new console)

  1. Navigate to the migration task list page for the destination region using one of the following methods.

    From the DTS console

    1. Log on to the Data Transmission Service (DTS) console.

    2. In the navigation pane on the left, click Data Migration.

    3. In the upper-left corner of the page, select the region where the migration instance is located.

    From the DMS console

    Note

    The 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.

    1. Log on to the Data Management (DMS) console.

    2. In the top menu bar, choose Data + AI > Data Transmission (DTS) > Data Migration.

    3. To the right of Data Migration Tasks, select the region where the migration instance is located.

  2. Click Create Task to navigate to the task configuration page.

  3. Configure the source and destination databases.

    Warning

    After 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.

    Section

    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

    Database Type

    Select PostgreSQL.

    Connection Type

    Select Public IP Address.

    Instance Region

    Select the region of the Amazon RDS for PostgreSQL instance.

    Note

    If your instance region is not listed, select the nearest region.

    Domain Name or IP

    Enter the endpoint of the Amazon RDS for PostgreSQL instance.

    Note

    Find the endpoint on the Basic Information page of the Amazon RDS for PostgreSQL instance.

    Port Number

    Enter the service port of the Amazon RDS for PostgreSQL instance. Default: 5432.

    Database Name

    Enter the name of the source database on the Amazon RDS for PostgreSQL instance.

    Database Account

    Enter the database account for the Amazon RDS for PostgreSQL instance. Required permissions: Permissions required for database accounts.

    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

    Database Type

    Select PostgreSQL.

    Connection Type

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region of the destination ApsaraDB RDS for PostgreSQL instance.

    Instance ID

    Select the ID of the destination ApsaraDB RDS for PostgreSQL instance.

    Database Name

    Enter the destination database name in the ApsaraDB RDS for PostgreSQL instance. The name can differ from the source database name.

    Note

    The database must already exist in the ApsaraDB RDS for PostgreSQL instance. Create a database.

    Database Account

    Enter the database account for the destination ApsaraDB RDS for PostgreSQL instance. Required permissions: Permissions required for database accounts.

    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.

  4. 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.

    Note

    Ensure 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.

  5. Configure the task objects.

    1. 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. Selecting Full Data Migration is also recommended.

      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.

        Note

        If 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.

        Warning

        Selecting 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 Rightwards arrow icon and add the objects to the Selected Objects section.

      Note

      The 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

      Note
      • If you use the object name mapping feature, dependent objects might not migrate successfully.

      • To filter data with a WHERE clause, right-click the table in the Selected Objects box and specify filter conditions. Filter task data by using SQL conditions.

      • To select SQL operations to migrate at the schema or table level, right-click the object in the Selected Objects box and select the desired SQL operations in the dialog box that appears.

    2. 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.

      Important

      The 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

      Select environment tags to identify the instance. Optional.

      Configure ETL

      Choose whether to enable the extract, transform, and load (ETL) feature. For more information, see What is ETL? Valid values:

      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 contact. If a migration fails or the latency exceeds the threshold, the system sends an alert notification.

    3. Click Next: Data Validation to configure a data validation task.

      For more information about the data validation feature, see Configure data validation.

  6. 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.

  7. Purchase the instance.

    1. When the Success Rate is 100%, click Next: Purchase Instance.

    2. 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.

    3. After the configuration is complete, read and select Data Transmission Service (Pay-as-you-go) Service Terms.

    4. 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)

  1. Log on to the DTS console.

    Note

    If you are automatically redirected to the Data Management (DMS) console, you can click the jiqiren icon in the lower-right corner and then click 返回旧版 to return to the classic DTS console.

  2. In the left-side navigation pane, click Data Migration.

  3. At the top of the Migration Tasks page, select the region of the destination cluster.

  4. In the upper-right corner of the page, click Create Data Migration Task.

  5. Configure the source and destination databases.

    Source and destination database configuration

    Category

    Parameter

    Description

    N/A

    Task name

    DTS auto-generates a task name. Specify a descriptive name for easy identification. Uniqueness is not required.

    Source instance

    Instance type

    Select user-created database with public IP address.

    Instance region

    The source instance region. Not required when user-created database with public IP address is selected as the instance type.

    Database type

    Select PostgreSQL.

    Hostname or IP address

    Enter the endpoint of the Amazon RDS for PostgreSQL instance.

    Note

    Find the endpoint on the Basic Information page of the Amazon RDS for PostgreSQL instance.

    Endpoint

    Port number

    Enter the service port of the Amazon RDS for PostgreSQL instance. Default: 5432.

    Database name

    Enter the name of the database to migrate from the Amazon RDS for PostgreSQL instance.

    Database account

    Enter the database account for the Amazon RDS for PostgreSQL instance. For the required permissions, see Permissions required for database accounts.

    Database password

    Enter the password for the database account.

    Note

    After you enter the source database information, you can click Test Connectivity next to Database Password to verify that the information is correct. If the information is correct, a Passed message appears. If a Failed message appears, click Diagnose after Failed and follow the prompts to adjust the source database information.

    Destination instance

    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 ApsaraDB RDS for PostgreSQL instance.

    Database name

    Enter the destination database name in the ApsaraDB RDS for PostgreSQL instance. The name can differ from the source database name.

    Note

    The database must exist in the ApsaraDB RDS for PostgreSQL instance. If it does not exist, create a database.

    Database account

    Enter the database account for the ApsaraDB RDS for PostgreSQL instance. For the required permissions, see Permissions required for database accounts.

    Database password

    Enter the password for the database account.

    Note

    After you enter the target database information, you can click Test Connectivity next to Database Password to verify that the entered information is correct. If the information is correct, a Passed message is displayed. If a Failed message is displayed, click Diagnose next to Failed, and adjust the target database information based on the prompts.

  6. After you complete 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.

    Warning

    Adding public IP addresses 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, such as using strong passwords, restricting open ports, using authentication for internal APIs, regularly reviewing and limiting unnecessary network segments, or connecting by using private connections such as Express Connect, VPN Gateway, or Smart Access Gateway.

  7. Select the migration objects and migration types.

    Select migration types and objects

    Parameter

    Description

    Migration types

    Select Schema Migration, Full Data Migration, and Incremental Data Migration.

    Migration objects

    In the Available box, select the objects to migrate and click the Right arrow icon icon to move them to the Selected Objects box.

    Note
    • You can select migration objects at the schema, table, or column level.

    • By default, object names remain unchanged after migration. To rename objects in the destination instance, use the Object name mapping feature.

    • If you use the object name mapping feature, the migration of other dependent objects might fail.

    Rename mapped objects

    To rename migration objects in the destination instance, use Object name mapping.

    Retry duration for a failed connection

    Default: 12 hours. If DTS reconnects within the specified duration, the task resumes automatically. Otherwise, the task fails.

    Note

    The DTS instance incurs charges during the retry period. Set a retry duration based on your needs, or release the DTS instance when the source and destination instances are released.

  8. 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.

  9. After the task passes the precheck, click Next.

  10. 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.

  11. Click Buy and Start to start the migration task.

    Note

    The migration task does not stop automatically. Stop the task during off-peak hours or when you are ready to switch to the destination instance.

    1. Wait until the task progress changes to Incremental Data Migration and the status shows Undelayed. Then, stop writing data to the source database for a few minutes. During this time, the Incremental Data Migration status might show a delay.

    2. Wait until the Incremental Data Migration status changes back to Undelayed, then manually stop the migration task.Stop incremental migration task

  12. Switch your business to the ApsaraDB RDS for PostgreSQL instance.