0
0
PostgreSQLquery~20 mins

Logical replication basics in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Logical Replication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of logical replication in PostgreSQL?

Logical replication allows data to be copied between PostgreSQL servers. What is its main use?

ATo replicate data changes at the table level for selective synchronization
BTo compress data for faster network transfer
CTo create physical backups of the database files
DTo replicate the entire database cluster including configuration files
Attempts:
2 left
💡 Hint

Think about what logical replication copies: is it the whole database or parts of it?

query_result
intermediate
2:00remaining
What rows are replicated by default in logical replication?

Given a publication created with CREATE PUBLICATION pub1 FOR TABLE employees;, which rows will be replicated to the subscriber?

PostgreSQL
CREATE PUBLICATION pub1 FOR TABLE employees;
AAll rows existing before and after the publication creation
BAll rows inserted, updated, or deleted after the publication is created
COnly rows inserted after the publication is created
DOnly rows updated after the publication is created
Attempts:
2 left
💡 Hint

Think about whether logical replication copies existing data or just changes.

📝 Syntax
advanced
2:00remaining
Which command correctly creates a subscription to replicate from a publisher?

Choose the correct SQL command to create a subscription named sub1 connecting to a publisher at host=192.168.1.10 dbname=company for publication pub1.

ACREATE SUBSCRIPTION sub1 WITH CONNECTION 'host=192.168.1.10 dbname=company' PUBLICATION pub1;
BCREATE SUBSCRIPTION sub1 CONNECTION 'host=192.168.1.10 dbname=company' FOR PUBLICATION pub1;
CCREATE SUBSCRIPTION sub1 CONNECTION 'host=192.168.1.10 dbname=company' PUBLICATION pub1;
DCREATE SUBSCRIPTION sub1 CONNECTION 'host=192.168.1.10 dbname=company' TO PUBLICATION pub1;
Attempts:
2 left
💡 Hint

Check the exact syntax for the CREATE SUBSCRIPTION command in PostgreSQL.

optimization
advanced
2:00remaining
How to reduce replication lag in logical replication?

You notice replication lag between publisher and subscriber. Which approach helps reduce lag?

AReduce the <code>max_replication_slots</code> to 1
BIncrease the <code>wal_sender_timeout</code> to a higher value
CDisable the replication slot on the publisher
DUse synchronous_commit = 'remote_apply' on the publisher
Attempts:
2 left
💡 Hint

Consider how commit settings affect replication speed and confirmation.

🔧 Debug
expert
3:00remaining
Why does the subscription fail with error 'could not find replication origin'?

A subscription fails to start with the error: ERROR: could not find replication origin. What is the most likely cause?

AThe subscriber's replication slot was dropped or corrupted
BThe publication does not exist on the publisher
CThe connection string has wrong credentials
DThe subscriber database is missing the table being replicated
Attempts:
2 left
💡 Hint

Think about what replication origin means and what happens if it is missing.