Free audit

View Audit Scope
PostgreSQL High Availability · Replication & DRStreaming Replication · Patroni · Quorum · pgBackRest

PostgreSQL High Availability & Quorum Topologies.

We architect, audit, and operate production PostgreSQL high availability stacks across bare metal, VMs, cloud instances, and Kubernetes. From synchronous quorum streaming replication and Patroni / pg_auto_failover leader promotion to HAProxy + PgBouncer connection routing and pgBackRest point-in-time recovery, every cluster is engineered to survive node, AZ, and regional failures without split-brain.
  • Streaming replication (sync & async)
  • Patroni + etcd / Consul DCS
  • pg_auto_failover & repmgr
  • HAProxy + PgBouncer routing
  • pg_rewind timeline healing
  • pgBackRest & Barman PITR

postgresql-ha-topologies

4 production HA layers we design & run

Streaming Replication + Patroni

ok

Physical WAL streaming with DCS-backed leader locks, watchdog fencing, and timeline divergence protection.

Explore details

Every topology verified with controlled switchover and fault-injection drills.

P1 Incident Response
15 mins

24/7 for failover & replication emergencies

Consensus & Fencing
etcd · Consul · K8s

Majority quorum locks paired with Linux watchdog self-fencing

Client Re-Routing
HAProxy + PgBouncer

Port 8008 health probes with transaction-level connection draining

Recovery Verification
pg_rewind + PITR

Fast timeline heal plus standby-sourced pgBackRest object-store backups

Selected clients

  • Innoviti
  • Blitz
  • Freecharge
  • Nango
  • Recochain
  • Screen Facts
  • Nexora
  • WeCredit

01 · Why PostgreSQL HA Clusters Fail in Production

Six replication & failover failure modes we eliminate.

Standing up a streaming replica takes twenty minutes; making sure it promotes cleanly during a 3 AM availability-zone brownout without corrupting timelines or dropping application traffic is where most clusters break.

Production SymptomArchitectural Root CauseJusDB Engineering Remediation
Split-brain dual primaries after a transient network partitionHomegrown failover scripts promote a standby on ping failure without distributed consensus (etcd, Consul, or pg_auto_failover monitor) or Linux softdog/IPMI fencing, leaving the old primary accepting writes.Enforce strict DCS leader key TTLs, kernel watchdog hardware/software fencing before promotion, and HAProxy HTTP health checks that verify both leader role and DCS lock validity.
Replication slot WAL bloat fills primary disk during standby maintenancePhysical or logical replication slots retain WAL segments indefinitely when a standby disconnects or falls behind, and max_slot_wal_keep_size is left unset (-1).Configure max_slot_wal_keep_size safety caps, pair physical slots with continuous pgBackRest S3/GCS WAL archiving for fallback catchup, and alert on pg_replication_slots retained bytes.
Former primary requires full multi-terabyte basebackup to rejoin after failoverwal_log_hints or data checksums are disabled, or the old primary wrote transactions after the standby promotion point, causing pg_rewind to fail on timeline divergence.Enable data page checksums or wal_log_hints=on across all cluster nodes, configure restore_command access to the shared WAL archive, and automate pg_rewind before standby re-registration.
Synchronous replication stalls all primary writes during a single-AZ hiccupsynchronous_standby_names is configured with a single standby instead of an ANY 1 (node2, node3) quorum across three availability zones.Deploy a 3-AZ quorum topology using ANY 1 (standby_az2, standby_az3) with synchronous_commit = remote_write or on, ensuring writes continue if any single standby restarts.
Application connections hang for minutes after a controlled switchoverApplications connect directly to node IPs or rely on high-TTL DNS records without PgBouncer PAUSE/RESUME orchestration or HAProxy fast health-check intervals.Place HAProxy or Envoy in front of Patroni REST endpoints (/primary, /replica?lag=100MB) coupled with PgBouncer transaction pooling so switchovers reconnect in seconds.
Hot standby read queries cancel with 'conflict with recovery' errorsVACUUM on the primary removes dead tuples still visible to long-running analytical queries on the streaming replica, triggering hot_standby_feedback or max_standby_streaming_delay conflicts.Route long reporting queries to a dedicated delayed or logical replica, tune max_standby_streaming_delay for OLTP readers, and isolate hot_standby_feedback to prevent primary bloat.

