dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
postgresql Reference Architecture
RPO: 0 (Senkron Replikasyon ile)
RTO: < 15 saniye (Otomatik Lider Seçimi)

PostgreSQL + Patroni + etcd + HAProxy Enterprise HA

Distributed consensus-backed HA topology using etcd to eliminate split-brain hazards and guarantee sub-15s automatic failover.

Components:Patronietcd v3HAProxyKeepalivedpgBackRest
Architecture Topology & Flow Diagram
PostgreSQL + Patroni + etcd + HAProxy Enterprise HA Reference Architecture Diagram (Raft Quorum, DCS / Leader Lock, VIP)

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

Topology Blueprint
3x DB Node + 3x etcd Cluster + 2x HAProxy / Keepalived
Client Ingress & Routing Flow
11. Client Ingress & VIP

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

22. 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.

33. Synchronous WAL Streaming

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

Automated Failover & Quorum Sequence
11. Heartbeat Expiry

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

22. Standby Election

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

33. HAProxy Dynamic Re-route

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

Production Config Blueprint
# 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
Cluster Health & Triage CLI
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
Pros & Strengths
  • •Automated failover & split-brain immunity
  • •Dynamic cluster configuration
  • •Graceful zero-data-loss switchover for maintenance
Cons & Constraints
  • •Requires minimum 3-node quorum
  • •Higher infrastructure and networking complexity
Pre-Prod 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.