Edit

Share via


Migrate online, from an Amazon Aurora PostgreSQL server to Azure Database for PostgreSQL, with the migration service

APPLIES TO: Azure Database for PostgreSQL - Flexible Server

This article guides you in migrating a PostgreSQL instance from your on-premises or Azure virtual machines (VMs) to Azure Database for PostgreSQL flexible server in online mode.

The migration service in Azure Database for PostgreSQL is a fully managed service integrated into the Azure portal and Azure CLI. It's designed to simplify your migration journey to the Azure Database for PostgreSQL flexible server.

  • Prerequisites
  • Perform the migration
  • Monitor the migration
  • Initiate the cutover
  • Check the migration when completed

Prerequisites

To begin the migration, you need the following prerequisites:

Before you start a migration by using the migration service in Azure Database for PostgreSQL, it's important to complete the following prerequisites. These prerequisites are specifically designed for online migration scenarios.

Verify the source version

The source PostgreSQL server version must be 9.5 or later. If the source PostgreSQL version is earlier than 9.5, upgrade the version to 9.5 or later before you start the migration.

Install test_decoding for source setup

  • The test_decoding plugin receives Write-Ahead Logging (WAL) through the logical decoding mechanism. The plugin decodes WAL into text representations of the operations that are performed.
  • In Amazon RDS for PostgreSQL, the test_decoding plugin is preinstalled and ready for logical replication. You can easily set up logical replication slots and stream WAL changes, for example, for change data capture (CDC) or for replication to external systems.

For more information about the test_decoding plugin, see the PostgreSQL documentation.

Configure the target setup

Before you begin the migration, you must create an instance of Azure Database for PostgreSQL in Azure. The SKU that's provisioned for Azure Database for PostgreSQL flexible server should match the source.

For more information, see Create an Azure Database for PostgreSQL flexible server.

Enable CDC as a source

  • The test_decoding logical decoding plugin captures the changed records from the source.

  • To allow the migration user to access replication permissions, execute the following command:

    GRANT rds_replication TO <username>;
    
  • In the source PostgreSQL instance, modify the following parameters in the database clusters parameter group by creating a new parameter group:

    • Set rds.logical_replication to 1.
    • Set max_replication_slots to a value greater than 1. The value should be greater than the number of databases you select for migration.
    • Set max_wal_senders to a value greater than 1. It should be at least the same value as the value for max_replication_slots, plus the number of senders already used in your instance.
    • The wal_sender_timeout parameter ends inactive replication connections that are longer than the specified number of milliseconds. The default value for an Amazon Aurora PostgreSQL instance is 30000 milliseconds (30 seconds). Setting the value to 0 (zero) disables the timeout mechanism and is a valid setting for migration.
  • In the target flexible server, to prevent the online migration from running out of storage to store the logs, ensure that you have sufficient storage in your tablespace by using a provisioned managed disk. Disable the server parameter azure.enable_temp_tablespaces_on_local_ssd for the duration of the migration. Restore the parameter to the original state after the migration.

Configure the network setup

Network setup is crucial for the migration service to function correctly. Ensure that the source PostgreSQL server can communicate with the target server in Azure Database for PostgreSQL.

For information about network setup, see Network scenarios for the migration service.

Enable extensions

To ensure a successful migration by using the migration service in Azure Database for PostgreSQL, you might need to verify extensions to your source PostgreSQL instance. Extensions provide functionality and features that might be required for your application. Make sure that you verify the extensions on the source PostgreSQL instance before you initiate the migration process.

In the target instance of Azure Database for PostgreSQL flexible server, enable supported extensions that are identified in the source PostgreSQL instance.

For more information, see Extensions and modules.

Check server parameters

Server parameters aren't automatically migrated to the target environment and must be manually configured.

  • Match server parameter values from the source PostgreSQL database to the instance of Azure Database for PostgreSQL. In the Azure portal, go to Server parameters and manually update the values.

  • Save the parameter changes and restart the instance of Azure Database for PostgreSQL to apply the new configuration if necessary.

Check users and roles

When you migrate to Azure Database for PostgreSQL, it's essential to address the migration of users and roles separately because they require manual intervention.

  • Manual migration of users and roles: Users and their associated roles must be manually migrated to the instance of Azure Database for PostgreSQL. To facilitate this process, you can use the pg_dumpall utility with the --globals-only flag to export global objects such as roles and user accounts.

    Execute the following command. Replace <username> with the actual username, and replace <filename> with the name you want to use for the output file.

    pg_dumpall --globals-only -U <username> -f <filename>.sql
    
  • Restriction on superuser roles: Azure Database for PostgreSQL doesn't support superuser roles. Superuser permissions must be removed before migration. Ensure that you adjust the permissions and roles accordingly.

By completing these steps, you can ensure that user accounts and roles are correctly migrated to Azure Database for PostgreSQL without issues related to superuser restrictions.

Disable high availability (reliability) and read replicas in the target

