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.
NoteIf 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.
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:
Network configurations
Migration source
Network configuration
Self-managed ECS-based PostgreSQL database or ApsaraDB RDS for PostgreSQL instance
If the self-managed PostgreSQL instance resides on an ECS instance, the ECS instance and the destination RDS instance must reside in the same virtual private cloud (VPC). If the source instance is an RDS instance, the source RDS instance and the destination RDS instance must reside in the same VPC. If the source instance and the destination RDS instance reside in different VPCs, you must use Cloud Enterprise Network (CEN) to connect the VPCs. For more information, see What is CEN?
Self-managed PostgreSQL database in a data center (within the same VPC as the destination database)
The data center must be able to communicate with the VPC to which the destination RDS instance belongs. For more information, see Connect a data center to a VPC.
If the self-managed PostgreSQL instance resides on an ECS instance, an ECS security group must be configured. For more information, see (Optional) Configure an ECS security group.
The configurations that are described in Configure the postgresql.conf file of a self-managed PostgreSQL instance are complete.
The configurations that are described in Create an account are complete.
The configurations that are described in Update the pg_hba.conf file are complete.
The configurations that are described in Configure the firewall of a server are complete.
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: Perform a cloud migration assessment
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.
In the left-side navigation pane, click Cloud Migration/DR Construction. On the page that appears, click the Feasibility assessment tab.
In the Configure Scenario and Source Type step of the configuration wizard, select Migration to Cloud for Scenario and ApsaraDB RDS Instance for Source. Then, click Next.
In the Configure Destination Instance step of the configuration wizard, click Next.
In the Configure Source Instance 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.
NoteFor more information about the items that are listed in the Configure Source Instance step of the configuration wizard, see (Optional) Configure an ECS security group, Create an account, and Update the pg_hba.conf file.
In the Start Feasibility Assessment step of the configuration wizard, configure the information about the self-managed PostgreSQL instance.
Parameter
Description
Migration Task Name
The 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.
Port of Source Instance
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 Create an account 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 Create an account step.Click Create Feasibility Assessment Task.
NoteDuring the feasibility 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 in Migration to Cloud section of the Feasibility assessment tab.
If the value in the Status column of the feasibility 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 feasibility 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-assess in the the Actions column of the feasibility assessment task to run it again.
Step 2: Start the cloud migration
You can start the cloud migration only when the status of the feasibility assessment task is Successful.
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 Cloud Migration/DR Construction. On the page that appears, click the Migration to Cloud tab. On the tab that appears, click Create Cloud Migration Task.
In the Create Cloud Migration Task dialog box, select the cloud migration assessment task whose status indicates a success in Step 1: Perform a cloud migration assessment from the Associated Assessment Task drop-down list.
NoteAfter 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.
Click Initiate Migration to Cloud. The system automatically starts the cloud migration task.
WarningDuring 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.
Switch the workloads of the self-managed PostgreSQL instance to the ApsaraDB RDS for PostgreSQL instance.
Click the link in the Cloud Migration Phase column of the cloud migration task to view the task progress.
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.
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.
NoteYou 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:
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();
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();
Select all check boxes and click the button for Switch now. Then, wait until the cloud migration is complete.