Use it to design or test automatic failover.
Failover and Split Brain
Failover promotes a replica when the primary fails; split brain happens when two nodes both accept writes. Quorum, fencing and a single source of truth prevent it.
1. Who is primary now? manager status (patronictl list, AG dashboard).
2. Quorum/witness healthy?
3. Fencing configured?
4. Clients follow the primary?
5. Test failover and failback.
primary fails → quorum agrees → replica promoted → old primary fenced → clients redirected
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Run failover drills. Confirm writes go only to the new primary. Check data written to the old primary after the failure was not lost unexpectedly.
Step 2 Common failures Narrow the fault
Two nodes promoted after a network split cause diverging data. DNS caching keeps clients on the old primary. Asynchronous replicas lose commits that never arrived.
Use a consensus-based manager (Patroni with etcd, Always On with quorum, Orchestrator/MHA, Galera quorum). Fence the old primary. Point clients via VIP, DNS or proxy that follows the leader.
patronictl list— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
Cluster managers use a consensus store or quorum to elect one primary. After promotion, the old primary must be rebuilt (for example with pg_rewind) before rejoining as a replica.
ReferenceImportant terms & boundaries3 sections · depth on demand
Avoiding split brain
- Use a cluster manager with consensus (Patroni with etcd/Consul, Pacemaker with quorum, SQL Server WSFC, Orchestrator/MySQL InnoDB Cluster).
- Fence or isolate the old primary before promoting (STONITH, shutting its listener, revoking VIP).
- Point clients through a VIP, DNS record or proxy (HAProxy, PgBouncer, ProxySQL) that the cluster manager updates.
- After failover, rebuild the old primary as a replica (
pg_rewindin PostgreSQL).
In depth
What must be true before promoting a standby
1. The old primary cannot accept writes any more — stopped, isolated, or fenced (STONITH). Without that, both nodes may accept writes and the data diverges.
2. The chosen standby is the most up to date (compare received/replayed LSN on all candidates).
3. Clients will reach the new primary: virtual IP moved, DNS updated with a short TTL, or connection strings listing several hosts with target_session_attrs=read-write (libpq) so clients find the writable node themselves.
PostgreSQL itself does not detect primary failure or move clients; a cluster manager does that.
Cluster managers and their quorum source
| Platform | Manager | Decides leadership through |
|---|---|---|
| PostgreSQL | Patroni | Leader key in etcd / Consul / ZooKeeper / Kubernetes |
| PostgreSQL | pg_auto_failover | Monitor node |
| MySQL | InnoDB Cluster (Group Replication) | Group majority |
| SQL Server | Availability Groups | WSFC or Pacemaker quorum |
| Generic | Pacemaker/Corosync | Votes + fencing devices |
A manager without fencing or an external quorum is a split-brain risk in a network partition.
Rejoining the old primary
After failover the old primary may have WAL the new primary never received. It cannot simply start as a standby: rewind it to the divergence point and follow the new timeline.
pg_rewind --target-pgdata=/var/lib/postgresql/data --source-server='host=db2 user=postgres'
pg_rewind needs wal_log_hints = on or data checksums enabled beforehand; otherwise rebuild the node from a fresh base backup.
What asynchronous replication can lose
Every transaction committed on the old primary but not yet received by the promoted standby is gone from the new timeline. Measure typical replication lag; that is the realistic data loss on failover.
Common mistakes
- Automatic failover without fencing.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.