Primary selection
HAProxy performs an HTTP check against port 8008 on every PostgreSQL member. The /primary endpoint returns 200 only on the current Patroni leader, so the TCP frontend on port 5000 has exactly one writable backend in the UP state.
3s
Patroni health-check interval
fall 3
Failed checks before marked down
rise 2
Healthy checks before restored
30m
Client and server TCP timeout
Component architecture
etcd stores the distributed leader state, Patroni manages PostgreSQL promotion and replication, HAProxy converts Patroni state into backend availability, and Swarm places each stateful service on the host containing its bind mounts.
HAProxy
TCP frontend with Patroni-aware backend selection.
·
TCP mode on :5000
·
HTTP health checks on :8008
·
Global Swarm service
Spilo + Patroni
PostgreSQL 17 managed by Patroni inside Spilo.
·
Leader election and promotion
·
Replication slots + pg_rewind
·
Asynchronous replication
etcd
Distributed configuration store used for leader election.
·
One member per declared node
·
Leader key and cluster state
·
Majority quorum required
Docker Swarm
Service placement and private overlay networking.
·
DNSRR service discovery
·
Host-pinned stateful members
·
Immutable Swarm configs
Configuration reference
These excerpts define the primary health check, backend transition thresholds, global service placement, Patroni failover parameters and checksum-versioned Swarm config.
Failure handling
Primary failure triggers Patroni promotion and HAProxy backend convergence. If etcd loses majority quorum, Patroni demotes the database to read-only rather than allowing multiple members to accept writes.
Network exposure
PostgreSQL, etcd, the SQL frontend and stats page publish no host ports. Applications join db-network and use haproxy:5000.
Primary-routed logical backups
A manager-only pg_dumpall runs through HAProxy, captures databases and roles, compresses the dump, and prunes local copies after seven days by default.
etcd member recovery
A lost etcd member cannot rejoin with initial state set to new. Remove it, add it back, then start only that member with state existing.
on-marked-down shutdown-sessions
drops sessions to the failed primary instead of letting them linger.
Deployment and inspection
Pre-deployment assertions reject missing or placeholder database credentials. After deployment, patronictl reports member roles and replication state, while the overlay-only HAProxy stats endpoint reports backend health.
Required deployment inputs
postgres_replica_members
Hostnames and per-member memory budgets.
postgres_password
Required superuser secret, supplied through Vault.
postgres_standby_password
Required replication secret in HA mode.
db-network
External overlay created before this role deploys.