Skip to content
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=logical at startup, and changing the setting required a restart. In PostgreSQL 19, wal_level remains a startup setting, but with replica configured, creating the first logical slot synchronously raises the effective level to logical without 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 with pgoutput. Because both databases were on the same instance, the slot was created manually and the subscription used create_slot = false to avoid hanging on CREATE SUBSCRIPTION.
  • effective_wal_level reports the current level. The new logical_decoding column in pg_control_checkpoint() and the output of pg_controldata also expose decoding state. A valid slot can keep logical decoding enabled even when inactive; pg_replication_slots helps 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.

Read Official Source

Related PostgreSQL Reference