PostgreSQL + Patroni + etcd + HAProxy Enterprise HA
Distributed consensus-backed HA topology using etcd to eliminate split-brain hazards and guarantee sub-15s automatic failover.

📌 PostgreSQL + Patroni + etcd + HAProxy Enterprise HA Reference Architecture Diagram (Raft Quorum, DCS / Leader Lock, VIP)
Applications connect through Keepalived Virtual IP (VIP: 10.0.1.10) to HAProxy layer.
Port 5000 routes write traffic to the `/primary` node, while port 5001 load balances read traffic across healthy `/replica` nodes.
Primary verifies WAL delivery to at least one synchronous standby replica before acknowledging commit (RPO=0).
Primary fails to refresh its DCS lease key in etcd (lease TTL: 30s).
Patroni daemons elect the standby node with the highest WAL LSN as the new cluster leader.
HAProxy detects the change via port 8008 REST API and redirects write traffic within 2 seconds.
# patroni.yml snippet
scope: pg-cluster-prod
namespace: /service
name: pg-node-01
etcd3:
hosts: 10.0.1.11:2379,10.0.1.12:2379,10.0.1.13:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
parameters:
wal_level: replica
max_wal_senders: 10
wal_keep_size: 2048MB
postgresql:
listen: 0.0.0.0:5432
connect_address: 10.0.1.11:5432
data_dir: /var/lib/postgresql/17/main
pgpass: /var/lib/postgresql/.pgpass
authentication:
replication:
username: replicator
superuser:
username: postgrespatronictl -c /etc/patroni/patroni.yml topology
patronictl -c /etc/patroni/patroni.yml list
etcdctl --endpoints=10.0.1.11:2379,10.0.1.12:2379,10.0.1.13:2379 endpoint health- •Automated failover & split-brain immunity
- •Dynamic cluster configuration
- •Graceful zero-data-loss switchover for maintenance
- •Requires minimum 3-node quorum
- •Higher infrastructure and networking complexity
- etcd nodes must be distributed across at least 3 distinct physical/virtual fault domains.
- pg_rewind must be enabled and superuser credentials secured in DCS vault.
- HAProxy health check intervals configured to 2000ms with 5000ms connection timeout.
- pgBackRest must be integrated with immutable remote storage for disaster recovery.