Patroni PostgreSQL HA
An open-source project that builds a highly available PostgreSQL cluster on Patroni, etcd, PgBouncer, and HAProxy with a single Ansible playbook run.
Key Strengths
Automatic failover
When the leader node fails, a standby is promoted automatically within seconds, minimizing service disruption.
Split-brain prevention
Leaders are elected through etcd quorum (majority) consensus, eliminating the possibility of two leaders running at once.
Fixed virtual IP (VIP)
Applications connect through a VIP managed by Keepalived, so no configuration change is needed even after a failover.
Zero-downtime configuration
PostgreSQL settings are applied at runtime through Patroni and rolled out consistently across the cluster.
Components
Proven, standard open-source building blocks with clearly separated responsibilities at each layer.
PostgreSQL
The database itself. Leader and standbys are built on streaming replication (supports 14–17, default 16).
Patroni
The cluster conductor. Automates leader election, replication setup, and failover.
etcd
The cluster state store. Keeps leader information safe through quorum consensus.
PgBouncer
A lightweight connection pooler that brokers high connection volumes and reduces database load.
HAProxy
The traffic guide. Detects the current leader and routes read/write traffic to the right node.
Keepalived
The VIP manager. Maintains a single fixed entry point even during failures.
Architecture
The connection path flows from applications through the VIP, HAProxy, and PgBouncer to PostgreSQL, backed by etcd consensus.
Deployment
The entire process is automated with Ansible playbooks, with two topologies to match your infrastructure.
Separated topology
Three dedicated etcd nodes plus two or more database nodes — suited to large, mission-critical environments.
Converged topology
All components co-located on three servers, delivering HA with minimal resources.
Ansible automation
Idempotent playbooks for Debian/Ubuntu and RHEL/Rocky that are safe to run repeatedly.
Get started on GitHub
The full playbooks and installation guide are open source and available in the repository.