Database field guide · 18
Replication and High Availability
Transport, apply, failover, and recovery objectives
Turn log transport and replicas into explicit durability, availability, consistency, RPO, and RTO guarantees.
Franck Pachot7 chaptersreplication · Data Guard · failover · RPO/RTO
Build the mental model before choosing the mechanism.
This minibook was AI-generated from Franck Pachot's archived blog posts. Links to the original articles are included for source context and verification.
01
Replication starts with a promise
A replica may protect durability, serve reads, enable disaster recovery, or feed change data capture. Each purpose requires a different contract for acknowledgement and apply.
- Transported is not necessarily applied.
- Available is not necessarily current.
- State the failure domain each copy protects.
02
Synchronous changes commit
Synchronous transport adds a remote acknowledgement to commit. The exact wait point may prove receipt in memory, durable log storage, or applied state.
- Quorum policy defines tolerated failures.
- Network tails appear in commit latency.
- Fallback modes can silently change protection.
03
Asynchronous creates an RPO
Asynchronous replication decouples commits from network latency but permits acknowledged changes to be absent after source loss. Lag must be measured in the log coordinate system.
- Byte lag and time lag answer different questions.
- Archive gaps can stop apply long after transport recovers.
- RPO is a tested business limit, not a topology label.
04
Reads need a freshness contract
A read replica can be transactionally consistent at its replay position while stale relative to the primary. Read routing must define monotonicity and read-your-writes behavior.
- Route consistency-sensitive reads to a sufficient position.
- Apply delay may be intentional for recovery.
- Long queries can conflict with replay cleanup.
05
Failover is a client workflow
Promotion alone does not restore service. Fencing the old primary, changing routes, reconnecting pools, replaying transactions, and rebuilding protection determine real recovery time.
- Prevent dual writers before accepting traffic.
- Use request identity across ambiguous commits.
- Practice failback and replica re-creation.
06
Prove RPO and RTO
A resilient design measures detection, decision, promotion, routing, client recovery, and backlog drain under realistic faults.
- Observe-only automation validates decisions safely.
- Test regional and storage failures separately.
- Include data validation in recovery completion.
07
Field manual
Concrete mechanics, diagnostic evidence, and executable patterns to carry into a real system.
01
Measure PostgreSQL replay position
Compare primary flush LSN with standby receive, replay, and replay timestamp. Timestamp delay can be NULL or misleading when a system is idle.
-- Primary: SELECT pg_current_wal_flush_lsn();
-- Standby:
SELECT pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(),
now()-pg_last_xact_replay_timestamp() AS replay_delay;
02
Inspect synchronous policy
synchronous_standby_names defines which standbys participate; pg_stat_replication shows state, sync role, and byte positions. Validate the policy during a standby outage.
SHOW synchronous_commit;
SHOW synchronous_standby_names;
SELECT application_name, state, sync_state, sent_lsn, flush_lsn, replay_lsn
FROM pg_stat_replication;
03
Read Data Guard transport and apply
V$ARCHIVE_DEST_STATUS and V$DATAGUARD_STATS separate destination health, transport lag, and apply lag. Broker status adds role-transition readiness.
SELECT dest_id, status, database_mode, recovery_mode, error
FROM v$archive_dest_status WHERE status <> 'INACTIVE';
SELECT name, value, unit FROM v$dataguard_stats;
04
Test ambiguous commit recovery
A client can lose its connection after commit reaches the server but before acknowledgement returns. Retrying blindly duplicates effects; a stable request key makes outcome discovery safe.
CREATE UNIQUE INDEX payment_request_uk ON payment(request_id);
INSERT INTO payment(request_id, account_id, amount) VALUES ($1,$2,$3)
ON CONFLICT (request_id) DO NOTHING
RETURNING payment_id;
08
Source articles
Optional deep dives with the complete experiments and product-version context behind this guide.