FULL AI ANALYSIS

PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL

Generated Oct 3, 2026, 12:35:03 AM

Analysis summary

Replica failure occurs when the replica requests WAL segments that are no longer available on the primary or in archive — commonly caused by WAL removal due to retention settings, disk-space-triggered cleanup, or failed archiving while the replica was slow. pg_repack can produce large volumes of WAL, temporarily accelerating WAL recycling; if archive_command failed for some WALs and hot standby lagged, the required WAL bytes can be lost. Recovery requires a new base backup or restoring the missing WALs from archive; simply restarting streaming won't resurrect removed segments.

Possible causes

Archive_command failures (permissions or transient I/O errors) prevented missing WALs from being stored in archive during the heavy WAL generation by pg_repack.

90%

WAL segments required by replica were recycled by primary because wal_keep_size/wal_keep_segments and replication slot retention thresholds were exceeded.

75%

Disk pressure on primary triggered WAL cleanup even though replica had not consumed earlier segments (insufficient WAL retention configuration).

50%

Replication slot corruption or manual deletion after pg_repack causing slot metadata mismatch.

10%

Suggested fixes

1

Diagnostic step 1

Confirm which WAL segments are missing by inspecting primary's pg_wal and archive directory and checking replica's last WAL LSN in recovery logs; do not attempt to manipulate WAL files on disk without backups.

2

Diagnostic step 2

If missing WALs are irrecoverable, take a fresh base backup from primary (pg_basebackup) and reinitialize the replica; this is the safest recovery path when required WALs are gone.

3

Diagnostic step 3

Before future heavy WAL operations: ensure archive_command is reliable and monitored, increase wal_keep_size (or enable sufficient retention), and consider running pg_repack with chunking and lower maintenance_work_mem to spread WAL over a longer period.

4

Diagnostic step 4

Run pg_repack during a maintenance window with replica paused or with promoted standby available; consider using logical replication for schema changes that would otherwise cause large WAL churn.

5

Diagnostic step 5

If you require assistance preserving forensic WAL segments, consider engaging a DBA with access to archived WAL storage; escalate to specialist if archive integrity or hardware failure is suspected.