Use it to design or troubleshoot replicas and failover.
Replication & High Availability
Replication copies data to other servers for read scaling and availability; high availability adds automatic failover (Patroni, Always On AGs, Galera, orchestrators).
1. Replication state: pg_stat_replication / SHOW REPLICA STATUS\G / AG dashboard.
2. Lag within target?
3. Failover tested?
4. Clients reconnect to the new primary (VIP/DNS/proxy)?
5. Quorum/witness configured.
primary writes WAL/binlog → shipped to replicas → applied → failover promotes a replica
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. Preserve the first divergent observation and repeat the same bounded verification after remediation.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Databases owns engine replication/failover semantics. Networking owns transport/name resolution; Storage owns shared/replicated media where applicable; backup remains a separate protection layer.
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 Verification workflow Verify boundary
Verify source/primary identity, replica receive/apply position, lag and health from both sides. Exercise a documented failover in a bounded environment, confirm client reconnection and writable/read-only role, then validate failback/resynchronization and backup continuity.
Step 2 Failure signatures and limits Narrow the fault
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.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
Streaming replication sends WAL from a primary to standbys continuously so they can take over or serve read queries.
Subtopic Failover and Split BrainFailover promotes a replica to primary when the old primary fails; split brain happens when two nodes accept writes at the same time.
Subtopic Read Replicas and Replication LagRead replicas serve read queries to offload the primary; replication lag means they may return slightly old data.
Asynchronous replicas can lose recent transactions on failover; synchronous ones add latency. Monitor lag. Prevent split brain with a quorum/witness.
pg_stat_replication— 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
Operating model
Replication & High Availability covers keeping database copies synchronized enough to serve read scaling or failover. Synchronous modes trade latency/availability for stronger acknowledgement semantics; asynchronous modes can lose recent committed data at failover. HA reduces service interruption but does not protect against every logical/data-corruption event.
ReferenceHow it works1 section · depth on demand
In depth
Replication copies data from a primary to one or more replicas, providing read scaling, faster failover and disaster recovery. High availability adds automatic or managed failover so applications keep working when the primary fails.
| Engine | Replication | HA tooling |
|---|---|---|
| PostgreSQL | Streaming (physical), logical | Patroni, repmgr, cloud managed services |
| MariaDB/MySQL | Binlog (GTID), semi-sync; Galera (MariaDB) | Orchestrator, MaxScale, InnoDB Cluster |
| SQL Server | Always On availability groups, log shipping | Windows/Pacemaker clusters, listeners |
Key concepts:
| Concept | Meaning |
|---|---|
| Synchronous | Commit waits for replica — no data loss, higher latency |
| Asynchronous | Faster; recent transactions can be lost on failover |
| Replication lag | How far replicas are behind |
| Split brain | Two primaries — prevented with quorum/fencing |
Replication is not a backup: deletions and corruption replicate too. Monitor lag and test failover regularly.
ReferenceImportant terms & boundaries1 section · depth on demand
Scope map
- Primary/replica model
- Synchronous vs asynchronous replication
- Replication lag
- Read replicas
- Failover/failback
- Split-brain/fencing concepts
- HA does not replace backup
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: One primary and at least one physical standby.
SELECT client_addr, state, sync_state,
pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) AS replay_lag_bytes,
replay_lag
FROM pg_stat_replication;Expected output
SELECT client_addr, state, sync_state, replay_lag FROM pg_stat_replication;Expected state: Each standby is streaming and replay lag stays small and stable.
client_addr | state | sync_state | replay_lag
-------------+-----------+------------+-----------------
10.0.10.23 | streaming | async | 00:00:00.012
(1 row)A missing row means the standby is not connected at all. async standbys can lose recent commits on failover; sync standbys trade latency for that guarantee. Illustrative authored output: field layout matches the tool, values will differ in your environment.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Documentation verification: confirms the upstream model used by the Topic. It does not assert local production behavior.
Basis: https://www.postgresql.org/docs/current/high-availability.html · confidence 92%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
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.
Quick lookup tables
Replication & High Availability verification boundary matrix
A compact lookup separating intent, owning component state, effective state and consumer-visible outcome for Replication & High Availability.
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Primary/replica model | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Synchronous vs asynchronous replication / Replication lag | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Read replicas | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Failover/failback | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Deep reference
Design & tradeoffs
Scope
Databases owns engine replication/failover semantics. Networking owns transport/name resolution; Storage owns shared/replicated media where applicable; backup remains a separate protection layer.