Learning Hub / Architecture & System Design / Distributed Data — Replication, Partitioning & Consensus
Copies and partitions · wrap-up
Cheat sheet & self-check
Every command from this section on one page.
01 · Replication and consistency
PostgreSQL replication
pg_basebackup -h primary -U repl -D dir -R -X stream | Clone a primary and write standby settings (-R) |
SELECT * FROM pg_stat_replication; | On the primary: each standby's state, sync_state and lag |
SELECT pg_current_wal_lsn(); | On the primary: current write position |
SELECT pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(); | On a standby: how far it has received and replayed |
SELECT pg_wal_replay_pause(); / pg_wal_replay_resume(); | Pause or resume replay on a standby (lab use) |
synchronous_standby_names = 'ANY 1 (a, b)' | Quorum commit: wait for any one of two standbys |
SELECT pg_promote(); | Promote a standby to primary |
Guarantees
Linearizable | Acknowledged write visible to every later read, everywhere |
Causal | Effects after causes; strongest model available under partition |
Read-your-writes | A client always sees its own writes |
W + R > N | Read and write sets overlap; not linearizable by itself |
PACELC | Partition: A or C; Else: Latency or C |
Fencing token | Monotonic term number storage checks to reject a stale leader |