In low-traffic databases, replication slots can cause WAL bloat because the slot's restart_lsn lags behind, preventing WAL recycling. go-pq-cdc provides a table-based heartbeat mechanism to solve this.
When heartbeat.table.name is configured, the connector:
- Creates the heartbeat table automatically.
- Ensures a single row exists.
- Periodically runs an internal
UPDATE to generate small committed WAL records. - Auto-acknowledges these events internally (they are not forwarded to your listener).
Requirements for Heartbeat to work:
- The heartbeat table must be listed in
publication.tables. If it is not part of the publication, the change is filtered out before reaching the slot, and WAL will not advance. - The heartbeat table must have a
REPLICA IDENTITY of DEFAULT (if it has a primary key) or FULL. Using REPLICA IDENTITY NOTHING will prevent the UPDATE from being decoded, causing the slot to stay frozen and WAL to grow.
Best Practice: Always use a dedicated heartbeat table; never reuse a business table.