Guide

PostgreSQL high availability: the complete guide (2026)

This guide covers what PostgreSQL replication does and does not guarantee, what each synchronous_commit level waits for, who detects a dead primary and promotes a standby, how WAL slots fill disks, how point-in-time recovery and pgBackRest fit in, and how RDS, Cloud SQL and Azure handle failover.

45 minutes with an engineer: we review your workload and sketch the design.

  • Docs read 19 Nov 2026
  • OSStend runs Patroni or CloudNativePG
Postgres point in time recovery and pgBackRest

PostgreSQL high availability means a primary with at least one standby, a tool that detects a dead primary and promotes a standby, and a decision on whether each commit must reach that standby first. PostgreSQL ships replication but no failure detection, and replication is asynchronous by default. Facts read from official documentation, 19 Nov 2026.

Customers

  • Microsoft logo
  • Henry Schein logo
  • Enbridge logo
  • Gojek logo

Partners

  • Broadcom logo
  • Redis logo
  • VMware Tanzu logo
  • OSSeva logo

What is PostgreSQL high availability?

PostgreSQL high availability is the set of parts that keep a database answering after its primary server fails: a standby that has the data, something that notices the failure and promotes the standby, and a way for applications to find the new primary. PostgreSQL provides the first part and leaves the other two to you or your provider.

Replication.
The primary streams its write-ahead log (WAL) to one or more standbys. It is asynchronous unless you configure otherwise, which is the first thing to know when someone says a cluster is highly available.
Failure detection and promotion.
The PostgreSQL manual says it does not provide the system software required to identify a failure on the primary and notify the standby (failover, checked 19 Nov 2026). A cluster manager such as Patroni, or a cloud provider's control plane, does this.
Client routing.
A DNS name, a virtual IP, a load balancer or a connection pooler that follows the leader. After a promotion, existing connections break and applications must reconnect.
Recovery from mistakes.
A standby copies a dropped table as faithfully as it copies an insert, so high availability does not replace backups. That is the job of WAL archiving and point-in-time recovery, covered below.

These are the choices a design for managed PostgreSQL writes down before anything is built. For choosing between CloudNativePG, Patroni and a cloud service, read CloudNativePG vs Patroni vs a managed service.

Which PostgreSQL HA setup survives what?

Each setup survives a different failure and loses a different amount of data. The deciding questions are whether a commit waits for the standby, and whether a person or software promotes it.

SetupWhat it survivesData loss on failoverWho promotes
One server, base backups and archived WALDisk or host loss, by restoring on new hardwareEverything after the last archived WAL segmentA person, by restoring
Primary plus asynchronous standbyLoss of the primary host or zoneWAL the standby had not yet received when the primary failedA person, with pg_ctl promote or pg_promote()
Primary plus asynchronous standby under PatroniLoss of the primary host or zone, without a pageThe same unreplicated WAL; Patroni's maximum_lag_on_failover limits how far behind a candidate may bePatroni, using a lock in its configuration store
Synchronous standby (synchronous_commit on, FIRST or ANY n)Loss of the primary, with each acknowledged commit already flushed on a standbyNone for commits acknowledged under on or remote_apply, while a synchronous standby is availableA person or a cluster manager
Amazon RDS Multi-AZ DB instanceLoss of the instance or its Availability ZoneSynchronous standby in another zone, so committed data is on both (RDS)AWS, with a DNS change
Amazon RDS Multi-AZ DB clusterLoss of the writer or its zone, three zones in allSemisynchronous: one reader must acknowledge a commit (RDS)AWS
Cloud SQL high availabilityLoss of the primary or its zoneWrites go to disks in both zones before commit (Cloud SQL)Google, after missed heartbeats
Azure flexible server, zone-redundantLoss of the primary or its zoneRPO of zero for zone failures, as Azure documents it (Azure)Azure, after failed health checks
Cross-region read replicaLoss of a whole regionReplication lag at the moment of the outage; Azure says it is typically at least several minutesA person; Azure does not promote replicas automatically

