This document describes how to migrate a MyBase for PostgreSQL instance to an ApsaraDB RDS for PostgreSQL instance by using Cloud Migration.
Prerequisites
Create an ApsaraDB RDS for PostgreSQL instance that meets the following requirements:
The version and category must match those of the source MyBase for PostgreSQL instance.
The disk space must be larger than the space used by the source MyBase for PostgreSQL instance.
The instance family must be dedicated.
For more information about how to create an instance, see Quickly create an ApsaraDB RDS for PostgreSQL instance.
NoteFor internal network migration, make sure that the destination ApsaraDB RDS for PostgreSQL instance is in the same region and VPC as the source MyBase for PostgreSQL instance.
For public network migration, make sure that you have applied for public endpoints for both the ApsaraDB RDS for PostgreSQL and MyBase for PostgreSQL instances. For more information, see Apply for a public endpoint for an ApsaraDB RDS for PostgreSQL instance and Apply for a public endpoint for a MyBase for PostgreSQL instance.
Configure an IP whitelist to ensure that the ApsaraDB RDS for PostgreSQL and MyBase for PostgreSQL instances can access each other. For more information, see Configure an IP whitelist for an ApsaraDB RDS for PostgreSQL instance and Configure an IP whitelist for a MyBase for PostgreSQL instance.
You can log on to the ApsaraDB RDS or ApsaraDB for MyBase console to view the internal CIDR block of your instance. In the navigation pane on the left, click Database Connection. On this page, find the Network Type row to view the instance's internal CIDR block, such as
172.x.x.x. The internal port is5432.Create a high-privilege account for the MyBase for PostgreSQL instance. For more information, see Create a database account.
Precautions
During the Cloud Migration task, you can read from and write to the source MyBase for PostgreSQL database. However, do not perform operations such as another migration, a restart, or specification changes.
If you set the MyBase for PostgreSQL instance to read-only, your applications can only read from the instance.
Instances of the new general-purpose instance family do not support migration over the public network.
Step 1: Feasibility 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 navigation pane on the left, click Cloud Migration/Disaster Recovery. Then, click the Feasibility Assessment tab.
In the Select Scenario and Source Type step of the configuration wizard, select Cloud Migration for the scenario and select Alibaba Cloud RDS Instance for the source type. Then, click Next.
-
On the Configure Destination Instance page, click Next.
In the Source Instance Configuration step, select all completed prerequisite checks and click Next.
In the Start Feasibility Assessment step, configure the source database information.
Parameter
Description
Migration Task Name
The system automatically generates a name. You do not need to change it.
Source VPC IP/DNS
The endpoint of the MyBase for PostgreSQL instance. For more information about how to view the public and internal endpoints of an instance, see View or change the internal and public endpoints and ports.
Source Instance Port
The port number of the MyBase for PostgreSQL instance. For more information about how to view the port number of an instance, see View or change the internal and public endpoints and ports.
Username
The high-privilege account of the MyBase for PostgreSQL instance. For more information about how to view the instance account, see View a database account.
Password
The password for the high-privilege account.
Click Create Feasibility Assessment Task.
NoteDuring the feasibility assessment task, the instance status changes to Maintaining Instance.
After the feasibility assessment is complete, you can view the status of the assessment task in the Cloud Migration list on the Feasibility Assessment page.
You can proceed to Step 2: Cloud Migration only if the Status is Succeeded.
If the Status is Failed, click View Report in the Actions column and resolve the error as detailed in the report. For information about common errors, see Interpret the Feasibility Assessment report.
After you resolve the error, you can click Re-assess in the Actions column to run the assessment again.
Step 2: Cloud Migration
You can perform this step only after the feasibility evaluation is successful.
On the Cloud Migration tab, click Create Cloud Migration Task.
In the dialog box that appears, select the successful feasibility assessment task from Step 1: Feasibility assessment in the Associated Assessment Task drop-down list.
NoteAfter you select an Associated Assessment Task, the Migration Source Type, Source IP/ DNS, Port of Source Instance, and Username parameters are automatically populated.
Click Start Cloud Migration to start the migration task.
ImportantDuring the migration task, the instance status changes to Migrating Data. You can read from and write to the source MyBase for PostgreSQL database, but do not perform operations such as another migration, a restart, or specification changes.
Perform a cloud cutover.
In the migration task list, click the link in the Cloud Migration Phase column to view the progress of the current task.
When the cloud migration phase is incremental synchronization, you can click Cloud Switchover in the Actions column to make the ApsaraDB RDS for PostgreSQL instance the primary instance.
In the Switch to Cloud dialog box, follow the on-screen instructions to set the MyBase for PostgreSQL instance to read-only or stop application writes.
NoteTo set the MyBase for PostgreSQL instance to read-only:
Log on to the MyBase for PostgreSQL database and run the following command to check whether a superuser exists.
SELECT CASE WHEN(count(rolname)<= 3) THEN 'superuser check ok' ELSE 'exists superuser created by user' END AS result FROM pg_roles where rolsuper= 't' and rolname in ('aurora', 'replicator') or rolname like 'pg%' GROUP BY rolname limit 1;If a superuser exists, contact an Alibaba Cloud engineer to modify the settings.
If no superuser exists, perform the following steps to modify the settings:
Log on to the ApsaraDB for MyBase console.
Use the Parameter Settings feature to set the rds_force_trans_ro_non_sup parameter to on. In the navigation pane on the left, click Parameter Settings. On the Modifiable Parameters tab, find the
rds_force_trans_ro_non_supparameter, change its running value toon, and then click Submit Parameters.After the modification is complete, log on to the MyBase for PostgreSQL database and run the following command to terminate all active 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 checkboxes and click Switch Now. Wait for the migration to complete.
Step 3: Connect to your application
Option 1: Swap endpoints (recommended)
Change the endpoint of the MyBase for PostgreSQL instance. Then, assign its original endpoint to the ApsaraDB RDS for PostgreSQL instance.
For example, assume that the endpoint of your MyBase for PostgreSQL instance is pgm-aaa.pg.rds.aliyuncs.com and the endpoint of your ApsaraDB RDS for PostgreSQL instance is pgm-bbb.pg.rds.aliyuncs.com. You can change the endpoint of the MyBase for PostgreSQL instance to pgm-ccc.pg.rds.aliyuncs.com and then change the endpoint of the ApsaraDB RDS for PostgreSQL instance to pgm-aaa.pg.rds.aliyuncs.com.
Option 2: Update the application endpoint
Obtain the endpoint of the ApsaraDB RDS for PostgreSQL instance, and then update it in your application's configuration.