Site icon Information2 | Data Management & Recovery Pioneer

Configure Azure Database for PostgreSQL High Availability

What Is High Availability in Azure Database for PostgreSQL?

High availability (HA) in Azure Database for PostgreSQL refers to the ability of the database service to remain operational with minimal downtime during system failure or outage. It’s very important for organizations to ensure business continuity, data security, and SLAs.

Unlike traditional PostgreSQL deployments that require complex clustering tools and manual failover configurations, Azure provides a fully managed HA solution. Failover is automatically triggered when the system detects an issue, and the service endpoint remains unchanged, allowing applications to reconnect without additional configuration.

Architecture Overview:

It works by deploying a primary server along with a standby replica. And Azure will monitor the health of the two servers and trigger a failover after a failure.

Deployment Model: Zone-Redundant vs Zonal HA

Azure Database for PostgreSQL offers two high availability deployment models: zone-redundant and zonal. Choosing the right model depends on your requirements for resilience, latency, and cost.

Zone-Redundant High Availability

In a zone-redundant setup:

Advantages:

Considerations:

This model is ideal for applications where uptime is critical and downtime is not acceptable.

Zonal High Availability

In a zonal setup:

Advantages:

Considerations:

This model is often used when cost and latency are higher priorities than maximum resilience.

The table below summarizes the key differences between the two Azure database for PostgreSQL High Availability

Feature

Zone-Redundant HA

Zonal HA

Deployment

Across availability zones

Within a single zone

Resilience

High (zone-level protection)

Moderate

Latency

Slightly higher

Lower

SLA

Up to ~99.99%

Typically lower

Cost

Higher

Lower

In practice, zone-redundant HA is recommended for production and mission-critical systems, while zonal HA is suitable for less critical workloads or environments where cost optimization is a priority.

How to Enable Azure Database for PostgreSQL High Availability

You can configure HA either during initial deployment or enable it on an existing server, depending on your workload requirements.

Prerequisite:✎…
Choose General Purpose and Memory optimized tiers, which provide the necessary performance, scalability, and resource stability to support synchronous streaming replication. 
If you choose zone-redundant HA, check if your region supports it. Go to your PostgreSQL Flexible Serverinstance > Under settings, choose High Availability. If it is greyed out, it doesn’t support. 
The application should implement connection retry logic. 
Ensure your application does not cache the primary server’s IP address, as the DNS record will update to point to the standby server after a failover.

Method 1. Enable HA During Server Creation

Step 1. Navigate to the Azure Portal (portal.azure.com) and sign in with your Azure account.

Step 2. Search for “Azure Database for PostgreSQL Flexible Server” and select the service from the results.

Step 3. Click “Create” to start provisioning a new server. Fill in the basic details (Subscription, Resource Group, Server name, Region, PostgreSQL version, and Admin credentials) as required.

Step 4. Under the “Compute + storage” tab, select either the General Purpose or Memory Optimized tier, then configure the SKU size, storage size, and backup retention period.

Step 5. Navigate to the “High Availability” tab (critical step for enabling HA). Here, you will configure Zonal Resiliency, which controls whether your server is protected across availability zones.

Step 6. Choose your preferred zone(s) for HA. Select “Enabled”.

Step 7. Enable the “Allow same zone” fallback option. This ensures that if there is insufficient capacity for your selected zone configuration, Azure will deploy both servers in the same zone to avoid deployment failures.

Step 8. Review all configurations, then click “Create” to provision the server with HA enabled.

The deployment process typically takes 5-10 minutes, as Azure deploys both the primary and standby servers simultaneously.

If you prefer Azure CLI Commands:

Below are example scripts for both Zone-Redundant and Same-Zone HA configurations during server creation.

►Example CLI Script for Zone-Redundant HA:

# Create a PostgreSQL Flexible Server with Zone-Redundant High Availability
az postgres flexible-server create \
  --resource-group myResourceGroup \  # Replace with your resource group name
  --name my-pg-ha-server \            # Replace with your unique server name
  --location eastus \                 # Replace with your preferred Azure region (multi-zone recommended)
  --admin-user pgadmin \              # Replace with your admin username
  --admin-password 'StrongPassword123!'  # Replace with a secure password
  --sku-name Standard_D4ds_v4 \       # General Purpose tier SKU (adjust based on your workload)
  --tier GeneralPurpose \             # Must be General Purpose or Memory Optimized
  --version 16 \                      # PostgreSQL version (14+ recommended for HA)
  --storage-size 128 \                # Storage size in GB (minimum 32 GB)
  --zonal-resiliency Enabled \        # Enables HA (replaces deprecated --high-availability)
  --zone 1 \                          # Primary availability zone
  --standby-zone 3 \                  # Standby availability zone (different from primary for zone-redundant)
  --allow-same-zone true              # Fallback to same zone if cross-zone capacity is unavailable

►Example CLI Script for Same-Zone HA:

