Senior LevelPostgreSQL
How do Patroni and etcd manage automated PostgreSQL Leader Election and Failover?
❓ Interview Prompt: Explain Patroni HA framework, Distributed Consensus Stores (etcd/Consul), TTL leader keys, automatic failover, and fencing (STONITH).
Patroni is the industry-standard High Availability (HA) template for PostgreSQL, using a Distributed Consensus Store (etcd or Consul):
Failover Architecture:
1
Patroni leader node acquires a key lock in etcd renewed every X seconds.
2
If leader network drops and key expires, remaining Patroni nodes hold a DCS Leader Election via etcd.
3
Automatically promotes the standby node with most up-to-date WAL LSN position!
Code Implementation Example
yaml
# Patroni configuration snippet using etcd DCS
scope: postgres-cluster
namespace: /service
etcd3:
hosts: 10.0.0.1:2379,10.0.0.2:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10💡Patroni High Availability configuration snippet using etcd.
🎯 Interview Key Takeaway
Deploy Patroni with etcd for automatic, split-brain-safe PostgreSQL leader election and failover.
#Patroni#etcd#High Availability#Failover#Senior
Back to all PostgreSQL Questions→