This topic describes how to use the cloud migration feature 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 or later.
      Note If you want to migrate data from an instance that runs PostgreSQL 10 to an RDS instance that runs PostgreSQL 13, you must use the cloud migration feature to migrate the data from the source PostgreSQL instance to an RDS instance that runs PostgreSQL 10 and then upgrade the major engine version of the RDS instance to PostgreSQL 13 based on the descriptions in Upgrade the major engine version of an ApsaraDB RDS for PostgreSQL instance.
    • The ApsaraDB RDS for PostgreSQL instance is a primary instance. Read-only ApsaraDB RDS for PostgreSQL instances do not support cloud migration.
    • The RDS instance is equipped with cloud disks.
    • 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 self-managed PostgreSQL instance meets the following requirements:

Usage notes

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

Step 1: Evaluate whether cloud 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.
  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.
    ParameterDescription
    Migration Task NameThe system automatically generates a name for the cloud migration task. You do not need to modify the generated name.
    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 PortThe 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.
    UsernameThe 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 Create an account for cloud migration on a self-managed PostgreSQL instance step.
    PasswordThe 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 Create an account for cloud migration on a self-managed PostgreSQL instance 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 the button for initiating another assessment 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 Cloud Migration Task. Create Cloud Migration Task button
  3. In the Create Cloud Migration Task dialog box, select the cloud migration assessment task whose status indicates a success in Step 1: Evaluate whether cloud 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, the system 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. The system automatically starts the cloud migration task.
    Warning 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. 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 Phase
    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 You can configure the source instance to process only read requests.
      • If the source instance is an ApsaraDB RDS for PostgreSQL instance, perform the following steps:
        1. Change the value of the rds_force_trans_ro_non_sup parameter of the RDS instance to on. For more information, see Modify the parameters of an ApsaraDB RDS for PostgreSQL instance.
        2. Execute the following statement to terminate all existing sessions:
          SELECT pg_terminate_backend(pid) FROM pg_stat_activity 
          WHERE usename not in ('replicator', 'monitor', 'pgsql', 'aurora') AND pid != pg_backend_pid();
      • If the source instance is a self-managed PostgreSQL instance, perform the following steps:
        -- Configure the self-managed PostgreSQL instance to process only read requests.
        ALTER SYSTEM SET default_transaction_read_only=on;
        
        -- Reload the parameter configuration for the modification to take effect.
        SELECT pg_reload_conf();
        
        -- Terminate all existing sessions.
        SELECT pg_terminate_backend(pid) FROM pg_stat_activity 
        WHERE usename not in ('replicator', 'monitor', 'pgsql', 'aurora') AND pid != pg_backend_pid();
    4. Select all check boxes and click the button for Switch now. Then, wait until the cloud migration is complete.
    Cloud migration complete