It's critical that you disable high availability (reliability) and read replicas in the target environment before you initiate migration. These features should be enabled only after the migration is completed.

Perform the migration

You can migrate by using Azure portal or Azure CLI.

This article guides you using the Azure portal to migrate your PostgreSQL database from an Amazon Aurora PostgreSQL server to an Azure Database for PostgreSQL. The Azure portal allows you to perform various tasks, including database migration. Following the steps outlined in this tutorial, you can seamlessly transfer your database to Azure and take advantage of its powerful features and scalability.

Configure the migration task

The migration service comes with a simple, wizard-based experience on the Azure portal.

Using the Azure portal:

  1. Select your Azure Database for PostgreSQL flexible server.

  2. In the resource menu, select Migration.

    Screenshot of the Migration page.

  3. Select Create to go through a wizard-based series of tabs to perform a migration to a flexible server from on-premises or Azure VM.

    Note

    The first time you use the migration service, an empty grid appears with a prompt to begin your first migration.

    If migrations to your flexible server target have already been created, the grid now contains information about attempted migrations.

    Screenshot of the Setup tab which appears after selecting Create in the Migration page.

Setup

You need to provide multiple details related to the migration, like the migration name, source server type, option, and mode.

  • Migration name is the unique identifier for each migration to this flexible server target. This field accepts only alphanumeric characters and doesn't accept any special characters except a hyphen (-). The name can't start with a hyphen and should be unique for a target server. No two migrations to the same flexible server target can have the same name.

  • Source server type - Depending on your PostgreSQL source, you can select Azure Virtual Machine or On-premise server.

  • Migration option - Allows you to perform validations before triggering a migration. You can pick any of the following options:

    • Validate - Checks your server and database readiness for migration to the target.
    • Validate and migrate — Performs validation before triggering a migration. If there are no validation failures, the migration is initiated.

Choosing the Validate or Validate and migrate option is always a good practice for performing premigration validations before running the migration.

To learn more about the premigration validation, visit premigration.

  • Migration mode allows you to pick the mode for the migration. Offline is the default option. In this case, we'll change it to Online.

Select Next: Runtime server.

Screenshot of the Setup tab after providing necessary details.

Runtime server

The migration runtime server is a specialized feature within the migration service in Azure Database for PostgreSQL, designed to act as an intermediary server during migration. It's a separate Azure Database for PostgreSQL flexible server instance that isn't the target server, but is used to facilitate the migration of databases from a source environment that is only accessible via a private network.

Screenshot of the Runtime server tab.

For more information about the runtime server, visit Migration runtime server.

Source server

The Source server tab prompts you to give details related to the source selected in the Setup tab, which is the source of the databases.

  • Server name - Provide the name of the host or the IP address of the source PostgreSQL server.
  • Port - Port number of the source server.
  • Administrator login - Name of the administrator user of the source PostgreSQL server.
  • Password - Password of the administrator login provided to connect to source PostgreSQL server.
  • SSL mode - Supported values are preferred and required. When the SSL at the source PostgreSQL server is OFF, use prefer. If the SSL at the source server is ON, use the require. SSL values can be determined in postgresql.conf file of the source server.
  • Test connection — Performs the connectivity test between the target and source. Once the connection is successful, you can proceed to the next tab. These test aims to identify any connectivity issues that might exist between the target and source servers, including verification of authentication using the credentials supplied. Establishing a test connection takes a few seconds.

After the successful test connection, select Next: Target server.

Screenshot of Source server migration tab.

Target server

The Target server tab displays metadata for the flexible server target, such as the subscription name, resource group, server name, location, and PostgreSQL version.

  • Administrator login - Name of the administrator user of the target PostgreSQL server.
  • Password - Password of the administrator login provided to connect to target PostgreSQL server.
  • Custom FQDN or IP address: The custom FQDN or IP address field is optional, and can be used when the target is behind a custom DNS server or has custom DNS namespaces, making it accessible only via specific FQDNs or IP addresses. For example, this could include entries like production-flexible-server.example.com, 198.1.0.2, or a PostgreSQL FQDN such as production-flexible-server.postgres.database.azure.com, if the custom DNS server contains the DNS zone postgres.database.azure.com or forward queries for this zone to 168.63.129.16, where the FQDN is resolved in the Azure public or private DNS zone.
  • Test connection — Performs the connectivity test between the source and target. Once the connection is successful, you can proceed to the next tab. These test aims to identify any connectivity issues that might exist between the source and target servers, including verification of authentication using the credentials supplied. Establishing a test connection takes a few seconds.

After the successful test connection, select the Next: Databases to validate or migrate

Screenshot of the Target server migration tab.

Databases to validate or migrate

Under the Databases to validate or migrate tab, you can choose a list of user databases to migrate from your source PostgreSQL server.

After selecting the databases, select Next: Summary.

Screenshot of the Databases to validate or migrate  migration tab.

Summary

The Summary tab summarizes all the source and target details for creating the validation or migration. Review the details and select Start validation and migration.

Screenshot of the Summary migration tab.