02 · High Availability Workstreams

End-to-end PostgreSQL resilience across six layers.

We design and operate the complete high availability stack: physical WAL streaming, distributed consensus leader election, connection pooling and proxy routing, continuous PITR backups, and live switchover GameDays.

01

Streaming Replication & Quorum Design

We architect physical streaming replication topologies across availability zones and regions, selecting async, sync remote_write, or sync remote_apply quorum rules based on your RPO and latency budgets.

  • 3-node and 5-node quorum layouts with ANY N / FIRST N standby groups
  • Replication slot lifecycle management and max_slot_wal_keep_size guardrails
  • Cascading replication trees to offload WAL sender CPU from the primary
pg_stat_replication · synchronous_standby_names · wal_sender_timeout
PostgreSQL Architecture Consulting
02

Patroni & pg_auto_failover Orchestration

We implement and harden automated leader election using Patroni (with etcd, Consul, or Kubernetes DCS) or pg_auto_failover for simpler two-node plus monitor deployments.

  • DCS lease timing (ttl, loop_wait, retry_timeout) tuned for cloud network jitter
  • Linux softdog/watchdog integration and pre-promote fencing verification
  • Automated pg_rewind timeline healing when former primaries rejoin
Patroni · etcd · Consul · pg_auto_failover · pg_rewind
Patroni HA Consulting
03

HAProxy, Keepalived & PgBouncer Routing

Leader promotion only works if traffic follows immediately. We build deterministic connection routing stacks that separate read/write traffic and drain connections cleanly during switchover.

  • HAProxy HTTP checks against Patroni /primary and /replica?lag=max_bytes
  • PgBouncer transaction pooling with PAUSE, RECONNECT, and RESUME hooks
  • Keepalived VRRP virtual IPs, AWS NLB target groups, or Consul service discovery
HAProxy · PgBouncer · Keepalived · Envoy
PgBouncer Connection Pooling
04

pgBackRest, Barman & Cross-Region DR

High availability protects against node failures; backups protect against DROP TABLE and regional outages. We engineer continuous WAL archiving and tested point-in-time recovery (PITR).

  • Parallel delta backup and restore pipelines to S3, GCS, or Azure Blob via pgBackRest
  • Standby-sourced backups to eliminate disk I/O impact on the primary
  • Automated monthly restore verification into ephemeral test instances
pgBackRest · Barman · WAL-G · S3 / GCS / Azure Blob
PostgreSQL Managed Support
05

Managed Cloud & Kubernetes HA Topologies

Running on RDS Multi-AZ, Aurora PostgreSQL, Cloud SQL Regional HA, or Kubernetes? We tune cloud failover behavior, RDS Proxy pooling, and CloudNativePG operator configurations.

  • RDS Multi-AZ DB Cluster vs single-standby Multi-AZ latency and failover trade-offs
  • Aurora PostgreSQL writer failover, custom reader endpoints, and driver wrapper tuning
  • CloudNativePG (CNPG) and Zalando operator pod anti-affinity and local NVMe PVCs
RDS Multi-AZ · Aurora · Cloud SQL HA · CloudNativePG
PostgreSQL on Kubernetes
06

Chaos GameDays & Switchover Runbooks

An untested HA cluster is a hypothesis. We run controlled switchovers and fault-injection GameDays in staging and production maintenance windows to measure real recovery times.

  • Packet-loss, primary process kill, and disk-stall fault injection testing
  • Measured RTO and RPO scorecards across application connection pools
  • Step-by-step operator runbooks for manual switchover, fencing, and PITR
patronictl switchover · pg_ctl promote · Prometheus postgres_exporter
PostgreSQL Remote DBA

03 · Topology Selection & Response SLA

Choosing the right HA stack and P1-P3 response coverage.

Not every PostgreSQL cluster needs a 5-node etcd ring, and not every workload can tolerate cloud DNS failover latencies. We match the topology to your RPO, RTO, and operational footprint, backed by published SLA response times.

