PostgreSQL High Availability Overview

High availability in PostgreSQL is a topology problem, not a single feature toggle. Core PostgreSQL provides WAL generation, streaming replication, archive recovery, synchronous commit controls, and promotion. What it does not provide by itself is a one-command equivalent to SQL Server Availability Groups with built-in cluster orchestration. The operator has to choose a topology, define an RPO and RTO, decide whether failover is manual or automatic, and then add the surrounding coordination layer that makes promotion safe.

HA topology decision path

PostgreSQL HA design starts by deciding whether the requirement is zero data loss, manual failover, or geographic isolation. The database provides replication; the control plane decides who is allowed to become primary.


flowchart TD
  START["Need HA / DR"] --> LOSS{"Need zero<br/>committed data loss?"}
  LOSS -->|Yes| SYNC["Primary + synchronous standby<br/>plus fencing / failover manager"]
  LOSS -->|No| AUTO{"Need automatic<br/>failover?"}
  AUTO -->|Yes| ORCH["Asynchronous or mixed topology<br/>with external orchestrator"]
  AUTO -->|No| MANUAL["Manual promotion runbook"]
  SYNC --> SCALE{"Need read scale?"}
  SCALE -->|Yes| READ["Readable standbys<br/>with replay monitoring"]
  SCALE -->|No| SIMPLE["Primary + failover target"]
  ORCH --> GEO{"Need region-level<br/>survival?"}
  GEO -->|Yes| DR["Async standby or archive-based DR<br/>plus off-region backups"]
  GEO -->|No| LOCAL["Same-region async HA"]

Why High Availability

PostgreSQL | HA | key metrics and failure boundaries

Frame the topology around RTO, RPO, and write safety

MetricMeaningPostgreSQL impact
RTOMaximum acceptable downtime before service returnsDetermines whether manual promotion is acceptable or a failover manager is required
RPOMaximum acceptable data lossDetermines whether standbys must be synchronous or may lag asynchronously
Write-safety boundaryWhether two primaries must be prevented absolutelyDetermines whether fencing and leader coordination are mandatory

The core distinction is the same as in SQL Server:

NeedPostgreSQL interpretation
Local HASurvive one node or zone loss with rapid promotion of a standby
DRSurvive broader infrastructure loss, usually with async lag or archive replay
Read scaleOffload read-only queries to hot_standby replicas without confusing that with failover readiness

PostgreSQL | current cluster posture | what the lab can and cannot do today

Inspect whether the current cluster is actually HA-enabled

The current stoxx-postgres lab is replication-capable, but it is not highly available yet. These settings and views show the difference between “prepared for replication” and “protected by replication”.

SELECT name, setting, unit, source
FROM pg_settings
WHERE name IN (
  'hot_standby',
  'max_replication_slots',
  'max_wal_senders',
  'synchronous_commit',
  'synchronous_standby_names',
  'wal_level'
)
ORDER BY name;
namesettingunitsource
hot_standbyondefault
max_replication_slots10default
max_wal_senders10default
synchronous_commitondefault
synchronous_standby_namesdefault
wal_levelreplicadefault
SELECT pg_is_in_recovery() AS in_recovery,
       pg_current_wal_lsn() AS current_wal_lsn,
       pg_walfile_name(pg_current_wal_lsn()) AS current_wal_file;
in_recoverycurrent_wal_lsncurrent_wal_file
f0/B04202000000001000000000000000B
SELECT pid, application_name, client_addr, state, sync_state, sent_lsn, write_lsn, flush_lsn, replay_lsn
FROM pg_stat_replication
ORDER BY pid;
pidapplication_nameclient_addrstatesync_statesent_lsnwrite_lsnflush_lsnreplay_lsn
(0 rows)
SELECT slot_name, slot_type, active, restart_lsn, wal_status
FROM pg_replication_slots
ORDER BY slot_name;
slot_nameslot_typeactiverestart_lsnwal_status
(0 rows)
SELECT pid, status, receive_start_lsn, written_lsn, flushed_lsn, latest_end_lsn, latest_end_time, slot_name, sender_host, sender_port
FROM pg_stat_wal_receiver;
pidstatusreceive_start_lsnwritten_lsnflushed_lsnlatest_end_lsnlatest_end_timeslot_namesender_hostsender_port
(0 rows)