Rows are read from the PostgreSQL manual (failover, synchronous_commit) and the cloud documents linked in the cells, checked 19 Nov 2026. OSStend is not a row because its design is written per workload; the zones, the failover tool and the synchronous decision are fixed in the design review, and the response commitment is in the service levels.

45 minutes with an engineer: we review your workload and sketch the design, then price it.

How does PostgreSQL replication work, and what does synchronous_commit wait for?

PostgreSQL streaming replication sends WAL from the primary to standbys and is asynchronous by default, so the primary can acknowledge a commit before any standby has it. The synchronous_commit setting decides how long a commit waits, and synchronous_standby_names decides which standbys it waits for.

synchronous_commitA commit waits untilNote
offNothing. Success can be reported before WAL is flushed.A crash can lose a commit already reported; the manual puts the maximum delay at three times wal_writer_delay.
localThe local WAL flush to disk.No wait for any standby.
remote_writeA synchronous standby has received the commit record and written it to its file system.Not yet flushed on the standby.
on (default)A synchronous standby has received the commit record and flushed it to durable storage.With no synchronous standbys named, on is the same as a local flush.
remote_applyA synchronous standby has applied the commit record, so it is visible to queries there.The slowest and strongest level.

Source: the synchronous_commit entry of the PostgreSQL manual, checked 19 Nov 2026.

Naming the standbys.
synchronous_standby_names takes FIRST num_sync (priority order) or ANY num_sync (quorum): FIRST waits for num_sync standbys chosen by priority, ANY waits for at least num_sync of the listed standbys (replication settings, checked 19 Nov 2026).
The trade.
A synchronous standby adds its round trip to every commit, and if no named standby is reachable, writes stall. Quorum with ANY keeps writing when one of three standbys is down; a single named standby does not.
Capacity of the sender.
max_wal_senders defaults to 10 and 0 disables replication (replication settings, checked 19 Nov 2026).

Who promotes the standby: failover, fencing and pg_rewind

Something other than PostgreSQL must notice the dead primary, promote one standby and make sure the old primary cannot accept writes again. Without that fence, two servers believe they are primary and diverge, which the manual says leads to data loss.

  • Fencing. If the old primary restarts, the manual says you need a way to tell it that it is no longer primary, sometimes called STONITH, to avoid both systems thinking they are primary (failover, checked 19 Nov 2026). Patroni's last resort is a Linux watchdog that resets the host if Patroni cannot send a keepalive; it expires 5 seconds before the leader key's ttl by default and, in required mode, a node that cannot arm it will not become leader (Patroni watchdog, checked 19 Nov 2026).
  • Rejoining the old primary. pg_rewind makes the old primary's data directory follow the new primary by copying only changed blocks, which is faster than a fresh base backup on large clusters. It needs wal_log_hints or data checksums, full_page_writes on, a cleanly stopped target, and the WAL from the divergence point (pg_rewind, checked 19 Nov 2026).
  • Patroni's moving parts. Patroni keeps its leader lock in etcd, Consul, ZooKeeper or Kubernetes, and its timers default to ttl 30, loop_wait 10 and retry_timeout 10 seconds, with the rule that loop_wait + 2 x retry_timeout must not exceed ttl (dynamic configuration, checked 19 Nov 2026). synchronous_mode accepts off, on or quorum, with synchronous_node_count defaulting to 1. What those timers mean for how long a failover takes is worked through in CloudNativePG vs Patroni.
  • Logical slots. Logical replication slots have to be synchronized to a standby to survive a promotion, and the manual says to check that synchronized slots are ready before a planned switchover. The consequences for CDC pipelines are in the Postgres CDC guide.

On Kubernetes, CloudNativePG does the detection and promotion through the Kubernetes API instead of a separate configuration store. That comparison is a guide of its own, so this page leaves it there; managed CloudNativePG is the service that runs it.

Coming from Oracle? The Oracle RAC alternative guide sorts what RAC and Data Guard did into what this design replaces and what it does not.

Replication slots, wal_keep_size and hot_standby_feedback: what fills the disk

