This article addresses PostgreSQL replication lag caused by stalled logical replication slots during partial database migrations. It explains how heartbeat tables force the advancement of the Log Sequence Number (LSN) in the WAL stream, preventing disk exhaustion and migration stalls when specific tables experience low write activity.
Key points
Stalled replication slots occur when CDC captures only a subset of tables, preventing the LSN from advancing during periods of low activity on those specific tables.
PostgreSQL retains all WAL segments until every active replication slot confirms receipt, leading to disk space exhaustion during migration stalls.
Heartbeat tables mitigate this by injecting periodic dummy updates, ensuring the replication slot consistently advances despite low activity in the replicated tables.
Monitoring WAL size and replication slot status is essential for detecting early signs of CDC pipeline stalls.