Replication BasicsIntermediate
1Question 1 of 1
sqlWhat is physical vs logical replication in PostgreSQL?
Explanation & Concept
• Physical Replication (Streaming Replication): Copies byte-for-byte WAL records from the primary server to standby replicas. It replicates the entire cluster verbatim and standby nodes are read-only. • Logical Replication: Replicates data changes at the logical row level using a publish-subscribe model. You can replicate specific tables, write to target replicas, replicate between different PostgreSQL major versions, or consolidate multiple databases into one.
Code Example
sql
-- On Primary (Publisher):
CREATE PUBLICATION customer_sync FOR TABLE customers, orders;
-- On Remote Subscriber:
CREATE SUBSCRIPTION customer_receiver
CONNECTION 'host=primary.internal dbname=app user=replicator password=secret'
PUBLICATION customer_sync;How It Works & Key Takeaways
Logical replication allows microservices or analytical databases to stream specific table updates in real-time across different database versions without full database cloning.
Mock Test · 1 Questions · Optional
Ready for Constraints & Foreign Keys?
Take a quick test to evaluate yourself, or move straight to the next module.
Advanced1 questions