S
Supanote
Sign in Sign up

PostgreSQL Logical Replication & CDC WAL Settings

plain (sql) 1 month ago · 26 lines · 231 views
Verified Blueprint PostgreSQL

Optimized postgresql.conf and publication/subscription SQL statements for change data capture and replication.

Quick Fetch
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.

Related PostgreSQL & Database, Cache & SQL Blueprints

Production-ready configurations and diagnostics from the verified Supanote library.

All Database, Cache & SQL →
Interactive Developer Workbench: .env, Log & API Key Secret Scanner

Detect and redact leaked AWS keys, JWTs, database URIs, private keys, and Bearer tokens before sharing.

Open Secret Scanner →

Share Note

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

Report this note

Notification