Create and manage read replicas in Azure Database for PostgreSQL - Single Server from the Azure portal

In this article, you learn how to create and manage read replicas in Azure Database for PostgreSQL from the Azure portal. To learn more about read replicas, see the overview.

Prerequisites

An Azure Database for PostgreSQL server to be the master server.

Prepare the master server

These steps must be used to prepare a master server in the General Purpose or Memory Optimized tiers. The master server is prepared for replication by setting the azure.replication_support parameter. When the replication parameter is changed, a server restart is required for the change to take effect. In the Azure portal, these two steps are encapsulated by a single button, Enable Replication Support.

  1. In the Azure portal, select the existing Azure Database for PostgreSQL server to use as a master.

  2. On the server sidebar, under SETTINGS, select Replication.

  3. Select Enable Replication Support.

    Enable replication support

  4. Confirm you want to enable replication support. This operation will restart the master server.

    Confirm enable replication support

  5. You will receive two Azure portal notifications once the operation is complete. There is one notification for updating the server parameter. There is another notification for the server restart that follows immediately.

    Success notifications - enable

  6. Refresh the Azure portal page to update the Replication toolbar. You can now create read replicas for this server.

    Updated toolbar

Enabling replication support is a one-time operation per master server. A Disable Replication Support button is provided for your convenience. We don't recommend disabling replication support, unless you are certain you will never create a replica on this master server. You cannot disable replication support while your master server has existing replicas.

Create a read replica

To create a read replica, follow these steps:

  1. Select the existing Azure Database for PostgreSQL server to use as the master server.

  2. On the server sidebar, under SETTINGS, select Replication.

  3. Select Add Replica.

    Add a replica

  4. Enter a name for the read replica.

    Name the replica

  5. Select a location for the replica. The default location is the same as the master server's.

    Select a location

    Note

    To learn more about which regions you can create a replica in, visit the read replica concepts article.

  6. Select OK to confirm the creation of the replica.

A replica is created by using the same compute and storage settings as the master. After a replica is created, several settings can be changed independently from the master server: compute generation, vCores, storage, and back-up retention period. The pricing tier can also be changed independently, except to or from the Basic tier.

Important

Before a master server setting is updated to a new value, update the replica setting to an equal or greater value. This action helps the replica keep up with any changes made to the master.

After the read replica is created, it can be viewed from the Replication window:

View the new replica in the Replication window

Stop replication

You can stop replication between a master server and a read replica.

Important

After you stop replication to a master server and a read replica, it can't be undone. The read replica becomes a standalone server that supports both reads and writes. The standalone server can't be made into a replica again.

To stop replication between a master server and a read replica from the Azure portal, follow these steps:

  1. In the Azure portal, select your master Azure Database for PostgreSQL server.

  2. On the server menu, under SETTINGS, select Replication.

  3. Select the replica server for which to stop replication.

    Select the replica

  4. Select Stop replication.

    Select stop replication

  5. Select OK to stop replication.

    Confirm to stop replication

Delete a master server

To delete a master server, you use the same steps as to delete a standalone Azure Database for PostgreSQL server.

Important

When you delete a master server, replication to all read replicas is stopped. The read replicas become standalone servers that now support both reads and writes.

To delete a server from the Azure portal, follow these steps:

  1. In the Azure portal, select your master Azure Database for PostgreSQL server.

  2. Open the Overview page for the server. Select Delete.

    On the server Overview page, select to delete the master server

  3. Enter the name of the master server to delete. Select Delete to confirm deletion of the master server.

    Confirm to delete the master server

Delete a replica

You can delete a read replica similar to how you delete a master server.

  • In the Azure portal, open the Overview page for the read replica. Select Delete.

    On the replica Overview page, select to delete the replica

You can also delete the read replica from the Replication window by following these steps:

  1. In the Azure portal, select your master Azure Database for PostgreSQL server.

  2. On the server menu, under SETTINGS, select Replication.

  3. Select the read replica to delete.

    Select the replica to delete

  4. Select Delete replica.

    Select delete replica

  5. Enter the name of the replica to delete. Select Delete to confirm deletion of the replica.

    Confirm to delete te replica

Monitor a replica

Two metrics are available to monitor read replicas.

Max Lag Across Replicas metric

The Max Lag Across Replicas metric shows the lag in bytes between the master server and the most-lagging replica.

  1. In the Azure portal, select the master Azure Database for PostgreSQL server.

  2. Select Metrics. In the Metrics window, select Max Lag Across Replicas.

    Monitor the max lag across replicas

  3. For your Aggregation, select Max.

Replica Lag metric

The Replica Lag metric shows the time since the last replayed transaction on a replica. If there are no transactions occurring on your master, the metric reflects this time lag.

  1. In the Azure portal, select the Azure Database for PostgreSQL read replica.

  2. Select Metrics. In the Metrics window, select Replica Lag.

    Monitor the replica lag

  3. For your Aggregation, select Max.

Next steps