A replication slot makes the primary keep WAL until the standby has used it, which protects a lagging standby and can fill the primary's disk if the standby never returns. wal_keep_size is the blunter alternative, and hot_standby_feedback trades standby query cancellations for bloat on the primary.

Illustrative shape: real designs start from your metrics.
SettingDefaultWhat it does
wal_keep_size0Minimum size of past WAL kept for standbys. At zero, retention depends on the last checkpoint and WAL archiving.
max_slot_wal_keep_size-1Caps WAL held by slots. At -1 a slot may retain unlimited WAL; set a limit and a lagging standby may lose its slot and need a rebuild.
idle_replication_slot_timeout0 (off)Invalidates a slot inactive longer than the set time, checked at checkpoints.
hot_standby_feedbackoffStandby reports its oldest query to the primary. It can stop query cancellations caused by cleanup records, but can cause bloat on the primary.
primary_slot_namenoneNames the slot a standby uses to hold WAL upstream.

Source: the replication and WAL settings pages of the PostgreSQL manual, checked 19 Nov 2026.

The practical rule is to give every slot an owner and an alert on the WAL it holds. A dead standby with a slot and no cap is a standard way for a healthy primary to run out of disk.

Postgres point in time recovery and pgBackRest

Postgres point in time recovery restores a base backup and replays archived WAL up to a chosen time, named restore point or transaction ID. It needs WAL archiving turned on before the mistake happens, and pgBackRest is the tool most teams use to run the backups and restores.

  1. Archive WAL

    Set archive_mode to on, which needs a restart and a wal_level of replica or higher, and give archive_command or archive_library a command that returns zero only on success and refuses to overwrite an existing file (continuous archiving, checked 19 Nov 2026). archive_command is empty by default, so nothing is archived until you set it.

  2. Take base backups

    A base backup is the starting point for every restore. WAL older than the oldest base backup you keep is of no use.

  3. Restore to a moment

    Restore the base backup, set restore_command and a recovery target (time, named restore point or transaction ID), create an empty recovery.signal file and start the server (continuous archiving, checked 19 Nov 2026). recovery_target_timeline follows the latest timeline in the archive by default.

  4. Check the data, then open it up

    If the data is wrong, restore again with an earlier target. If it is right, restore pg_hba.conf and let users back in.

Backup types.
pgBackRest runs full, differential (--type=diff, against the last full) and incremental (--type=incr, against the prior chain) backups (user guide, checked 19 Nov 2026).
Parallelism.
process-max defaults to 1, and the guide says that is almost never the appropriate value.
Backing up from a standby.
The backup-standby option moves the backup load off the primary, and needs a standby host configured.
Encryption.
repo1-cipher-type=aes-256-cbc with a repo1-cipher-pass encrypts the repository on the client side; the guide says it cannot be changed once the stanza is created.
Repositories and restore.
Repositories can be a local path, object storage on Azure, S3 or GCS, or SFTP, and restore --type=time --target=... with --target-action=promote recovers to a time and opens the database.

How do RDS, Cloud SQL and Azure handle Postgres failover?

All three keep a standby in another zone and fail over for you, but they differ in how a commit reaches the standby, whether the standby serves reads and how long the documents say failover takes. The documented figures below are the providers' own words, not measurements.

ServiceHow commits reach the standbyDocumented failoverCatch
Amazon RDS Multi-AZ DB instanceSynchronous standby in another zone; the standby cannot serve reads.The page we read gives no time.Commit and write latency can be higher than Single-AZ because replication is synchronous.
Amazon RDS Multi-AZ DB clusterSemisynchronous to two readers in three zones; at least one must acknowledge.Typically under 35 seconds, and it depends on replica lag.For PostgreSQL the reader with the lowest lag must apply outstanding transactions first; limited instance classes, and not the same product as Aurora.
Cloud SQL high availabilityWrites are copied to disks in both zones before commit.About sixty seconds of unavailability; it can vary.A heartbeat runs every second and failover starts after several misses; it is blocked if the standby zone is unhealthy. An HA instance costs twice a standalone one.
Azure flexible server, zone-redundantPrimary confirms a commit after the standby durably stores the WAL, not after it applies it.Typically 60 to 120 seconds.The standby serves no client traffic. Same-zone HA does not protect against a zone outage, and gives no automatic failover for one.

