Skip to content
Learn Netverks

Lesson

Step 28/36 78% through track

replication-preview

Replication preview

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Replication preview: the SQL patterns, schema habits, and query reasoning you need before advancing in PostgreSQL.

Streaming replication underpins HA—lag monitoring and failover drills are production requirements.

You will apply Replication preview in contexts like: Managed cloud databases, on-call runbooks, and disaster recovery drills.

Copy Postgres SQL into psql, local PostgreSQL, or DB Fiddle (PostgreSQL dialect)—use \d and EXPLAIN ANALYZE where lessons show them. The in-browser lab ships later; psql is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

Replication copies data to standby servers for read scaling and high availability. Postgres streaming replication ships WAL records to replicas.

Primary and standby concept

Primary accepts writes; standby replays WAL for read-only queries (hot standby) or failover promotion. Managed services automate failover.

Replication lag check

SELECT client_addr, state, sent_lsn, replay_lsn,
       pg_wal_lsn_diff(sent_lsn, replay_lsn) AS lag_bytes
FROM pg_stat_replication;

Run on primary when replication is configured—empty on single-node sandboxes.

Practice: Run on a local Postgres instance you own. Avoid changing production cluster settings.

Read replicas in apps

Route analytics to replicas; keep writes on primary. ORMs need explicit read replica routing—eventual consistency applies.

Important interview questions and answers

  1. Q: WAL role in replication?
    A: Standbys replay WAL to stay consistent with primary.
  2. Q: Logical vs physical replication?
    A: Physical streams byte-level changes; logical decodes row changes for selective subscriptions.

Self-check

  1. What does pg_stat_replication show?
  2. Why route heavy reports to replicas?

Tip: Route heavy reads to replicas; keep writes on the primary.

Interview prep

WAL in replication?

Standbys replay WAL from primary.

Read replica use?

Offload read-heavy reporting from primary.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Streaming vs logical?
  • Replica lag?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump