This topic describes how to migrate data from a self-managed PostgreSQL instance that resides on an Elastic Compute Service (ECS) instance or in a data center to an ApsaraDB RDS for PostgreSQL instance. The cloud migration feature of ApsaraDB RDS for PostgreSQL uses physical streaming replication to help you migrate data to the cloud in an easy-to-use, efficient manner and at a high speed with no downtime. This feature is suitable in all scenarios.

Prerequisites

  • The ApsaraDB RDS for PostgreSQL instance meets the following requirements:
    • The ApsaraDB RDS for PostgreSQL instance and the self-managed PostgreSQL instance run the same PostgreSQL version, which can be PostgreSQL 10, PostgreSQL 11, PostgreSQL 12, PostgreSQL 13, or PostgreSQL 14.
    • The ApsaraDB RDS for PostgreSQL instance is a primary instance. Read-only ApsaraDB RDS for PostgreSQL instances do not support cloud migration.
    • The ApsaraDB RDS for PostgreSQL instance is equipped with standard SSDs or enhanced SSDs (ESSDs).
    • The ApsaraDB RDS for PostgreSQL instance is empty. The available storage of the ApsaraDB RDS for PostgreSQL instance is greater than or equal to the size of the data in the self-managed PostgreSQL instance.
    • The ApsaraDB RDS for PostgreSQL instance does not use a new general-purpose instance type.
      Note The new general-purpose instance types provide better scalability and performance and reduce the time to create an RDS instance or change the specifications of an RDS instance. The new general-purpose instance types do not support the cloud migration feature. For more information, see Primary ApsaraDB RDS for PostgreSQL instance types.
  • The self-managed PostgreSQL instance meets the following requirements:

Precautions

During the cloud migration, you can read data from and write data to the self-managed PostgreSQL instance. However, do not perform operations such as migration, restart, or specification changes on the self-managed PostgreSQL instance.

Step 1: Evaluate whether the data migration is allowed

  1. Access RDS Instances, select a region at the top, and then click the ID of the target RDS instance.
  2. In the left-side navigation pane, click Migrate to Cloud. On the page that appears, click the Migration Assessment tab. Migration Assessment tab
  3. In the Select Migration Source step of the configuration wizard, select a migration source and click Next.
  4. In the Configure Destination Database step of the configuration wizard, click Next.
  5. In the Configure Source Database step of the configuration wizard, select all listed items and click Next. You must complete the preparations that are described in the listed items before you start the cloud migration.
  6. In the Initiate Migration Assessment step of the configuration wizard, configure the information about the self-managed PostgreSQL instance.
    Parameter Description
    Migration Task Name The name of the cloud migration task. ApsaraDB RDS automatically generates a name for the cloud migration task. You do not need to modify the generated name.
    Source VPC/DNS IP or Source Public/DNS IP
    • Source VPC/DNS IP
      • If the self-managed PostgreSQL instance resides on an ECS instance, enter the private IP address of the ECS instance. For more information about how to obtain the private IP address of an ECS instance, see View IP addresses.
      • If the self-managed PostgreSQL instance resides in a data center, enter a private IP address of the data center.
    • Source Public/DNS IP

      If the self-managed PostgreSQL instance resides on a device that is connected over the Internet, enter the public IP address of the device.

    Source Port The port that is used to connect to the self-managed PostgreSQL instance. You can run the netstat -a | grep PGSQL command to view the port.
    Username The username of the account that is used to connect to the self-managed PostgreSQL instance. Enter migratetest, which is the username of the account that you created in the Configure Source Database step.
    Password The password of the account that is used to connect to the self-managed PostgreSQL instance. Enter 123456, which is the password of the account that you created in the Configure Source Database step.
  7. Click Create Migration Assessment Task.
    Note During the cloud migration assessment, the status of the ApsaraDB RDS for PostgreSQL instance changes to Maintaining Instance.
    After the cloud migration assessment is complete, you can view the status of the cloud migration assessment task on the Migration Assessment tab.
    • If the value in the Status column of the cloud migration assessment task is Successful, you can start the cloud migration. For more information, see Step 2: Start the cloud migration.
    • If the value in the Status column of the cloud migration assessment task is Failed, you can click View Report in the Actions column to view and handle the reported errors. For more information about common errors, see Introduction to cloud migration assessment reports.

    After you handle the reported errors, you can click Re-access in the Actions column to run the cloud migration assessment task again.

    Migration assessment report

Step 2: Start the cloud migration

Note You can start the cloud migration only when the status of the cloud migration assessment task indicates a success.
  1. Access RDS Instances, select a region at the top, and then click the ID of the target RDS instance.
  2. In the left-side navigation pane, click Migrate to Cloud. On the page that appears, click the Migration to Cloud tab. On the tab that appears, click Create Migration Cloud Task. Create Migration Cloud Task button
  3. In the Create Migration Cloud Task dialog box, select the cloud migration assessment task whose status indicates a success in Step 1: Evaluate whether the data migration is allowed from the Associated Assessment Task drop-down list. Create Migration Cloud Task button
    Note After you select a cloud migration assessment task from the Associated Assessment Task drop-down list, ApsaraDB RDS automatically obtains the values of the Migration Source Type, Source IP/DNS, Source Port, and Username parameters. You do not need to manually configure these parameters.
  4. Click Initiate Migration to Cloud. ApsaraDB RDS automatically starts the cloud migration task.
    Notice During the cloud migration, the status of the ApsaraDB RDS for PostgreSQL instance changes to Migrating Data In. You can read data from and write data to the self-managed PostgreSQL instance. However, do not perform operations such as migration, restart, or specification changes on the self-managed PostgreSQL instance.
  5. Switch the workloads of the self-managed PostgreSQL instance to the ApsaraDB RDS for PostgreSQL instance.
    1. Click the link in the Cloud Migration Phase column of the cloud migration task to view the task progress. Cloud migration progress
    2. When the cloud migration task enters the phase of Incremental Data Synchronization, click Switchover in the Actions column of the cloud migration task to switch the workloads of the self-managed PostgreSQL instance to the ApsaraDB RDS for PostgreSQL instance.
    3. In the Switchover dialog box, configure the self-managed PostgreSQL instance to process only read requests. Alternatively, stop the connected application from writing data to the self-managed PostgreSQL instance. Switch workloads to the cloud
      Note To configure the self-managed PostgreSQL instance to process only read requests, you must run the following command by using the credentials of a superuser account:
      ALTER SYSTEM SET default_transaction_read_only=on;
      SELECT pg_reload_conf();
    4. Select all check boxes and click Switch Now. Then, wait until the cloud migration is complete.
    Cloud migration complete