ApsaraDB RDS for PostgreSQL provides the cloud migration feature. You can use the feature to migrate the data of a self-managed PostgreSQL instance that is deployed on an Alibaba Cloud Elastic Compute Service (ECS) instance or in a data center to an ApsaraDB RDS for PostgreSQL instance. You can also use the feature to reduce the storage capacity of an ApsaraDB RDS for PostgreSQL instance. This topic describes how to use the cloud migration feature to scale down an ApsaraDB RDS for PostgreSQL instance.

Background information

When you change the specifications of your RDS instance, you cannot reduce the storage capacity of the RDS instance. You can use the cloud migration feature to migrate the data of the original RDS instance to a new RDS instance whose storage capacity is less than the storage capacity of the original RDS instance based on your business requirements. This way, you can reduce the storage capacity that you purchased.

The cloud migration feature has the following benefits:
  • Data is migrated by using physical streaming replication in an easy-to-use and efficient manner and at a high speed with minimum downtime.
  • Data is migrated over an internal network, which is secure and free of charge.
  • Cloud migration has a few limits. Specifically, the destination RDS instance is a primary instance that uses standard SSDs or enhanced SSDs (ESSDs) and runs the same major engine version as the source RDS instance.
  • The destination RDS instance can provide the same performance and statistics as the source RDS instance.

Prerequisites

The destination RDS instance is created and meets the following conditions:
  • The source RDS instance and the destination RDS instance run the same major engine version. The supported major engine versions are PostgreSQL 10, PostgreSQL 11, PostgreSQL 12, PostgreSQL 13, and PostgreSQL 14.
  • The destination RDS instance is a primary instance. Read-only RDS instances do not support cloud migration.
  • The destination RDS instance is equipped with standard SSDs or ESSDs.
  • The destination RDS instance is empty.
  • The storage capacity of the destination RDS instance is planned before cloud migration. We recommend that you reserve more than 20% of the storage capacity.

    For example, if the occupied storage of the source RDS instance is 200 GB, the storage capacity of the destination RDS instance must be at least 250 GB based on the following formula:

    200/(1 - 20%) = 250 GB

Procedure

Note This topic describes how to migrate data between two ApsaraDB RDS for PostgreSQL instances that reside in the same virtual private cloud (VPC) in the China (Hangzhou) region. The source RDS instance has a storage capacity of 500 GB, and 200 GB of storage is used. The destination RDS instance has a storage capacity of 250 GB.
  1. Configure the source RDS instance.
    1. Add the CIDR block of the VPC to which the destination RDS instance belongs to an IP address whitelist of the source RDS instance.
      For more information see Configure an IP address whitelist for an ApsaraDB RDS for PostgreSQL instance.
      To view the CIDR block of the VPC to which the destination RDS instance belongs, perform the following operations:
      1. Visit the RDS instance list , select a region above, and click the target instance ID.
      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, view the VPC CIDR Block parameter.
    2. Create a privileged account for the source RDS instance.
      For more information, see Create an account on an ApsaraDB RDS for PostgreSQL instance. When you create a privileged account, you must set the Account Type parameter to Privileged Account.
      Note The privileged account is used to migrate data and must have the CREATE ROLE, REPLICATION, and pg_monitor permissions. If a privileged account is created for the source RDS instance, you do not need to perform this operation.
  2. Configure the destination RDS instance.
    1. Perform a cloud migration assessment.
      1. Visit the RDS instance list , select a region above, and click the target instance ID.
      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. Before you start the cloud migration, you must complete the preparations that are described in the listed items.
      6. In the Initiate Migration Assessment step of the configuration wizard, configure the information about the source RDS instance.
        Parameter Description
        Migration Task Name Enter a name for 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 IP/DNS Enter the internal endpoint of the source RDS instance. For more information, see View and change the internal and public endpoints and port numbers of an ApsaraDB RDS for PostgreSQL instance.
        Source Port Enter the internal port number of the source RDS instance. For more information, see View and change the internal and public endpoints and port numbers of an ApsaraDB RDS for PostgreSQL instance.
        Username Enter the username of the privileged account of the source RDS instance.
        Password Enter the password of the privileged account of the source RDS instance.
      7. Click Create Migration Assessment Task.
        Note During the cloud migration assessment, the status of the destination RDS instance indicates that the instance is in maintenance.
        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 status of the cloud migration assessment task indicates a success, you can start the cloud migration.
        • If the status of the cloud migration assessment task indicates a failure, 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.
        Status of cloud migration assessment
    2. Migrate data to the destination RDS instance.
      1. Visit the RDS instance list , select a region above, and click the target instance ID.
      2. In the left-side navigation pane, click Migrate to Cloud. On the page that appears, click the Migrate to Cloud tab. On the tab that appears, click the 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 from the Associated Assessment Task drop-down list.
        Note After you select a cloud migration assessment task from the Associated Assessment Task drop-down list, ApsaraDB RDS automatically determines the values of the Migration Source Type, Source/DNS IP, Source Port, and Username parameters. You do not need to 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 destination RDS instance changes to Migrating Data In. You can read and write data to the source RDS instance. However, do not migrate data from or to the source RDS instance, restart the source RDS instance, or change the specifications of the source RDS instance.
      After you start the cloud migration task, the page that is shown in the following figure is displayed.Migration to cloud
    3. Switch the workloads of the source RDS instance over to the destination RDS instance.
      1. Click the link in the Cloud Migration Phase column to view the progress of the cloud migration task. Cloud migration progress
      2. When the cloud migration task enters the phase for incremental data synchronization, click the button for a switchover in the Actions column of the cloud migration task to switch the workloads of the source RDS instance to the destination RDS instance.
      3. In the dialog box that appears, configure the source RDS instance to process only read requests. Otherwise, stop the connected application from writing data to the source RDS instance.
        Note You can also use the privileged account of the source RDS instance to execute the following statements to configure the source RDS instance to process only read requests:
        ALTER SYSTEM SET default_transaction_read_only=on;
        
        SELECT pg_reload_conf();
        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 an immediate switchover. Then, wait until the cloud migration is complete.
        After the workloads of the source RDS instance are switched over to the destination RDS instance, the page that is shown in the following figure is displayed.Migration complete

What to do next

To connect your applications to the destination RDS instance without the need to modify business code after the scale-down, perform the following steps on the destination RDS instance:

  1. Modify the whitelist settings of the destination RDS instance to ensure that the whitelists of the destination RDS instance are the same as the whitelists of the source RDS instance. For more information, see Configure an IP address whitelist for an ApsaraDB RDS for PostgreSQL instance.
  2. Change the endpoints that are used to connect to the destination RDS instance to ensure that these endpoints are the same as the endpoints that are used to connect to the source RDS instance. For more information, see View and change the internal and public endpoints and port numbers of an ApsaraDB RDS for PostgreSQL instance.
    For example, if the endpoint that is used to connect to the source RDS instance is pgm-aaa.pg.rds.aliyuncs.com and the endpoint that is used to connect to the destination RDS instance is pgm-bbb.pg.rds.aliyuncs.com, perform the following steps to change the endpoints:
    1. Change the endpoint that is used to connect to the source RDS instance from pgm-aaa.pg.rds.aliyuncs.com to pgm-ccc.pg.rds.aliyuncs.com.
    2. Change the endpoint that is used to connect to the destination RDS instance from pgm-bbb.pg.rds.aliyuncs.com to pgm-aaa.pg.rds.aliyuncs.com.