HA StackConsensus & Fencing MechanismTypical RPOTraffic Switchover PathBest Fit
Patroni + etcd/Consul + HAProxy3-node or 5-node DCS (etcd / Consul / ZooKeeper)Zero committed tx loss (sync quorum) or <1s WAL lag (async)Automated leader promotion + HAProxy HTTP port 8008 routingMission-critical bare-metal, VM, and multi-AZ self-managed PostgreSQL
pg_auto_failoverDedicated PostgreSQL monitor node health-check state machineSynchronous replication by default with configurable standby countMonitor-coordinated state transition with libpq multi-host URIsCompact 2-data-node + 1-monitor setups seeking simpler operations without etcd
repmgr + witness noderepmgrd daemon with witness node in third failure domainAsync or synchronous physical streaming replicationrepmgrd promotion hook triggering VIP move or PgBouncer reloadLegacy PostgreSQL estates standardizing existing repmgr deployments
CloudNativePG (CNPG) on K8sKubernetes API server lease + native operator controller loopSynchronous quorum commit across AZ-pinned worker nodesOperator updates -rw and -ro Kubernetes Service endpoints directlyKubernetes-native PostgreSQL platforms with local NVMe CSI storage
RDS Multi-AZ / Cloud SQL HACloud provider storage-level or regional synchronous standbyZero storage-level loss within region; async cross-region read replicasProvider-managed DNS flip + RDS Proxy or PgBouncer fast reconnectTeams offloading OS/storage maintenance while tuning DB-layer failover speed
Published SLA Response Times

P1 to P3 SLA response times for replication & failover incidents

Our engineering team is in India (IST, UTC+5:30) and provides 24/7 support.

P1 · Critical15 mins

Production database down, primary unreachable, data corruption risk, or active failover event.

P2 · High30 mins

Severe latency spike, replication lag climbing rapidly, connection exhaustion, or degraded HA node.

P3 · Medium60 mins

Non-critical slow query regression, staging issue, backup warning, configuration question, or planned operational request.

Response means an on-call engineer is working the incident, not an automated reply. JusDB's security practices are aligned with ISO 27001 and SOC 2 Type II, and JusDB is pursuing both certifications (see Terms, section 12). Review SLA & legal terms.

04 · Interactive Quorum Failover Lifecycle

Inspect how a 3-AZ PostgreSQL quorum cluster handles primary isolation.

Step through a real synchronous quorum topology during steady state, an availability-zone partition that triggers DCS lease expiry and standby promotion, and automated pg_rewind re-integration.

pg-prod-core · 3-AZ Quorum State Machine

Select a lifecycle stage to inspect cluster telemetry and logs

Application and routing

Primary pg-node-01 holds the DCS leader lock, commits synchronously to at least one quorum standby (ANY 1), and ships continuous WAL archives to object storage.

