Know your speaker
Dipendra Khadka
Senior System and Postgres Engineer, Dharma of Data
Professional Biography
Senior System and Postgres Engineer
Sessions
Pi-Cluster: Injecting Failures into PostgreSQL HA and Measuring What Actually Happens
Pi-Cluster is a laboratory for observing how PostgreSQL behaves under controlled faults, across properties that are often discussed as one: high availability (does a writable primary come back, and how fast?), durability (do acknowledged writes survive?), replication (how far do standbys fall behind, and do they catch up?), and distributed atomicity (does a transaction spanning two clusters commit everywhere or nowhere?). Each scenario runs PostgreSQL with pg_auto_failover on isolated nodes, applies a single fault at a chosen moment, and records what the system did. Pi-Cluster never performs recovery itself. Promotion, crash recovery, replica catch-up and resolution of in-doubt transactions are left entirely to the software under test.
Scenarios are written as code. A single scenario file declares the cluster topology, the client workload, which fault to inject, when to inject it, when to heal it, and which invariants to check. The same file runs unchanged on every execution, so a result can be reproduced, shared, and rerun after an upgrade or configuration change to see whether behaviour has shifted.
A run produces evidence, not an impression:
- HA: never two writable primaries; the surviving standby is promoted; the old primary rejoins as a standby.
- Durability: every acknowledged write survives, and data can be restored to a named point in time.
- Replication: standbys converge with the primary once the fault is removed.
- Two-phase commit: a distributed transaction is never committed on one cluster and aborted on the other; a prepared transaction survives failover; no in-doubt transaction is left behind.
Costs are measured separately, each over a defined time window: write unavailability, replica lag and staleness, recovery time, and for 2PC, how long transactions stay in doubt and how many writes their held locks block. On the laptop version, each node is a Linux network namespace and cgroup with its own address and disk. Every run is saved as a single self-contained record: the fault and its exact injection time, each node’s role changes, client write attempts and their outcomes, replication positions, and every invariant check. The record can be replayed on a timeline, so you can step through the seconds around a fault and see the order of events: when the primary stopped answering, when the monitor noticed, when promotion happened, when writes resumed, and when lagging standbys caught up. Two runs can be compared side by side, and a surprising result can be examined again without rerunning the experiment.
We contrast four faults that are commonly treated as the same thing:
- Node disappears (link down, then processes killed): pg_auto_failover promotes a standby. Writes were unavailable for 46.6–48.5 s in our recorded runs.
- Node restarts on the same disk: PostgreSQL performs crash recovery from WAL, and no acknowledged write is lost.
- Node frozen (cgroup freeze): the kernel still acknowledges packets, so clients get no error and simply wait. Nothing fails over.
- Replication link cut, both ends alive: the cut standby falls behind (26 s in our runs) and catches up after the heal, while the other standby stays current.
We then apply the same faults between the two phases of a commit spanning two HA clusters: a participant failing over after PREPARE, the coordinator dying with transactions in doubt, and a link cut during COMMIT PREPARED. These show whether prepared transactions survive promotion, and what orphaned prepared transactions cost in held locks and blocked writes until they are resolved.
We also show point-in-time recovery to a named restore point after the source node is gone, demonstrating durability beyond the life of any single node.
Attendees leave with a repeatable method for testing PostgreSQL failover, durability, replication and two-phase commit on a laptop, scenario files they can adapt to their own clusters, a way to replay and compare runs on a timeline, and a clear distinction between crash, freeze and partition. The target platform is a Raspberry Pi 5 cluster, which adds real power loss, storage behaviour and arm64. We’ll show it live if the hardware is ready.