Migrate data between ApsaraDB RDS for PostgreSQL instances across accounts

Updated at:

Use one-click cloud migration to move data between ApsaraDB RDS for PostgreSQL instances across accounts. The feature also supports self-managed databases on ECS or in data centers.

Prerequisites

  • The ApsaraDB RDS for PostgreSQL instances must meet the following requirements:

    • The source and destination instances run the same major version of PostgreSQL. PostgreSQL 10 and later are supported.

    • The destination instance is a primary instance. Read-only instances do not support one-click cloud migration.

    • The destination instance uses cloud disks.

    • The destination instance contains no data and has enough available storage for all data from the source instance.

    • The VPC CIDR blocks of the source and destination instances do not overlap.

  • Cross-account migration requires cross-account authorization for network instances. For more information, see Cross-account authorization for network instances.

Usage notes

Cross-account migration requires Cloud Enterprise Network (CEN) to connect the instances over an internal network. CEN incurs additional charges. For more information, see Billing overview.

Procedure

Note

This example migrates data from an RDS PostgreSQL instance in Account A to an instance in Account B. Account B also owns the CEN instance.

  1. In Account B, configure CEN to connect the two RDS PostgreSQL instances over an internal network.

    1. Create a CEN instance.

      1. Log on to the CEN console.

      2. On the CEN Instance page, click Create CEN Instance.

      3. On the Create CEN Instance page, configure the parameters in the following table and click OK.

        Parameter

        Description

        Name

        The name of the CEN instance.

        Description

        The description of the CEN instance.

    2. Attach both VPCs to the CEN instance.

      1. On the CEN Instance page, click the CEN instance ID.

      2. On the Basic Information page, click the Attach a network instance icon next to the VPC count to attach a VPC to the CEN instance.

      3. On the Connection with Peer Network Instance page, configure the parameters in the following table and click Confirm Creation.

        Note

        Attach the source and destination VPCs separately. The following table describes the source VPC configuration. Repeat the procedure for the destination VPC. Change the Region and Networks parameters to the destination instance's region and VPC. Set Account to Current Account.

        Parameter

        Description

        Instance Type

        The default value is VPC. Leave this setting unchanged.

        Region

        Select the region in which the source instance resides.

        Transit Router

        If no transit router exists in the region, CEN creates one. Select its primary and secondary zones.

        Account

        After you select Another Account, enter the UID of Account A, which owns the source instance.

        Note

        Click the user icon in the top navigation bar to view the account UID.

        Connection Name

        Specify a custom name.

        Networks

        Select the source instance's VPC. In the ApsaraDB RDS console, go to the Database Connection page of the source instance. Confirm that the network type is VPC, and record the VPC ID (such as vpc-2z***) and the internal port 5432.

        Select a vSwitch in each of the transit router's primary and secondary zones.

      After both VPCs are attached, check the Basic Information page. In this example, the VPC count is 2. The Transit Router list contains two instances: one for Account A in China (Beijing) and one for Account B in China (Hangzhou). Both have the status Available, confirming that the cross-account connections are ready.

    3. (Optional) Purchase cross-region bandwidth.

      Note

      Perform this step only if the instances are in different regions, such as Account A in China (Beijing) and Account B in China (Hangzhou). For instances in the same region, skip to step 2: Configure the source instance.

      1. On the CEN Instance page, click the CEN instance ID.

      2. On the Basic Information page, click the Bandwidth Plans tab, and then click Purchase Bandwidth Plan (Subscription).

      3. On the purchase page, configure the bandwidth plan as described in the following table. Click Buy Now and complete the payment.

        Parameter

        Description

        Product Type

        • Non-cross-border: connects areas within the Chinese mainland or areas outside the Chinese mainland. Examples include Chinese mainland to Chinese mainland and Asia Pacific to North America.

        • Cross-border: connects the Chinese mainland to an area outside the Chinese mainland, such as North America.

        In this example, select Non-cross-border.

        CEN

        Keep the current CEN instance selected. The bandwidth plan is automatically associated with this instance after purchase.

        Area A

        Select the geographic area of the network instances to connect. In this example, select Chinese Mainland.

        Note

        The selected areas cannot be changed after the bandwidth plan is created.

        Area B

        Select the geographic area of the network instances to connect. In this example, select Chinese Mainland.

        Billing Method

        The bandwidth plan's billing method. The default is Pay-By-Bandwidth.

        Bandwidth value

        Select the bandwidth in Mbps.

        Bandwidth Plan Name

        Enter the name of the bandwidth plan.

        Duration

        Select the subscription duration of the bandwidth plan.

        Select Auto-renewal to enable auto-renewal for the bandwidth plan.

        Resource Group

        Select the resource group to which the bandwidth plan belongs.

        This parameter is available only for non-cross-border bandwidth plans.

      After purchase, go to the Bandwidth Plans tab and confirm that the bandwidth plan is associated with the CEN instance. This example uses 50 Mbps.

    4. (Optional) Set the cross-region bandwidth.

      Note

      Perform this step only if the instances are in different regions, such as Account A in China (Beijing) and Account B in China (Hangzhou). For instances in the same region, skip to step 2: Configure the source instance.

      1. On the CEN Instance page, click the CEN instance ID.

      2. On the Basic Information page, click the Bandwidth Plans tab, and then click Set Inter-region Bandwidth.

      3. On the Connection with Peer Network Instance page, configure the cross-region connection and click OK.

        Parameter

        Description

        Instance Type

        Select Inter-region Connection.

        Region

        The region of the source instance. In this example, select China (Beijing).

        Transit Router

        The existing transit router is selected automatically.

        Peer Region

        The region of the destination instance. In this example, select China (Hangzhou).

        Transit Router

        The existing transit router is selected automatically.

        Bandwidth Allocation Method

        Select how to allocate bandwidth. Valid values:

        • Allocate from Bandwidth Plan

        • Pay-By-Data-Transfer

        This topic uses Allocate from Bandwidth Plan as an example.

        Bandwidth Plan

        Select a bandwidth plan associated with the CEN instance.

        Note

        Configure this parameter only when Bandwidth Allocation Method is set to Allocate from Bandwidth Plan.

        Bandwidth

        Enter the allowed bandwidth in Mbps.

        Default Line Type

        The link type used by default. Valid values:

        • Platinum

        • Gold

        Note

        When Bandwidth Allocation Method is set to Pay-By-Data-Transfer, Platinum is available. Otherwise, it is unavailable.

      After creating the connection, go to the Bandwidth Plans tab. Confirm that Allocated Bandwidth matches the configured value, such as 50 Mbps. This confirms that the cross-region bandwidth is configured.

  2. Configure the source instance.

    1. Configure the IP whitelist.

      Follow the instructions in Configure an IP address whitelist. Set IP Addresses to the VPC CIDR block of the destination instance.

      How to find the VPC CIDR block

      1. Log on to the ApsaraDB RDS console and go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the instance ID.

      2. In the left navigation bar, click Database Connection, and view the VPC CIDR block under Network Type. On the Database Connection page for the instance, you can view the Network Type (Virtual Private Cloud (VPC)), the VPC CIDR block (such as 172.1x.xxx.xx/12), the internal endpoint (such as pgm-bp**.rds.aliyuncs.com), and the status of the public endpoint. Note the VPC CIDR block information because you may need it for future network configurations.

    2. Create a privileged account.

      For information about how to create an account, see Create an account. Set Account Type to privileged account.

      Note

      The migration account must have the CREATE ROLE, REPLICATION, and pg_monitor permissions. Use an existing privileged account if one is available.

  3. Configure the destination instance.

    1. Perform the cloud migration assessment.

      1. Log on to the ApsaraDB RDS console and go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the instance ID.

      2. In the left-side navigation pane, click Cloud Migration/DR Deployment and then click the Feasibility Assessment tab.

      3. In the Configure Scenario and Source Type step of the configuration wizard, set the scenario to Migration to Cloud and set the source to ApsaraDB RDS Instance. Click Next.

      4. In the Configure Destination Instance step, click Next.

      5. In the Configure Source Instance step, select all configuration preparation items and click Next.

      6. In the Start Feasibility Assessment step, configure the source database information.

        Parameter

        Description

        Migration Task Name

        The task name is generated automatically. Leave it unchanged.

        Source VPC/DNS IP

        Enter the internal endpoint of the source instance. For more information, see View and change the endpoints and port numbers.

        Source Port

        Enter the port of the source instance. For more information, see View and change the endpoints and port numbers.

        Username

        Enter the privileged account created on the source instance.

        Password

        Enter the password of the source instance's privileged account.

      7. Click Create Feasibility Assessment Task.

        Note

        During the migration assessment task, the instance status changes to Maintaining Instance.

        After the assessment finishes, go to the Feasibility Assessment page. Check the task status in the Migration to Cloud list.

    2. Migrate data to the cloud.

      1. Log on to the ApsaraDB RDS console and go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the instance ID.

      2. In the left-side navigation pane, click Cloud Migration/DR Deployment. On the Migration to Cloud tab, click Create Cloud Migration Task.

      3. In the Create Cloud Migration Task dialog box, select a successful cloud migration assessment task from the Associated Assessment Task list.

        Note

        After Associated Assessment Task is selected, the Migration Source Type, Source IP/ DNS, Source Port, and Username parameters are filled in automatically. No manual configuration is required.

      4. Click Initiate Migration to Cloud. The migration task starts automatically.

        Important

        During migration, the destination instance status changes to Migrating Data In. The source instance remains readable and writable. Do not run another migration, restart the source instance, or change its specifications.

    3. Promote the destination ApsaraDB RDS for PostgreSQL instance to the primary instance.

      1. To monitor the migration, click the link in the Cloud Migration Phase column.

      2. When the migration reaches Incremental Data Synchronization, go to the Actions column and click Switchover. This promotes the destination RDS PostgreSQL instance to the primary instance so that it can serve application workloads.

      3. In the Switchover dialog box, follow the instructions to make the source instance read-only or stop application writes.

        Note

        Perform the following steps to set the source instance to read-only:

        1. In Configure instance parameters, set the rds_force_trans_ro_non_sup parameter of the source instance to on.

        2. Run 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();
      4. Select all check boxes, click Switch Now, and wait for the migration to complete.