PostgreSQL replication lag and slots on your iPhone
HeapDeck shows how far each standby is behind and which phase of WAL shipping holds it up. It also lists your slots with the WAL each keeps on disk, including an inactive slot that a removed replica or CDC connector left behind.
Updated · Vladimir Chemeris, the developer of HeapDeck
Lag, broken down by phase
On a primary, Replication lists the standbys from pg_stat_replication, the most lagging first: application_name, streaming or catchup, the client address, sync state, replay lag and, if the server reports it, the lag in bytes. Lag turns amber at 1 second and red at 30.
Open a standby and HeapDeck lays out the WAL positions, Sent LSN, Written LSN, Flushed LSN and Replayed LSN, together with write, flush and replay lag. A section called What the lag means reads them for you:
- Replication is catching up before replay: the bottleneck sits between the primary and the standby’s disk, so check the network and the standby’s I/O.
- WAL has arrived but replay is behind: the standby has the data and replay falls behind. Look for a long query on the standby or slow I/O.
- No measured replication gap, or Lag cause is unknown if the server hides some of the phases from your role.
Connected to a standby, the same screen shows its own recovery position: last WAL received, last WAL replayed, replay lag and the WAL received but not yet replayed.
The slot that fills your disk
A replication slot makes the primary keep each WAL segment its consumer has not confirmed. You want that while the consumer is alive. Once the consumer is gone, say a decommissioned replica or a CDC connector someone switched off, the slot keeps WAL forever, and the disk fills up without a single error until it is full.
You can see retained WAL per slot with:
SELECT slot_name, slot_type, active, wal_status,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal
FROM pg_replication_slots
ORDER BY pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) DESC NULLS LAST;
HeapDeck lists slots inactive first, then by retained WAL, each with physical or logical, retaining 84 GB of WAL, and on PostgreSQL 17 and later the time since it was last active. If any slot is inactive, a red banner says so: An inactive slot makes PostgreSQL keep WAL forever. This is the most common cause of a disk filling up silently. The Replication tile on Health turns amber for an inactive slot, so you see it before the disk alert.
Slot details add wal_status (reserved, extended, unreserved or lost), safe WAL remaining, the active pid, restart and confirmed flush LSN, and for logical slots the plugin and database.
Dropping a slot
If the consumer is not coming back, drop the slot. In HeapDeck you swipe the slot or tap Drop slot in its details. The sheet shows the WAL it holds and warns that you would have to rebuild a replica that depends on it; the button stays disabled until you type the slot name. HeapDeck then runs pg_drop_replication_slot() and reads pg_replication_slots again to confirm the slot is gone. PostgreSQL refuses to drop a slot that is in use, and HeapDeck shows that refusal word for word.
Dropping slots is part of HeapDeck Pro. Watching lag and slots is free for one saved server.
Slots, max_slot_wal_keep_size and how to decide that a slot is safe to drop get a full post: an inactive replication slot is filling your disk.
Questions
How do I check replication lag in Postgres?
On the primary, read write_lag, flush_lag and replay_lag in pg_stat_replication. A gap in write_lag points at the network or the standby's disk, and a gap only in replay_lag points at replay on the standby.
Is it safe to drop an inactive replication slot?
Yes, if its consumer isn't coming back. PostgreSQL releases the WAL at the next checkpoint. If the consumer returns later it can't resume, so a replica needs a rebuild and a CDC pipeline needs a fresh snapshot.