Patroni_ha
Chapter 43: High Availability with Patroni
Section titled “Chapter 43: High Availability with Patroni”Building Self-Healing PostgreSQL Clusters
Section titled “Building Self-Healing PostgreSQL Clusters”43.1 Understanding Patroni
Section titled “43.1 Understanding Patroni”Patroni is a template for building high availability solutions using PostgreSQL.
Patroni Architecture ========================================================================
┌─────────────────────────────────────────────────────────────────────┐ │ Patroni HA Solution │ │ │ │ Components: │ │ ─────────── │ │ • Patroni daemon - runs on each node │ │ • DCS (Distributed Configuration Store) │ │ - etcd, Consul, ZooKeeper, or Kubernetes │ │ • HAProxy - load balancer and connection router │ │ • PostgreSQL - the database │ │ │ │ Features: │ │ ───────── │ │ • Automatic failover │ │ • Manual switchover │ │ • Distributed consensus │ │ • Configuration management │ │ │ └─────────────────────────────────────────────────────────────────────┘43.2 Patroni Configuration
Section titled “43.2 Patroni Configuration”# patroni.yml on each nodescope: postgres-clustername: postgresql0
restapi: listen: 0.0.0.0:8008 connect_address: postgresql0:8008
etcd: host: etcd:2379
postgresql: data_dir: /data/postgresql bin_dir: /usr/lib/postgresql/15/bin parameters: wal_level: replica max_wal_senders: 10 max_replication_slots: 10 hot_standby: on
tags: nofailover: false noloadbalance: false clonefrom: false43.3 HAProxy Configuration
Section titled “43.3 HAProxy Configuration”# haproxy.cfglisten postgres bind *:5000 mode tcp option tcp-check balance roundrobin server postgresql0 postgresql0:5432 check inter 3s server postgresql1 postgresql1:5432 check inter 3s server postgresql2 postgresql2:5432 check inter 3sSummary
Section titled “Summary”| Component | Role |
|---|---|
| Patroni | HA orchestrator |
| etcd/Consul | Configuration store |
| HAProxy | Connection router |
| PostgreSQL | Database |