ApsaraDB RDS for PostgreSQL supports the cloud migration feature. You can use this feature to migrate data between ApsaraDB RDS for PostgreSQL instances.
Prerequisites
The following requirements are met:
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, PostgreSQL 14, and PostgreSQL 15.
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 enhance SSDs (ESSDs).
The destination RDS instance is empty. The available storage of the destination RDS instance is greater than or equal to the size of the data in the source RDS instance.
The CIDR block of the virtual private cloud (VPC) to which the source RDS belongs is different from the CIDR block of the VPC to which the destination RDS instance belongs.
Usage notes
When you migrate data between the RDS instances that reside in different regions, you must use Cloud Enterprise Network (CEN) to enable cross-region communication between the source RDS instance and the destination RDS instance over an internal network. You are charged for cross-region communication that is based on CEN. For more information, see What is CEN? and Billing.
Procedure
In this example, the source RDS instance resides in the China (Beijing) region, and the destination RDS instance resides in the China (Hangzhou) region.
Create a CEN instance and configure the CEN instance to enable cross-region communication between the source RDS instance and the destination RDS instance over an internal network.
Create a CEN instance.
Log on to the CEN console.
On the Instances page, click Create CEN Instance.
In the Create CEN Instance dialog box, configure the following parameters and click OK.
Parameter
Description
Name
Enter a name for the CEN instance.
The name must be 2 to 128 characters in length and can contain letters, digits, hyphens (-), and underscores (_). The name must start with a letter.
Description
Enter a description for the CEN instance.
The description must be 2 to 256 characters in length and cannot start with
http://
orhttps://
. You can leave this parameter empty.
Add the VPC of the source RDS instance and the VPC of the destination RDS instance to the CEN instance.
On the Instances page, click the ID of the CEN instance.
On the Basic Settings tab of the details page, click the icon to the right of the number that is displayed below VPC.
On the Connection with Peer Network Instance page, configure the following parameters and click OK.
NoteYou must separately add the VPC of the source RDS instance and the VPC of the destination RDS instance to the CEN instance. This example shows how to add the VPC of the source RDS instance to the CEN instance. You can use the same method to add the VPC of the destination RDS instance to the CEN instance. Take note that the values of the Region and Networks parameters for the source RDS instance and the destination RDS instance are different.
Parameter
Description
Network Type
Retain the default value VPC.
Region
Select the region in which the source RDS instance resides. In this example, select China (Beijing).
Transit Router
By default, no transit routers are available in the selected region. CEN automatically creates a transit router. You must select the primary zone and secondary zone of the transit router.
Resource Owner ID
Select Your Account.
Attachment Name
Enter an attachment name.
Networks
Select the ID of the VPC to which the source RDS instance belongs. You can view the VPC ID on the Database Connection page of the source RDS instance in the ApsaraDB RDS console.
After you specify the VPC, select the vSwitches that are associated with the primary zone and secondary zone of the transit router.
After you add the VPC of the source RDS instance and the VPC of the destination RDS instance to the CEN instance, the page that is shown in the following figure is displayed.
Purchase a bandwidth plan for the CEN instance.
On the Instances page, click the ID of the CEN instance.
On the Basic Settings tab of the details page, click the Bandwidth Plans tab. On the Bandwidth Plans tab, click Purchase Bandwidth Plan (Subscription).
On the page that appears, configure the following parameters and click Buy Now. Then, complete the payment.
Parameter
Description
CEN ID
Retain the CEN instance that is displayed. After you purchase a bandwidth plan, the bandwidth plan is automatically associated with the CEN instance.
Area A
Select an area for which you want to enable cross-region communication. In this example, select Mainland China.
NoteYou cannot change the area after the bandwidth plan is purchased.
Area B
Select the other area for which you want to enable cross-region communication. In this example, select Mainland China.
Billing Method
Select a billing method for the bandwidth plan. Retain the default value Pay by Bandwidth.
Bandwidth
Specify the bandwidth that is provided by the bandwidth plan. Unit: Mbit/s.
Name
Enter a name for the bandwidth plan.
Order time
Select a subscription duration for the bandwidth plan.
You can select Auto-renewal to enable auto-renewal for the bandwidth plan.
After you purchase a bandwidth plan, the page that is shown in the following figure is displayed.
Configure the bandwidth for cross-region communication.
On the Instances page, click the ID of the CEN instance.
On the Basic Settings tab of the details page, click the Bandwidth Plans tab. On the Bandwidth Plans tab, click Set Region Connection.
On the Connection with Peer Network Instance page, configure the following parameters and click OK.
Parameter
Description
Network Type
Select Inter-region Connection.
Region
Select the region in which the source RDS instance resides. In this example, select China (Beijing).
Transit Router
CEN automatically identifies the transit router in the region in which the source RDS instance resides.
Peer Region
Select the region in which the destination RDS instance resides. In this example, select China (Hangzhou).
Transit Router
CEN automatically identifies the transit router in the region in which the destination RDS instance resides.
Bandwidth Plan
Select a bandwidth plan that is associated with the CEN instance.
Bandwidth
Enter the bandwidth that is provided by the bandwidth plan. Unit: Mbit/s.
After the operation is successful, the page that is shown in the following figure is displayed.
Configure the source RDS instance.
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. You must set the IP Addresses parameter to the CIDR block of the VPC to which the destination RDS instance belongs.
Create a privileged account for the source RDS instance.
For more information, see Create an account. When you create a privileged account, you must set the Account Type parameter to Privileged Account.
NoteThe privileged account is used to migrate data and must have the CREATE ROLE, REPLICATION, and pg_monitor permissions. If you have a privileged account, skip this step.
Configure the destination RDS instance.
Perform a cloud migration assessment.
- 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 ID of the instance.
In the left-side navigation pane, click Migrate to Cloud. On the page that appears, click the Migration Assessment tab.
In the Select Migration Source step of the configuration wizard, select Self-managed ECS-based PostgreSQL Database or ApsaraDB RDS for PostgreSQL Instance and click Next.
In the Configure Destination Database step of the configuration wizard, click Next.
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.
In the Initiate Migration Assessment step of the configuration wizard, configure the information about the source RDS instance.
Parameter
Description
Migration Task Name
ApsaraDB RDS automatically generates a name for the cloud migration task. You do not need to modify the generated name.
Source VPC/DNS IP
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 that is created for the source RDS instance.
Password
Enter the password of the privileged account that is created for the source RDS instance.
Click Create Migration Assessment Task.
NoteDuring the cloud migration assessment, the status of the destination RDS 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 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.
Migrate data to the destination RDS instance.
- 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 ID of the instance.
In the left-side navigation pane, click Migrate to Cloud. On the page that appears, click the Migration to Cloud tab. On the Migration to Cloud tab, click Create Cloud Migration Task.
In the Create Cloud Migration Task dialog box, select the cloud migration assessment task whose status indicates a success from the Associated Assessment Task drop-down list.
NoteAfter 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.
Click Initiate Migration to Cloud. ApsaraDB RDS automatically starts the cloud migration task.
ImportantDuring the cloud migration, the status of the destination RDS instance changes to Migrating Data In. You can read data from 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.
Switch the workloads of the source RDS instance over to the destination RDS instance.
Click the link in the Cloud Migration Phase column to view the progress of the cloud migration task.
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.
In the Switchover dialog box, configure the source RDS instance to process only read requests. Alternatively, stop the connected application from writing data to the source RDS instance.
NoteTo configure the source RDS instance to process only read requests, perform the following steps:
- 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.
- 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();
Select all check boxes and click Switch Now. Then, wait until the cloud migration is complete.
What to do next
To connect your applications to the destination RDS instance without the need to modify business code after the migration, perform the following operations on the destination RDS instance:
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.
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 endpoints and port numbers.
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 ispgm-bbb.pg.rds.aliyuncs.com
, perform the following steps to change the endpoints:Change the endpoint that is used to connect to the source RDS instance from
pgm-aaa.pg.rds.aliyuncs.com
topgm-ccc.pg.rds.aliyuncs.com
.Change the endpoint that is used to connect to the destination RDS instance from
pgm-bbb.pg.rds.aliyuncs.com
topgm-aaa.pg.rds.aliyuncs.com
.