The lab is therefore in the “replication-ready single primary” state:

SurfaceCurrent meaning
wal_level = replicaphysical replication can be configured
max_wal_senders = 10there is sender capacity for standbys or tools like pg_receivewal
synchronous_standby_names emptyno standby is required for commits
pg_stat_replication emptyno active standbys exist
pg_replication_slots emptyno retained-WAL contract exists for a standby

HA Options for PostgreSQL 16

PostgreSQL | physical streaming replication | the default HA building block

Streaming replication is the core PostgreSQL HA pattern. A primary ships WAL to one or more standbys, which write and replay it continuously. This is the closest operational analogue to SQL Server AG log transport, but it is instance-scoped rather than “database-group” scoped: the standby is a physical copy of the cluster, not a subset of databases.

ModeHow it worksRPOTypical use
Asynchronous standbyprimary acknowledges commits without waiting for standby flush> 0low-latency local HA, cross-zone or cross-region DR
Synchronous standbyprimary waits for configured standby acknowledgment0 for acknowledged commitszero-data-loss HA when latency budget allows
Cascading standbystandby receives WAL from another standbyinherited from upstreamfan-out, WAN reduction, layered topologies

PostgreSQL | archive-based warm standby | simpler but slower failover path

An archive-based standby replays WAL from durable storage rather than from a live streaming connection. This is operationally closer to log shipping than to continuous streaming replication. It is useful for DR and recovery, but usually not the first choice for same-region low-RTO HA.

StrengthWeakness
simpler network boundary and durable off-cluster WAL historyhigher lag and slower failover than continuous streaming
pairs naturally with PITR toolingnot ideal for fast automatic failover

PostgreSQL | logical replication | not a physical HA substitute

Logical replication replicates tables and changes at the logical level. It is excellent for selective distribution, version upgrades, and data movement. It is not a full-cluster HA mechanism because it does not reproduce the cluster state the way a physical standby does.

Good fitNot a fit
selective table replicationwhole-cluster failover
blue/green migrationsexact crash-recovery equivalent of the primary
heterogenous subscriber patternspreserving every system relation and physical state

PostgreSQL | HA | decision matrix

RequirementSync standbyAsync standbyArchive-based standbyLogical replication
Zero committed-data lossYes, if the standby is part of synchronous_standby_namesNoNoNo
Fast same-region failoverYesUsuallyRarelyNo
Readable standbyYes (hot_standby)Yes (hot_standby)Sometimes after recovery state is reachedSubscriber is readable but not a physical standby
Whole-cluster replacementYesYesYesNo
Cheap DR copyExpensiveGoodGoodLimited
Cross-version migration helpPoorPoorPoorExcellent

Automatic Failover Boundaries

PostgreSQL | promotion and control planes | what core does and what orchestration adds

Separate database replication from cluster leadership

Core PostgreSQL is responsible for:

Core capabilityWhy it matters
WAL generation and shippingmoves committed changes to standbys
standby replay and read-only query supportkeeps a standby close enough to promote
synchronous commit semanticsdefines whether commit waits for a standby
promotionturns a standby into a writable primary

What PostgreSQL core does not decide alone:

External concernWhy it matters
which node is allowed to promoteprevents two primaries
whether the old primary is fenced offprevents split-brain
how applications find the new leaderroutes traffic correctly after failover
when automatic failover is safecombines replication lag, node health, and quorum

This is why PostgreSQL HA topologies typically include one of the following:

PatternTypical role
Patroni or Kubernetes operatorleader election, configuration, service endpoints
pg_auto_failovermonitoring and failover control plane
repmgrreplication management and promotion orchestration
Managed service control planeprovider-managed failover and routing

Replication without fencing is not HA

A standby that can be promoted is necessary but not sufficient. If the old primary can keep accepting writes after the new primary is promoted, the system is in split-brain. PostgreSQL HA design must include fencing or a control plane that can guarantee single-writer leadership.


Monitoring and Failover Readiness

PostgreSQL | replication views | the core HA health surface

Read the views that answer “can this standby take over?”

The baseline PostgreSQL HA monitoring set is:

