Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Failover and Split Brain

Direct answer

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.

When to use this

Use it to design or test automatic failover.

First 30 seconds

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.

Operational verification

primary fails → quorum agrees → replica promoted → old primary fenced → clients redirected

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it to design or test automatic failover.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

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.

Key checks
  • patronictl list — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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_rewind in 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

PlatformManagerDecides leadership through
PostgreSQLPatroniLeader key in etcd / Consul / ZooKeeper / Kubernetes
PostgreSQLpg_auto_failoverMonitor node
MySQLInnoDB Cluster (Group Replication)Group majority
SQL ServerAvailability GroupsWSFC or Pacemaker quorum
GenericPacemaker/CorosyncVotes + 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Automatic failover without fencing.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
failover and split braindatabase failoversplit brain fencing
Confirmation

Confirm action

Continue?