Skip to main content
RunBook Academy

PostgreSQLXV · High Availability, Failover and Disaster RecoveryHA

Replication is not high availability

Intermediate⏱ ~30 minpsql

What you'll learn

  • Separate what PostgreSQL provides from what an HA stack must supply
  • State the four decisions PostgreSQL will never make for you
  • Recognise the failure modes a manual failover has
  • Judge whether an HA stack is warranted at all

Prerequisites

Verified against PostgreSQL 18.x · PostgreSQL (comparison targets) 17.11, 16.15 · PostgreSQL (support calendar) 18, 17, 16, 15, 14 supported · pgBackRest 2.59.1 · PgBouncer 1.25.2 · Patroni 4.1.5 · Ubuntu (host baseline) 26.04 LTS · 2026-08-27

Not yet marked complete on this device.

Part XIV built a working replica. It is tempting to call that high availability. It is not, and the gap is larger than it looks.

What PostgreSQL gives you

Everything in this part was performed by hand on a live pair, and every step worked exactly as documented:

CapabilityMechanism
Ship changes to another hostStreaming replication
Make a standby writablepg_promote()
Keep divergent histories apartTimelines and .history files
Rejoin a diverged node cheaplypg_rewind

Those are genuinely good primitives. Promotion took under a second in the measurement in lesson XV-02, and pg_rewind rejoined a diverged node by copying 196 MB of a 376 MB cluster.

What it does not give you

Four decisions, and PostgreSQL will never make any of them:

1. Deciding the primary has failed. There is no health check, no quorum, no timeout after which anything happens. A primary that is unreachable to clients but reachable to the standby, or slow rather than dead, or has a full disk, looks identical to a healthy one from inside PostgreSQL.

2. Stopping the old primary from accepting writes. There is no mechanism. This is not a missing feature so much as a category error — a database cannot fence itself, because the situation where fencing is needed is exactly the one where it cannot be trusted to act.

3. Telling clients where the primary now is. A promoted standby does not announce itself. Every connection string still points at the old host.

4. Preventing two primaries. Nothing consults the old primary before a promotion, and nothing informs it afterwards.

The manual failover, honestly

Doing it by hand is legitimate for many systems. It is worth being clear about what it involves at three in the morning:

  1. Notice the primary is down — and be right about that.
  2. Confirm the standby is caught up, or accept the loss.
  3. Ensure the old primary cannot write. Power it off, revoke its storage, block it at the network. This is the step people skip.
  4. Promote.
  5. Repoint every client.
  6. Rebuild or pg_rewind the old primary.

Steps 1 and 3 are where the mistakes happen, and both involve judgement under pressure with incomplete information. Steps 4 to 6 are mechanical.

What availability actually depends on

A useful exercise: list what has to be true for the database to serve traffic, and notice how little of it is PostgreSQL.

  • The host is up.
  • Its storage is healthy and not full.
  • The network path from clients is intact.
  • DNS or the proxy points somewhere useful.
  • Connections are available (lesson IV-02).
  • No single query has taken a lock everything queues behind (Part IX).
  • pg_wal has not filled (lesson XII-03).
  • Someone would notice if any of this were false.

A second machine addresses the first two. Replication solves the narrowest of the failure modes that actually cause outages, and the observability in Part XVI addresses the last one, which is frequently the binding constraint.

What to take from this

  • PostgreSQL supplies replication, promotion, timelines and pg_rewind. Good primitives.
  • It supplies no failure detection, no fencing, no client routing, and nothing preventing two primaries.
  • Demonstrated: a promotion succeeded while the old primary kept accepting writes, with no error and no way to prevent it.
  • Manual failover is a legitimate choice. An untested automated stack is worse than a documented manual one.
  • A two-node HA cluster is not highly available; a majority cannot exist.
  • Most outages are not the failure mode replication addresses.

Cross-course references

  • Linux for Production Sysadmins — Part LII (High availability fundamentals) covers the same claim for services generally, and Part LV (Pacemaker and Corosync) covers what a real HA stack supplies beyond a copy of the data.
  • Proxmox — Part XII (High availability) covers the hypervisor’s own answer, which restarts a VM and knows nothing about the database inside it.

Quiz

Knowledge check · 6 questions

  1. Q1. A standby is promoted while the old primary is still running and reachable. What does PostgreSQL do about it?

  2. Q2. Why is a two-node automated HA cluster not actually highly available?

  3. Q3. From inside a standby, what distinguishes a crashed primary from an unreachable one?

  4. Q4. Which does PostgreSQL provide natively? Select all that apply.

  5. Q5. An automated HA stack that nobody tests or monitors is worse than a documented manual failover procedure.

  6. Q6. What must an HA stack supply that PostgreSQL does not, and why can PostgreSQL not supply it?

Passing score: 75%. Answers are checked in this browser.