0
0
PostgreSQLquery~5 mins

Logical replication basics in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is logical replication in PostgreSQL?
Logical replication is a method to copy data changes from one database to another in real-time, using a publish-subscribe model. It replicates data at the level of individual changes (like insert, update, delete) rather than copying entire files.
Click to reveal answer
beginner
What are the main components involved in logical replication?
The main components are: <br>1. Publisher: The source database that sends data changes.<br>2. Subscriber: The target database that receives and applies changes.<br>3. Publication: Defines which tables and changes to send.<br>4. Subscription: Defines which publications to receive.
Click to reveal answer
beginner
How do you create a publication for logical replication?
Use the SQL command: <br>CREATE PUBLICATION my_pub FOR TABLE table_name;<br>This tells PostgreSQL to publish changes for the specified table.
Click to reveal answer
beginner
How do you create a subscription to receive changes?
Use the SQL command: <br>CREATE SUBSCRIPTION my_sub CONNECTION 'conninfo' PUBLICATION my_pub;<br>This connects to the publisher and starts receiving changes.
Click to reveal answer
beginner
Can logical replication replicate schema changes automatically?
No, logical replication only replicates data changes (inserts, updates, deletes). Schema changes like adding or dropping columns must be done manually on both publisher and subscriber.
Click to reveal answer
Which component in logical replication sends data changes?
APublisher
BSubscriber
CSubscription
DPublication
What SQL command creates a publication for a table named 'orders'?
ACREATE SUBSCRIPTION orders_sub FOR TABLE orders;
BCREATE SUBSCRIPTION orders_pub FOR TABLE orders;
CCREATE PUBLICATION orders_sub FOR TABLE orders;
DCREATE PUBLICATION orders_pub FOR TABLE orders;
Does logical replication copy entire database files?
AYes, it copies all files.
BNo, it copies only data changes.
CYes, but only schema files.
DNo, it copies only schema changes.
Which command connects a subscriber to a publication?
ACREATE PUBLICATION
BALTER SUBSCRIPTION
CCREATE SUBSCRIPTION
DDROP SUBSCRIPTION
Are schema changes replicated automatically in logical replication?
ANo, never.
BYes, always.
COnly if enabled explicitly.
DOnly for certain data types.
Explain the roles of publisher and subscriber in logical replication.
Think about who sends and who receives data.
You got /3 concepts.
    Describe how to set up logical replication between two PostgreSQL databases.
    Focus on the SQL commands and their purpose.
    You got /4 concepts.