Parameter · Resource Usage / Memory
logical_decoding_work_mem
Sets the maximum memory to be used for logical decoding. This much memory can be used by each internal reorder buffer before spilling to disk.
- Default:
64MB - Type: integer (kB)
- Range: 64kB … max (2147483647)
- Applies: Session (any user)
In plain words
Logical replication reads WAL and reassembles each transaction's changes in memory until the transaction commits. If the in-progress changes exceed this limit, the largest transaction is either written to spill files under pg_replslot/ or, if the subscriber accepts streaming, sent ahead in chunks.
For DBAs and operators
One buffer per decoding walsender (or pg_logical_slot_get_changes() call), so it is safe to set well above work_mem: 256 MB–1 GB is common for systems with large batch transactions. Since PostgreSQL 14, a subscription with streaming = on (or parallel, PostgreSQL 16+; the default for new subscriptions is parallel since PostgreSQL 18) receives large in-progress transactions instead of the publisher spilling them.
Observe
SELECT slot_name, spill_txns, spill_count,
pg_size_pretty(spill_bytes) AS spilled,
stream_txns, pg_size_pretty(stream_bytes) AS streamed
FROM pg_stat_replication_slots;Spilling writes xid-*.spill files in pg_replslot/<slot>/; large values there plus replication lag point at this setting. Many subtransactions (e.g. PL/pgSQL exception blocks in a big batch) make decoding much more memory- and CPU-hungry. The limit counts only change data, not the reorder buffer's overhead, so actual memory can exceed it somewhat.
How to change it
Any user can change it for their session with SET.
See it in context
Logical replication Replication slots WAL sender Local (per-backend) memory Logical replication workers Logical decoding and ReorderBuffer