# Create a PostgreSQL Flexible Server with Same-Zone High Availability
az postgres flexible-server create \
  --resource-group myResourceGroup \
  --name my-pg-samezone-ha-server \
  --location eastus \
  --admin-user pgadmin \
  --admin-password 'StrongPassword123!' \
  --sku-name Standard_D2ds_v4 \
  --tier GeneralPurpose \
  --version 16 \
  --storage-size 64 \
  --zonal-resiliency Enabled \
  --zone 2 \                          # Primary and standby share the same zone
  --standby-zone 2 \

Method 2. Enable HA on Existing Azure PostgreSQL Server

If you already have a PostgreSQL Flexible Server without HA enabled, you can easily add Azure Database for PostgreSQL High Availability through the Azure Portal or CLI.

This operation requires a brief connection interruption (typically 30-60 seconds) as Azure provisions the standby server and configures synchronous replication, so plan this during a maintenance window.

Azure Portal Steps:

Step 1. In the Azure Portal, navigate to your existing PostgreSQL Flexible Server instance.

Step 2. On the left-hand menu, under the “Settings” section, select “High Availability”.

Step 3. Under Zonal Resiliency, select “Enabled” to enable HA. This will display options to configure the HA mode (Zone-Redundant or Same-Zone).

Step 4. Check the “Allow same zone” box to handle capacity fallback. This ensures HA is enabled even if cross-zone capacity is temporarily unavailable.

Step 5. Click “Save” to apply the changes. A dialog will confirm that a standby server will be provisioned, and you will see a cost increase. Click “Enable High Availability” to proceed.

Monitor the deployment progress via the Azure Portal notifications. The process takes 5-10 minutes, and you will receive a notification once HA is successfully enabled.

Azure CLI Commands for Enabling HA on Existing Servers:

Use the az postgres flexible-server update command with the –zonal-resiliency Enabled parameter to enable Azure Database for PostgreSQL High Availability on an existing server. Below are examples for both HA modes:

# Enable Zone-Redundant HA on an existing server

az postgres flexible-server update \
  --resource-group myResourceGroup \
  --name my-existing-pg-server \
  --zonal-resiliency Enabled \
  --zone 1 \
  --standby-zone 2 \
  --allow-same-zone true

 

# Enable Same-Zone HA on an existing server

az postgres flexible-server update \
  --resource-group myResourceGroup \
  --name my-existing-pg-server \
  --zonal-resiliency Enabled \
  --zone 3 \
  --standby-zone 3 \
  --allow-same-zone true

Note:

  1. Enabling HA on an existing server takes 5-10 minutes, depending on your server size and region.
  2. There will be a brief (30-60 second) connection drop when the standby server is provisioned and replication is configured. Plan this during low-traffic maintenance windows to minimize impact.
  3. If your region has insufficient capacity for your selected zone configuration, Azure will use the “Allow same zone” fallback to deploy both servers in the same zone. You will be notified when cross-zone capacity becomes available to switch to Zone-Redundant HA.

    Monitoring Azure Database for PostgreSQL High Availability Health

    To ensure your high availability is operating correctly, you will need to verify the HA status of your server.

    You can check the status via both the Azure Portal and Azure CLI.

    Azure Portal:

    Navigate to your PostgreSQL Flexible Server. > Under the “Overview” tab, look for the “High Availability” status card in the right sidebar. > This card displays:

    Azure CLI Commands:

    Use the following command to retrieve detailed HA status information for your server, including replication health and zone details:

    # Check Azure PostgreSQL High Availability status via CLI
    az postgres flexible-server show \
      --resource-group myResourceGroup \
      --name my-pg-ha-server \
      --query "{haMode: zonalResiliency, primaryZone: zone, standbyZone: standbyZone, replicationStatus: replicationState}"

    The output will return values like “haMode”: “Enabled”, “replicationStatus”: “Synchronized”, and the zones for primary/standby servers—providing a quick way to validate HA health programmatically.

    Easier Way to Create a High Availability for Databases

    While Azure database for PostgreSQL’s high availability is a robust solution, it has some limitations, such as its regional requirements. And it is not a complete disaster recovery solution, it does not solve region-wide outages, data corruption, accidental deletion, or ransomware attacks.

    Here we would like to introduce i2Availability, a comprehensive high availability solution. This solution continuously monitors and replicates data changes between the production and disaster recovery environments. It captures real-time file system write operations, filters non-essential data, and transmits critical changes in encrypted, compressed form.

    If you need a complete disaster recovery solution, Info2Soft also provides:

    FREE Trial for 60-Day
    Secure Download

    Conclusion 

    This is how to configure Azure database for PostgreSQL High Availability. In this article, we discuss how to configure it during database creation and on an existing database. Hope it helpful for you to set up a HA ability to ensure your business continity. In addition, if you want an easier way to have a solid HA solution or a complete disaster recovery solution, Info2Soft can help you. 

    Exit mobile version