Active

    Primary pg-node-01 holds the DCS leader lock, commits synchronously to at least one quorum standby (ANY 1), and ships continuous WAL archives to object storage.

    05 · Representative Production Deliverable

    Synchronous quorum config, replication lag probe & pg_rewind runbook.

    Every HA engagement ships with copy-pasteable configuration and verification SQL. Below is an excerpt from a 3-node synchronous quorum rollout showing synchronous_standby_names, byte-lag diagnostics, and pg_rewind timeline re-alignment.

    postgresql.conf + pg_stat_replication quorum & pg_rewind verification

    -- 1. Quorum synchronous replication across two standbys (AZ-b and AZ-c)
    -- Commits succeed as soon as ANY 1 standby flushes WAL to disk (or remote_write)
    ALTER SYSTEM SET synchronous_standby_names = 'ANY 1 (pg_node_02, pg_node_03)';
    ALTER SYSTEM SET synchronous_commit = 'on';
    ALTER SYSTEM SET wal_log_hints = 'on';              -- Required for pg_rewind if checksums are off
    ALTER SYSTEM SET max_slot_wal_keep_size = '64GB';   -- Guard primary disk from orphaned slots
    ALTER SYSTEM SET wal_sender_timeout = '15s';
    ALTER SYSTEM SET wal_receiver_timeout = '15s';
    SELECT pg_reload_conf();
    
    -- 2. Verify quorum state, LSN lag in bytes, and replay delay across standbys
    SELECT
        application_name,
        client_addr,
        state,
        sync_state,
        sync_priority,
        pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), sent_lsn))   AS send_lag,
        pg_size_pretty(pg_wal_lsn_diff(sent_lsn, flush_lsn))              AS flush_lag,
        pg_size_pretty(pg_wal_lsn_diff(flush_lsn, replay_lsn))            AS replay_lag,
        write_lag,
        flush_lag AS flush_time_lag,
        replay_lag AS replay_time_lag
    FROM pg_stat_replication
    ORDER BY sync_state, application_name;
    
    -- 3. Inspect physical replication slots for retained WAL bloat risk
    SELECT
        slot_name,
        slot_type,
        active,
        wal_status,
        pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal
    FROM pg_replication_slots;
    
    -- 4. Rejoin a fenced former primary after leader promotion using pg_rewind
    -- Run on pg-node-01 after stopping postgresql service:
    -- pg_rewind --target-pgdata=/var/lib/postgresql/16/main \
    --   --source-server="host=10.24.2.12 port=5432 user=rewind_user dbname=postgres sslmode=verify-full" \
    --   --restore-target-wal

    06 · Ways to Work Together

    Engage us for an HA architecture build, audit, or managed operations.

    Whether you need a fixed-scope Patroni + pgBackRest deployment, a pre-launch failover GameDay, or ongoing remote DBA ownership, we scope directly with senior PostgreSQL engineers.

    Retained OperationsRecommended

    Managed HA & Remote DBA

    Continuous monitoring of replication lag, slot retention, etcd/Consul quorum health, and monthly pgBackRest restore drills with published SLA response times.

    Included in scope

    • P1 response in 15 mins
    • Proactive switchover execution during OS & minor upgrades
    • Monthly automated PITR restore verification reports
    Fixed-Scope ProjectFixed-Scope Project

    HA Architecture & Cutover Build

    Design and deploy a production Patroni, pg_auto_failover, CloudNativePG, or Multi-AZ topology with HAProxy, PgBouncer, pgBackRest, and live switchover validation.

    Included in scope

    • Quorum topology & DCS sizing blueprint
    • Automated Ansible / Terraform / Helm manifests
    • Chaos GameDay switchover scorecard & operator runbook
    Diagnostic AssessmentDiagnostic Assessment

    PostgreSQL HA & DR Readiness Audit

    We inspect your existing replication, Patroni/repmgr configs, connection poolers, and backup pipelines to uncover split-brain vectors and single points of failure.

    Included in scope

    • DCS lease, watchdog fencing, and slot bloat audit
    • RPO/RTO gap analysis with prioritized remediation diffs
    • Direct walkthrough with senior PostgreSQL architects

    Procurement and security

    Ready for legal and security review.

    Mutual NDA before any access, least-privilege credentials in your vault, and security controls aligned with ISO 27001 and SOC 2 Type II.
    • Mutual NDA before any access
    • Named individual accounts only
    • Read-only access by default
    • ISO 27001 & SOC 2 Type II: aligned, certification in progress
    • Mutual NDA before any access

      We sign a mutual NDA before viewing schemas, logs, slow-query captures, or cloud topology.

    • Least-privilege, named credentials

      Engineers connect through your bastion, VPN, or SSM using named accounts with read-only permissions by default.

    • Change control & approval gates

      Production DDL, parameter changes, and failovers follow your change-management workflow with rollback steps prepared first.

    • Named leadership & direct escalation

      Engagements are led by named senior database reliability engineers in India with direct Slack, Teams, and PagerDuty channels.

    07 · Frequently Asked Questions

    PostgreSQL high availability & replication FAQs.

    Technical answers on Patroni vs pg_auto_failover, split-brain fencing, synchronous quorum latency, and pg_rewind.

    Still have a question?

    Ask it on a scoping call. No production access needed.

    Book a 30-min scoping call (opens Google Calendar in a new tab)

    Should we use Patroni, pg_auto_failover, or repmgr for PostgreSQL high availability?

    For production multi-AZ clusters on VMs or bare metal, Patroni backed by a 3-node or 5-node etcd or Consul cluster is the industry standard because it relies on strong distributed consensus and integrates cleanly with HAProxy and pgBackRest. pg_auto_failover is a strong fit for smaller footprints that want synchronous replication and automated leader promotion using a single lightweight PostgreSQL monitor node instead of operating etcd. repmgr remains common in legacy estates, and we frequently either harden existing repmgr witness topologies or migrate them to Patroni or CloudNativePG.

    How do you prevent split-brain dual primaries during a network partition?

    Preventing split-brain requires three coordinated controls: first, leader election must depend on a majority quorum in a Distributed Consensus Store (etcd, Consul, or Kubernetes API leases) rather than peer-to-peer ping checks; second, the primary must run with a Linux kernel watchdog (/dev/watchdog) so that if Patroni freezes or cannot demote PostgreSQL before the DCS lease expires, the node self-fences immediately; third, HAProxy or Envoy only routes writes to the node whose REST health endpoint confirms it currently holds the leader lock.

    What is the performance impact of synchronous replication in PostgreSQL?

    Synchronous replication adds the network round-trip time (RTT) between the primary and the fastest quorum standby to every commit. Within a single cloud region across availability zones (typically 0.5 ms to 1.5 ms RTT), using synchronous_standby_names = 'ANY 1 (node2, node3)' and synchronous_commit = remote_write or on adds minimal overhead while protecting against single-AZ loss. We also configure per-transaction synchronous_commit overrides so non-critical telemetry tables can commit locally without waiting for standby acknowledgment.

    How do HAProxy and PgBouncer work together during a PostgreSQL switchover?

    Patroni exposes HTTP health endpoints on port 8008 (/primary returns HTTP 200 only on the current leader; /replica?lag=100MB returns HTTP 200 only on healthy standbys within the lag threshold). HAProxy polls these endpoints every second and routes port 5000 to the writer and port 5001 to readers. When paired with PgBouncer in transaction pooling mode, planned switchovers use pre-switchover scripts to PAUSE client transactions, promote the new standby, and RESUME against the new primary in under a few seconds.

    Why do replication slots fill up primary disks, and how do you guard against it?

    A physical or logical replication slot forces the primary to retain all WAL segments since the standby's last confirmed flush LSN. If a standby crashes or loses network connectivity, pg_wal grows until the primary disk reaches full capacity and halts the cluster. On PostgreSQL 13+, we set max_slot_wal_keep_size as a circuit breaker, monitor pg_replication_slots retained bytes via Prometheus, and configure restore_command with pgBackRest so a lagging standby can fetch recycled WAL segments from S3 or GCS.

    How does pg_rewind work after a failover, and when can it fail?

    When an old primary comes back online after a standby was promoted to a new timeline, its data directory may contain blocks modified after the divergence LSN. pg_rewind scans the old primary's WAL back to the last common checkpoint before divergence and overwrites only the changed blocks from the new primary. For pg_rewind to succeed, the cluster must have either data checksums enabled at initdb time or wal_log_hints = on in postgresql.conf, plus access to all WAL segments generated around the divergence point.

    Is streaming replication enough for disaster recovery, or do we still need pgBackRest?

    Streaming replication is not a backup. An accidental DROP TABLE, TRUNCATE, or buggy migration replicates to synchronous and asynchronous standbys within milliseconds. True disaster recovery requires continuous physical backups and WAL archiving via pgBackRest or Barman to immutable object storage, enabling Point-In-Time Recovery (PITR) to the exact transaction or timestamp prior to logical corruption.

    What SLA response times apply if our PostgreSQL HA cluster suffers an outage?

    24/7 support. SLA response times: P1 – 15 mins | P2 – 30 mins | P3 – 60 mins. Our engineering team is in India (IST, UTC+5:30) and provides 24/7 support. Response means an on-call engineer is working the incident, not an automated reply.

    Ready to harden your PostgreSQL availability?

    Eliminate split-brain risks and verify your failover runbook.

    Speak directly with a senior PostgreSQL architect to review your streaming replication topology, Patroni or cloud HA configuration, and pgBackRest recovery posture.

    Direct with a senior engineer · No sales handoff · Our engineering team is in India (IST, UTC+5:30) and provides 24/7 support.