Skip to content

Patroni_ha

Chapter 43: High Availability with Patroni

Section titled “Chapter 43: High Availability with 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 │
│ │
└─────────────────────────────────────────────────────────────────────┘

# patroni.yml on each node
scope: postgres-cluster
name: 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: false

# haproxy.cfg
listen 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 3s

ComponentRole
PatroniHA orchestrator
etcd/ConsulConfiguration store
HAProxyConnection router
PostgreSQLDatabase

Next: Chapter 44: pg_dump & pg_restore