Diagnostic step 1
Create the missing index with CREATE INDEX CONCURRENTLY ON audit(events_id); monitor progress in pg_stat_progress_create_index.
Generated Oct 20, 2026, 9:41:02 AM
Create the missing index with CREATE INDEX CONCURRENTLY ON audit(events_id); monitor progress in pg_stat_progress_create_index.
If index build is too slow, build the index on a replica and promote or use logical copy: create new table with index, copy in batches, swap with minimal lock.
Switch DELETE to batched deletes: loop DELETE FROM events WHERE created_at < X LIMIT 10000; COMMIT between batches; monitor pg_stat_activity and lock waits.
Ensure no long-running transactions: inspect pg_stat_activity and terminate or coordinate clients keeping old snapshots.
After deletes, VACUUM ANALYZE the affected tables; if bloat is severe, plan a maintenance window for VACUUM FULL or pg_repack.