Pcornel
Databases

Replication & High Availability

Cheat sheet · https://pcornel.dk/topic.php?topic=6094

Back to the Topic

Answer

Replication copies data to other servers for read scaling and availability; high availability adds automatic failover (Patroni, Always On AGs, Galera, orchestrators).

Remember

Asynchronous replicas can lose recent transactions on failover; synchronous ones add latency. Monitor lag. Prevent split brain with a quorum/witness.

First checks

  • pg_stat_replication — 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

Verify in this order

primary writes WAL/binlog → shipped to replicas → applied → failover promotes a replica

Where it usually breaks

Failures include connected-but-stalled replicas, hidden lag, wrong read/write routing, split brain, stale DNS/listener targets, missing fencing, replication of accidental deletes and promoting a replica without understanding data-loss position.

Replication & High Availability verification boundary matrix

BoundaryInspectHealthy interpretationDo not infer
IntentPrimary/replica modelIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeSynchronous vs asynchronous replication / Replication lagOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateRead replicasIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeFailover/failbackThe original bounded check succeeds in the same time windowProduction correctness outside this scope

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6094

Confirmation

Confirm action

Continue?