Read from each provider's documentation, checked 19 Nov 2026. See also the RDS Multi-AZ overview. OSStend does not quote a failover time on this page because it depends on the design and sits in the service tier of the contract.

Two things catch teams after they pick a cloud service. Azure notes that a dropped table replicates to the standby like any other change, so recovery from user error needs a point-in-time restore. And on RDS the failover moves a DNS record, so a Java application with an unlimited DNS cache keeps talking to the dead address; AWS recommends a JVM TTL of 60 seconds or less. For price comparisons see managed PostgreSQL pricing compared, and for the limits of turnkey plans see Amazon RDS alternatives.

From our on-call engineers: checks before you trust a failover

These checks come from the PostgreSQL, Patroni and cloud documentation, read on 19 Nov 2026, turned into a runbook order. They are documentation restated, not a record of incidents, and we quote no customer figure.

  • Write down whether losing the last commits is acceptable, then set synchronous_commit and synchronous_standby_names to match, instead of finding out during an outage.
  • Confirm something fences the old primary, and that the pg_rewind prerequisites (wal_log_hints or checksums) were on before the failure, not after.
  • Alert on the WAL each slot retains, and decide whether max_slot_wal_keep_size is set, knowing the cap trades disk safety for a standby that must be rebuilt.
  • Restore a backup to a point in time on a spare server on a schedule, and time it. A backup nobody has restored is an assumption.
  • Test the client side: kill the primary in a rehearsal and measure how long applications take to reconnect, including DNS caching.
  • Keep max_connections on every standby at or above the primary's value, or queries are refused on the standby; the manual says so.

FAQ

What is PostgreSQL high availability?

A primary with at least one standby, a tool that detects a failed primary and promotes a standby, and client routing that follows the leader. PostgreSQL provides replication; the rest is a cluster manager or a cloud service.

Is PostgreSQL streaming replication synchronous?

No. It is asynchronous by default. Synchronous behaviour comes from synchronous_standby_names together with a synchronous_commit level of on, remote_write or remote_apply (manual, checked 19 Nov 2026).

Does Postgres fail over automatically?

Not by itself. The manual says PostgreSQL does not provide software to identify a primary failure (failover). Patroni, CloudNativePG and managed services supply it.

What is the difference between replication and backups?

Replication keeps a live copy and copies mistakes too. Backups plus archived WAL let you go back to a moment before the mistake. A production design needs both.

How does Postgres point in time recovery work?

Restore a base backup, then replay archived WAL up to a recovery target such as a time, using restore_command and a recovery.signal file. WAL archiving must have been on before the incident.

Should I use Patroni or CloudNativePG?

Patroni fits VMs and bare metal; CloudNativePG fits Kubernetes. The trade-offs are in CloudNativePG vs Patroni vs a managed service.

What does synchronous_commit remote_apply do?

It makes a commit wait until the synchronous standby has applied the change and it is visible to queries there, on top of being durable. It is the strongest and slowest level.

PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. Patroni, pgBackRest and CloudNativePG are the names of their projects. Amazon RDS and AWS are trademarks of Amazon, Google Cloud SQL of Google, and Azure of Microsoft. OSStend is not affiliated with or endorsed by these projects or companies, and the names are used only to say which software and services the guide describes.

Talk to an engineer

Talk to an engineer about your failover design

45 minutes: your replica layout, commit guarantees and restore tests are reviewed, and an engineer says what to change.

  • A design sketch for your workload, not a plan menu
  • A zero-downtime cutover path for what you run today
  • A price for that design, after the review
See pricing →

Your request goes to the OSStend team. No newsletter sign-up.

Get a quoteTalk to an engineer
2Engines Optional
3Where should it run?
4What do you need?

Your request goes to the OSStend team. No newsletter sign-up.