Relocate Azure Database for PostgreSQL to another region
This article covers relocation guidance for Azure Database for PostgreSQL, Single Server, and Flexible Servers across geographies where region pairs aren't available for replication and geo-restore.
There are various reasons why you may want to move your existing Azure resources from one region to another. You may want to:
- Take advantage of a new Azure region.
- Deploy features or services available in specific regions only.
- Meet internal policy and governance requirements.
- Align with company mergers and acquisitions
- Meet capacity planning requirements.
To learn how to relocate Azure Cosmos DB for PostgreSQL (formerly called Azure Database for PostgreSQL - Hyperscale (Citus)), see Read replicas in Azure Cosmos DB for PostgreSQL.
For an overview of the region pairs supported by native replication, see cross-region replication.
Prerequisites
Prerequisites only apply to redeployment with data. To move your database without data, you can skip to Prepare.
- To relocate PostgreSQL with data from one region to another, you must have an additional compute resource to run the backup and restore tools. The examples in this guide use an Azure VM running Ubuntu 20.04 LTS. The compute resources must:
- Have network access to both the source and the target server, either on a private network or by inclusion in the firewall rules.
- Be located in either the source or target region.
- Use Accelerated Networking (if available).
- The database content isn't saved to any intermediate storage; the output of the logical backup tool is sent directly to the target server.
- Depending on your Azure Database for PostgreSQL instance design, the following dependent resources might need to be deployed and configured in the target region prior to relocation:
Downtime
To understand the possible downtimes involved, see Cloud Adoption Framework for Azure: Select a relocation method.
Prepare
To get started, export a Resource Manager template. This template contains settings that describe your Automation namespace.
Sign in to the Azure portal.
Select All resources and then select your Automation resource.
Select Export template.
Choose Download in the Export template page.
Locate the .zip file you downloaded from the portal and unzip that file to a folder of your choice.
This zip file contains the .json files that include the template and scripts to deploy the template.
Redeploy without data
- Adjust the exported template parameters to match the destination region.
Important
The target server must be different from the name of the source server. You must reconfigure clients to point to the new server.
- Redeploy the template to the new region. For an example of how to use an ARM template to create an Azure Database for PostgreSQL, see Quickstart: Use an ARM template to create an Azure Database for PostgreSQL - Flexible Server.
Redeploy with data
Redeployment with data migration for Azure Database for PostgreSQL is based on logical backup and restore and requires native tools. As a result, you can expect noticeable downtime during restoration.
Tip
You can use the Azure portal to relocate an Azure Database for PostgreSQL - Flexible Server. To learn how to perform replication for Single Server, see Move an Azure Database for PostgreSQL - Flexible Server to another region by using the Azure portal.
- Adjust the exported template parameters to match the destination region.
Important
The target server name must be different from the source server name. You must reconfigure clients to point to the new server.
Redeploy the template to the new region. For an example of how to use an ARM template to create an Azure Database for PostgreSQL, see Quickstart: Use an ARM template to create an Azure Database for PostgreSQL - Flexible Server.
On the compute resource provisioned for the migration, install the PostgreSQL client tools for the PostgreSQL version to be migrated. The following example uses PostgreSQL version 13 on an Azure VM that runs Ubuntu 20.04 LTS:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get install -y postgresql-client-13
For more information on the installation of PostgreSQL components in Ubuntu, refer to Linux downloads (Ubuntu).
For other platforms, go to PostgreSQL Downloads.
(Optional) If you created additional roles in the source server, create them in the target server. To get a list of existing roles, use the following query:
select * from pg_catalog.pg_roles where rolename not like 'pg_%' and rolename not in ('azuresu', 'azure_pg_admin', 'replication') order by rolename;
To migrate each database, do the following steps:
- Stop all database activity on the source server.
- Replace credentials information, source server, target server, and database name in the following script:
export USER=admin_username export PGPASSWORD=admin_password export SOURCE=pgsql-arpp-source.postgres.database.azure.com export TARGET=pgsql-arpp-target.postgres.database.azure.com export DATABASE=database_name pg_dump -h $SOURCE -U $USER --create --exclude-schema=pg_catalog $DATABASE | psql -h $TARGET -U $USER postgres
To migrate the database, run the script.
Configure the clients to point to the target server.
Perform functional tests on the applications.
- Ensure that the
ignoreMissingVnetServiceEndpoint
flag is set toFalse
, so the IaC fails to deploy the database when the service endpoint isn't configured in the target region.
- Ensure that the