View or functionPrimary question answered
pg_stat_replicationwhich standbys are connected and how far behind they are
pg_stat_wal_receiverwhether a standby is receiving WAL at all
pg_replication_slotswhether slots exist and whether they are pinning WAL
pg_is_in_recovery()whether a node is primary or standby
pg_last_wal_replay_lsn() / pg_last_xact_replay_timestamp()how far a standby has replayed

The current lab shows the most important failure mode of all: there is no standby to fail over to. pg_stat_replication, pg_replication_slots, and pg_stat_wal_receiver are all empty. That means the cluster is not degraded HA. It is non-HA.

PostgreSQL | failover criteria | define promotability explicitly

Know what a failover manager should check before promotion

At minimum, a promotable standby should satisfy:

CriterionWhy it matters
connected WAL stream or recent archive catch-upproves the standby is not stale
acceptable replay lag for the workload RPOensures promotion meets the data-loss target
known synchronous status if RPO = 0 is requiredproves commits were durably acknowledged
fencing path for the old primaryprevents split-brain
routable application endpoint after promotionprevents “failover succeeded but clients still hit the dead node”

Read Scale and Performance

PostgreSQL | hot_standby and synchronous commit | read scale versus write latency

Balance commit safety against throughput and query offload

The live settings surface already shows the main tuning levers:

SettingCurrent valueHA meaning
hot_standbyonstandbys are allowed to accept read-only queries
synchronous_commitoncommits use normal durability semantics; sync topology can require standby acknowledgment
synchronous_standby_namesemptyno standby is currently required for commit

Operational tradeoffs:

ChoiceBenefitCost
Synchronous standbyzero-data-loss failover for acknowledged commitsadded commit latency and possible write stalls if sync standby is unavailable
Asynchronous standbylower write latencypossible data loss on failover
Read-heavy standbyoffloads reporting trafficreplay can lag or cancel conflicting queries

Backup Strategy on Standbys

PostgreSQL | backup from replicas | use standbys deliberately, not automatically

Know which backup operations fit a standby

OperationStandby fitNotes
pg_basebackup from a standbyGoodcommon way to offload physical backup reads
pg_dump against a hot standbyGood with caveatsexport is read-only and may reflect replay lag
WAL archiving responsibilityUsually still primary-side or shared backup systemdo not assume standby backups remove the need for WAL retention discipline

A standby used for backups is still part of the HA design. If backup I/O slows replay badly, the standby may stop being a good failover target even while backups continue to “succeed”.


GCP and Infrastructure Considerations

PostgreSQL | GCP deployment shape | leader routing, zones, and fencing

Design the non-database pieces explicitly

ConcernPostgreSQL implication
Zone placementspread primary and standbys across zones to reduce shared failure domains
Traffic routinguse a load balancer, proxy, DNS, or service registry that can follow leader changes
Fencingensure failed primaries cannot keep serving writes after a standby is promoted
Durable off-cluster WAL retentionkeep PITR and DR independent of the live replica set

The PostgreSQL lesson is the same one the SQL Server AG note reaches through different tooling: replication is only half the architecture. The other half is making sure clients always reach the one true primary and never two primaries.


Maintenance Checklist

PostgreSQL | HA | daily, weekly, and monthly checks

Review the HA posture on a schedule

CadenceCheck
Dailyconfirm replica connectivity, replay lag, slot health, and archive health
Weeklyverify failover candidate ordering, routing targets, and backup-from-standby behavior
Monthlyrun a promotion or restore drill and confirm application reconnection path
Quarterlyreview RTO / RPO assumptions against observed latency and infrastructure changes

PostgreSQL High Availability Overview Recommendations

For most PostgreSQL production systems, the practical baseline is a physical primary plus at least one standby, with the choice between synchronous and asynchronous replication driven by whether RPO = 0 is actually required. Automatic failover should be introduced only with a control plane that can fence the old primary and reroute traffic safely. Logical replication remains valuable, but as a distribution and migration tool, not as the first answer to HA.

The current stoxx-postgres lab is prepared for replication but not yet protected by it. Next: 10-postgresql-streaming-replication-and-failover turns that architecture into a concrete PostgreSQL replica build, monitoring surface, and promotion workflow.