dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
[Mimari]PostgreSQL PostgreSQL 16 / 17 · Patroni 3.3+Expert
25 min read

PostgreSQL + Patroni + etcd + HAProxy Enterprise High Availability

Raft Distributed Consensus, Sub-15s Automated Failover & Zero-Data-Loss Architecture

Author / Standard:Principal Infrastructure Architect
Topology
3x DB Node + 3x etcd Cluster + 2x HAProxy / Keepalived
RPO (Recovery Point Objective)
0 (Senkron Replikasyon ile)
RTO (Recovery Time Objective)
< 15 saniye (Otomatik Lider Seçimi)
Architecture Stack Components
Patronietcd v3HAProxyKeepalivedpgBackRest
PostgreSQL + Patroni + etcd + HAProxy Enterprise High Availability

PostgreSQL + Patroni + etcd + HAProxy Enterprise HA Reference Architecture Diagram (Raft Quorum, DCS / Leader Lock, VIP)

Architectural Strengths
  • •Automated failover & split-brain immunity
  • •Dynamic cluster configuration
  • •Graceful zero-data-loss switchover for maintenance
Trade-offs & Constraints
  • •Requires minimum 3-node quorum
  • •Higher infrastructure and networking complexity

Ingress & Traffic Flow

1. Client Ingress & VIP

Applications connect through Keepalived Virtual IP (VIP: 10.0.1.10) to HAProxy layer.

2. R/W & R/O Port Routing

Port 5000 routes write traffic to the `/primary` node, while port 5001 load balances read traffic across healthy `/replica` nodes.

3. Synchronous WAL Streaming

Primary verifies WAL delivery to at least one synchronous standby replica before acknowledging commit (RPO=0).

Automated Failover Steps

1. Heartbeat Expiry

Primary fails to refresh its DCS lease key in etcd (lease TTL: 30s).

2. Standby Election

Patroni daemons elect the standby node with the highest WAL LSN as the new cluster leader.

3. HAProxy Dynamic Re-route

HAProxy detects the change via port 8008 REST API and redirects write traffic within 2 seconds.

Production Go-Live Checklist

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.
Reference Configuration Snippet
# 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: postgres
Health Check & Status Commands
patronictl -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

Other PostgreSQL Guides

Verified operational assets for this database engine.

Tümünü Gör