User Guide · PostgreSQL · Failover protection

WAL-lag failover protection

A Patroni replica that is far behind the leader is a poor failover target: promoting it loses every transaction it has not replayed. Jarwis protects against this in two places — Patroni's own automatic failover, and manual switchovers started from the console.

/clusters/2?tab=overview
Patroni Switchover dialog with failover lag threshold of 1 MB, per-replica replay and receive lag, Behind by and Eligible status, target replica set to Auto
The Patroni Switchover dialog, opened from the cluster Overview tab: the failover lag threshold (1 MB, with a Change link), a per-replica table of Replay lag, Receive lag, Behind by and Status (Eligible), and the target replica set to Auto — best eligible replica.

The lag limit

Each PostgreSQL Patroni cluster has a maximum failover lag (default 1 MiB, allowed range 64 KiB–1 TiB). Change it from the Switchover dialog (cluster Overview tab, ?tab=overview) or the cluster settings API (pg_max_failover_lag_bytes); Jarwis writes it live to Patroni's maximum_lag_on_failover. A replica whose lag exceeds the limit is not allowed to become leader during automatic failover.

Choosing a value A small limit favours data safety; a large one favours availability. Replicate synchronously (or keep the limit small) if you cannot tolerate losing recent writes.

Candidate report

The Switchover dialog lists every member with its replay lag in bytes and a verdict: eligible or the reason it is not — lag exceeds threshold, lag unknown, not running, unreachable or nofailover tag. The report is read live from each member's Patroni.

Switchover guard

  • No candidate chosen: Jarwis picks the eligible replica with the least replay lag. If none is eligible it refuses and shows the report.
  • A candidate that lags too much is refused before anything starts, with the lag and the limit in the message.
  • A stopped, unreachable or nofailover candidate is also refused.

Forced promote

When the leader is gone and only lagging replicas remain, an administrator can force a promotion of a named replica. It requires an explicit candidate and an explicit acknowledgement that data will be lost. Jarwis then:

  • writes the estimated data loss (WAL position difference in bytes and the time gap) to the task log;
  • raises a critical forced promote alert that stays open until you resolve it;
  • records the action in the audit log.
Last resort Forced promote can only override a refusal caused by lag. Use it only after you have tried to recover the old leader, and reconcile the missing transactions afterwards.