select * from depesz;·· 1d agoFeatured
Testing PostgreSQL 19’s Slot-Driven Logical Decoding
Missed in PostgreSQL 19 : Toggle logical decoding dynamically based on logical slot presence.
Key Takeaway
Tests show PostgreSQL 19 enables logical decoding without a restart when the first logical slot is created with wal_level=replica. The checkpointer reverts to replica asynchronously after the last slot is dropped or invalidated. effective_wal_level shows the current level.
Why It Matters
Enabling logical decoding for on demand CDC no longer requires a restart, but leftover valid logical slots can keep the extra WAL overhead in place.
Technical Breakdown · Distilled from the original source
How the WAL level switches
- Through PostgreSQL 18, logical decoding required
wal_level=logicalat startup, and changing the setting required a restart. In PostgreSQL 19,wal_levelremains a startup setting, but withreplicaconfigured, creating the first logical slot synchronously raises the effective level tologicalwithout changing the configuration. - After the last logical slot is dropped or invalidated, the checkpointer disables logical decoding asynchronously. This avoids a race between activation and deactivation at the end of recovery and reduces toggling when a single slot is repeatedly created and dropped. A busy checkpointer can delay the switch back.
- The effective level can change within a transaction until an XID is assigned, after which it stays fixed for the rest of the transaction to keep WAL logging consistent.
Testing and operational visibility
- The author decoded inserts and updates with
test_decoding, then verified initial synchronization and replication of a subsequent insert withpgoutput. Because both databases were on the same instance, the slot was created manually and the subscription usedcreate_slot = falseto avoid hanging onCREATE SUBSCRIPTION. effective_wal_levelreports the current level. The newlogical_decodingcolumn inpg_control_checkpoint()and the output ofpg_controldataalso expose decoding state. A valid slot can keep logical decoding enabled even when inactive;pg_replication_slotshelps identify leftover slots.
Source: select * from depesz;· depesz.com
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.