Skip to main content
RunBook Academy

PostgreSQLXV · High Availability, Failover and Disaster RecoveryHA

What an HA stack must supply beyond PostgreSQL

Intermediate⏱ ~30 min

What you'll learn

  • Enumerate the responsibilities an HA stack takes on
  • Evaluate a tool against them rather than against its reputation
  • Recognise the failure modes the stack itself introduces
  • Decide whether the stack is worth its operational cost

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.

The previous three lessons established what is missing. This one turns that into a list you can evaluate a tool against.

The six responsibilities

1. Detect. Determine that the primary is unhealthy — and be right. Requires health checks that distinguish down from slow, from unreachable-from-here, from up but full disk.

2. Decide. Determine that a failover should happen. Distinct from detection: a single standby’s opinion is not sufficient evidence, which is where consensus and a majority come in.

3. Fence. Make certain the old primary cannot write, and verify it. Lesson XV-03.

4. Promote. The only one PostgreSQL supplies. pg_promote(), measured at 89 ms.

5. Reroute. Get clients to the new primary. Lesson XV-06.

6. Rejoin. Return the old primary to service as a standby. pg_rewind, lesson XV-07 — PostgreSQL supplies the tool but not the orchestration.

Evaluating a tool

Reputation is a poor guide. These questions are better, and each maps to a responsibility above.

How does it detect failure, and what does it do about ambiguity? Ask specifically what happens when a node is slow rather than dead. A tool that treats “no response in 10 seconds” as death will fail over during a long checkpoint.

How does it decide, and what is the quorum? If a single node can decide, it can decide wrongly during a partition. If a majority is required, count the nodes and confirm a majority can exist — a two-node cluster cannot form one.

How does it fence, and what happens when fencing fails? The important half is the second. A tool that promotes anyway when it cannot fence has traded a recoverable outage for an unrecoverable one. A tool that refuses to promote is behaving correctly and will be blamed for the outage.

How do clients find the new primary, and how fast? DNS TTL, VIP failover time, proxy reconfiguration. This is frequently the largest term in the real RTO and the least examined.

How does it rejoin, and does it require human intervention? A stack that fails over automatically and then needs a person to rebuild the old primary has automated the easy half.

What does it do when it is broken? The consensus store is unreachable; the agent has crashed; the agent is running but its view is stale. The right answer is that PostgreSQL keeps serving and the stack refuses to act. A stack that fails over because it cannot see clearly is worse than no stack.

Does the complexity earn its place?

Honest arithmetic beats instinct here.

Estimate your actual availability need. 99.9% is 8.8 hours of downtime a year; 99.99% is 53 minutes. Which one is written down anywhere, and what happens if you miss it?

Estimate manual failover time. Detection plus decision plus fencing plus promotion plus rerouting. Twenty to sixty minutes is typical with a practised team and a written runbook, and it is worse than people estimate because steps 1 to 3 involve judgement.

Count the primary failures you have actually had. Not incidents — primary host failures.

Estimate the cost of a spurious failover, and multiply by how often you think the stack will produce one.

For many systems the arithmetic favours a hot standby, good monitoring and a rehearsed manual procedure. For systems where minutes matter, or where there are enough clusters that per-cluster manual procedures do not scale, automation wins clearly. What almost never wins is automation installed because it seemed like best practice and then left unexercised.

What to take from this

  • Six responsibilities: detect, decide, fence, promote, reroute, rejoin. PostgreSQL supplies one.
  • Evaluate a tool by what it does with ambiguity and by what it does when it is itself broken.
  • The stack adds failure modes: spurious failover, flapping, promoting a stale standby, becoming the outage, configuration drift.
  • Do the arithmetic: availability target, manual failover time, actual failure rate, cost of a spurious failover.
  • Run the agent on the database host; run the consensus store elsewhere.
  • If an agent manages PostgreSQL, systemd must not.

Cross-course references

  • Linux for Production Sysadmins — Part LII (High availability fundamentals), Part LIV (Fencing and STONITH) and Part LVI (Keepalived and VRRP) cover failure detection, fencing and address failover as separate responsibilities, which is the decomposition this lesson uses.
  • Kubernetes for Production Sysadmins — Part LXVI (etcd) covers the consensus store an HA manager needs, and what it means when that store is the thing that fails.

Quiz

Knowledge check · 6 questions

  1. Q1. An HA stack cannot reach its consensus store. What is the correct behaviour?

  2. Q2. A node running an HA agent is deliberately demoted by that agent. systemd then restarts PostgreSQL. What is the result?

  3. Q3. Why should the HA agent run on the database host rather than on a separate monitoring machine?

  4. Q4. Which responsibilities must an HA stack supply because PostgreSQL does not? Select all that apply.

  5. Q5. An HA stack that cannot reach its consensus store should fail over to the standby, since an unreachable store indicates a wider failure.

  6. Q6. What arithmetic should decide whether an automated HA stack is worth its operational cost?

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