Logical Replication — Complete Guide
Logical Replication — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of PostgreSQL Tutorial on Toolliyo Academy.
On this page
PostgreSQL Tutorial · Lesson 62 of 100
Logical Replication
SQL ✓ → Advanced
Advanced · 2 — Production · ~10 min · PostgreSQL — Replication & High Availability
What is this?
Logical replication publishes row changes (INSERT/UPDATE/DELETE) for selected tables — subscribers apply decoded WAL as SQL. Supports upgrades, partial replication, and cross-version in some cases.
Why should you care?
PostgresVerse migrates orders table to new PG major on subscriber while other tables stay on old primary during cutover window.
See it live — copy this example
Run in pgAdmin or psql.
CREATE PUBLICATION orders_pub FOR TABLE orders;
-- On subscriber (connected to publisher)
CREATE SUBSCRIPTION orders_sub
CONNECTION 'host=primary.db.local dbname=PostgresVerse user=repl password=***'
PUBLICATION orders_pub;
What happened?
- Publication names tables to replicate.
- Subscription on downstream connects upstream and applies changes.
- Only orders flow — not whole cluster.
Practice next
- Set wal_level=logical on publisher.
- CREATE PUBLICATION for one table.
- CREATE SUBSCRIPTION on second instance.
- ADD TABLE order_items TO PUBLICATION orders_pub;
- Check lag: SELECT * FROM pg_stat_subscription;
Remember
Publication/subscription model for table-level sync. Requires wal_level logical. Use for migrations, aggregators, and selective fan-out.
PostgresVerse PG16 upgrade
Logical sub replays orders to PG16 cluster; app dual-writes during validation week.
Outcome: Major upgrade without multi-hour downtime window.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!