Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mastering Postgres Replication Slots: Preventin...

Mastering Postgres Replication Slots: Preventing WAL Bloat and Other Production Issues (JavaZone 2025)

With logical replication, Postgres provides a powerful interface for extracting data change events from the transaction log, as for instance utilized by Debezium. Replication slots are Postgres' mechanism for making sure that any segments of the write-ahead log (WAL) of the database are kept around until they have been processed by registered replication consumers.

But there be dragons: When not being careful, a replication slot may cause unduly large amounts of WAL segments to be retained by the database. Join us for this lightning talk to learn about best practices helping to prevent this and other issues, discussing aspects like heartbeats, replication slot failover, monitoring, the management of Postgres publications, and more. While this is primarily based on experience gained from using replication slots via Debezium, the principles are generally applicable and are worth considering also when using other change data capture (CDC) tools for Postgres based on logical replication.

Avatar for Gunnar Morling

Gunnar Morling

September 03, 2025
Tweet

More Decks by Gunnar Morling

Other Decks in Programming

Transcript

  1. Gunnar Morling @gunnarmorling.dev Mastering Postgres Replication Slots: Preventing WAL Bloat

    and Other Production Issues Megan Coughlin https://flic.kr/p/iggCAx (CC BY-ND 2.0) 🦋
  2. #PostgresReplicationSlots · @gunnarmorling.dev • Technologist at Confluent • Former project

    lead of Debezium • kcctl 🧸, JfrUnit, ModiTect, MapStruct • One Billion Row Challenge 1⃣🐝🏎 • Java Champion Gunnar Morling
  3. #PostgresReplicationSlots · @gunnarmorling.dev Choosing a Logical Decoding Plug-In Use pgoutput

    • Efficient binary representation • Available OOTB on Postgres 10+ • Fine-grained control over contents via publications
  4. #PostgresReplicationSlots · @gunnarmorling.dev Examining pgoutput Data Change Events Use pgoutput-cli

    • Can’t use SQL interface (pg_logical_slot_peek_changes() etc.)
  5. #PostgresReplicationSlots · @gunnarmorling.dev Define Maximum Retained WAL Size • Rather

    cut loose consumers than kill the DB • Since Postgres 13:
  6. #PostgresReplicationSlots · @gunnarmorling.dev Learning More… …at JavaZone 📝 “Ins and

    Outs of The Outbox Pattern” 🗓 Thursday 10:20 AM 📍 Room VII