S
Supanote
Sign in Sign up

PostgreSQL Logical Replication & CDC WAL Settings

plain (sql) 13 hours ago · 26 lines · 6 views
1-- PostgreSQL Logical Replication & Change Data Capture (CDC) Setup
2
3-- Step 1: Ensure postgresql.conf settings are applied:
4-- wal_level = logical
5-- max_wal_senders = 10
6-- max_replication_slots = 10
7
8-- Step 2: On PRIMARY Publisher Database:
9CREATE PUBLICATION pub_core_events
10FOR TABLE users, notes, api_tokens;
12-- Step 3: On REPLICA Subscriber Database:
13CREATE SUBSCRIPTION sub_core_events
14CONNECTION 'host=primary.db.internal port=5432 dbname=production user=replicator password=secure_password'
15PUBLICATION pub_core_events
16WITH (copy_data = true, create_slot = true);
18-- Step 4: Monitor Replication Lag & Status:
19SELECT
20 subname,
21 pid,
22 received_lsn,
23 latest_end_lsn,
24 latest_end_time
25FROM pg_stat_subscription;

No replies yet

Every reply is a note. Start a discussion, ask a question, or attach a code snippet.

Share Note

Download SVG
Social Card Preview
Open on mobile
Point your phone camera to open this note directly

Report this note

Notification