Cancel the validation or migration

You can cancel any ongoing validations or migrations. The workflow must be in the In progress status to be canceled. You can't cancel a validation or migration in the Succeeded or Failed status.

Canceling a validation stops any further validation activity and the validation moves to a Canceled status.

Canceling a migration stops further migration activity on your target server and moves to a Canceled status. It doesn't drop or roll back any changes on your target server. Be sure to drop the databases on your target server that is involved in a canceled migration.

Monitor the migration

After you select the Start validation and migration button, a notification appears, in a few seconds, to say that the validation or migration creation is successful. You're automatically redirected to the flexible server's Migration page. The entry shows Status as In progress. The workflow takes 2 to 3 minutes to set up the migration infrastructure and check network connections.

Screenshot of the monitor migration page.

The grid that displays the migrations has the following columns: Name, Status, Migration mode, Migration type, Source server, Source server type, Databases, Duration, and Start time. The entries are displayed sorted by Start time in descending order, with the most recent entry on the top. You can use the Refresh button in the toolbar, to refresh the status of the validation or migration run.

Migration details

Select the migration name in the grid to see the associated details.

Remember that in the previous steps, when you created this migration, you configured the migration option as Validate and migrate. In this scenario, validations are performed first, before migration starts. After the Performing prerequisite steps substate is completed, the workflow moves into the substate of Validation in progress.

  • If validation has errors, the migration moves into a Failed state.

  • If validation is complete without error, the migration starts, and the workflow moves into the substate of Migrating Data.

Validation details are available at the instance and database level.

  • Validation details for instance
    • Contains validation related to the connectivity check, source version, that is, PostgreSQL version >= 9.5, and server parameter check, whether the extensions are enabled in the server parameters of the Azure Database for PostgreSQL flexible server.
  • Validation and migration details for databases
    • It contains validation of the individual databases related to extensions and collations support in Azure Database for PostgreSQL flexible server.

You can see the Validation status and Migration status under the migration details page.

Screenshot of the details showing validation and migration.

Some possible migration statuses:

Migration status

Status Description
In progress The migration infrastructure setup is underway, or the actual data migration is in progress.
Canceled The migration is canceled or deleted.
Failed The migration has failed.
Validation failed The validation has failed.
Succeeded The migration has succeeded and is complete.
Waiting for user action Waiting for user action to perform cutover.

Migration details

Substatus Description
Performing prerequisite steps Infrastructure setup is underway for data migration.
Validation in progress Validation is in progress.
Dropping database on target Dropping already existing database on target server.
Migrating data Data migration is in progress.
Completing migration Migration is in the final stages of completion.
Completed Migration has been completed.
Failed Migration has failed.

Validation substatuses

Substatus Description
Failed Validation has failed.
Succeeded Validation is successful.
Warning Validation is in warning.

Initiate the cutover

You can initiate the cutover using Azure portal or Azure CLI.

For Validate and migrate option, completing of the online migration requires the user to complete an additional step, which is to trigger the cutover action. After the copying or cloning of the base data is complete, the migration moves to the Waiting for user action status and the Waiting for cutover trigger substatus. In this status, the user can trigger the cutover from the portal by selecting the migration.

Before initiating cutover, it's important to ensure that:

  • Writes to the source are stopped - latency value is 0 or close to 0. The latency information can be obtained from the migration details screen as shown below:
  • latency value decreases to 0 or close to 0
  • The latency value indicates when the target last synced with the source. Writing to the source can be stopped at this point, and a cutover can be initiated. In case there's heavy traffic at the source, it's recommended to stop writes first so that latency can come close to 0, and then a cutover is initiated.

The cutover operation applies all pending changes from the source server to the target server, and completes the migration. If you trigger a cutover, even with nonzero latency, the replication stops until that point in time. All the data on the source until the cutover point is then applied to the target. If you experience a latency of 15 minutes at the cutover point, all the changes made to data in the last 15 minutes are applied to the target.

The time depends on the backlog of changes occurring in the last 15 minutes. Hence, it's recommended that the latency goes to zero or near zero before triggering the cutover.

  • The migration moves to the Succeeded status when the Migrating data substatus or the cutover (in online migration) finishes successfully. If there's a problem at the Migrating data substatus, the migration moves into a Failed status.

Check the migration when completed

After completing the databases, you need to manually validate the data between source and target and verify that all the objects in the target database are successfully created.

After migration, you can perform the following tasks:

  • Verify the data on your flexible server and ensure it's an exact copy of the source instance.

  • Post verification, enable the high availability option on your flexible server as needed.

  • Change the SKU of the flexible server to match the application needs. This change needs a database server restart.

  • If you change any server parameters from their default values in the source instance, copy those server parameter values in the flexible server.

  • Copy other server settings, such as tags, alerts, and firewall rules (if applicable), from the source instance to the flexible server.

  • Make changes to your application to point the connection strings to a flexible server.

  • Monitor the database performance closely to see if it requires performance tuning.