cat _posts/2026-11-21-kiwifarmit-ol-sbx-pg-failover-drill-is-public-failover-drills-for-patroni-in-data-guard-terms-with-lost-writes-counted-rather-than-estimated.md
kiwifarmit/ol-sbx-pg-failover-drill is public: failover drills for Patroni in Data Guard terms, with lost writes counted rather than estimated
kiwifarmit/ol-sbx-pg-failover-drill is now public: a pgdrill CLI that runs repeatable failure drills against a disposable three-node Patroni, etcd and HAProxy lab on Podman and reports measured RTO, RPO, in-doubt commits and split-brain per failure type — in the terms a DBA migrating off Oracle already signs SLAs in. Seven scenarios — kill the primary, shut it down cleanly, patronictl switchover, a partition that cuts the primary off from etcd and its peers while clients still reach it, DCS loss, failover with lagging replicas, both replicas down — run against three replication modes: async, sync and strict, the last of which maps onto Maximum Protection only partly, since PostgreSQL blocks commits instead of shutting down.
The measurement is exact rather than statistical. N writer threads run inside the lab’s client network, each inserting (run_id, writer_id, seq) rows in autocommit and logging every acknowledged commit, every failed one and anything still blocked at the end; the CLI injects the fault, waits for one leader and two streaming replicas on the same timeline, then compares the ledger against the surviving primary. Lost acknowledged writes are the RPO, the longest stretch with no acknowledged write is the RTO the application sees, and an old primary still acknowledging after a new one started is split brain. A run fails outright on a lost acknowledged write in sync or strict, on split brain, on a cluster that does not heal, or on ledger rows no client wrote — separately from the --max-rto and --max-rpo thresholds — and the exit codes say which: 0 passed, 2 a check failed, 1 the run could not complete, 130 interrupted with the lab torn down.
Two design choices make the numbers mean something. The client and cluster networks are separate and internal, so a partition can isolate the primary without also cutting its clients off, which is the situation split-brain and lost writes actually happen in; and the writers’ libpq settings — tcp_user_timeout, one-second keepalives — are pinned in runner.py and recorded in every report, because stock libpq can sit on a dead or partitioned server for minutes and inflate every RTO. The full matrix of seven scenarios by three modes takes about 20 minutes on one host, unit tests cover verify and report as pure functions with one Podman integration test, and the README is candid about the limits: synthetic data, trust authentication inside the lab subnets, a single etcd node, and timings from containers on one machine (ee4cdcb).