Postgres queries that used to take 5 ms now take 800 ms with the same plan shape; the table hasn't grown much.

AdvancedTroubleshootingLatency
Answer

Likely causes → Table and index bloat from dead tuples because autovacuum can't keep up or is blocked by a long-running transaction (or an abandoned replication slot) holding back xmin. Stale statistics can also flip row estimates.

Diagnose →

SELECT relname, n_live_tup, n_dead_tup, last_autovacuum FROM pg_stat_user_tables ORDER BY n_dead_tup DESC LIMIT 5;
SELECT pid, now()-xact_start AS age, state, query FROM pg_stat_activity ORDER BY xact_start NULLS LAST LIMIT 5;
SELECT slot_name, active FROM pg_replication_slots;

Fix → Kill the long transaction or drop the dead slot, then VACUUM (VERBOSE, ANALYZE) orders;. Use pg_repack for heavy bloat without long locks.

Prevent → Tune per-table autovacuum thresholds for hot tables, set idle_in_transaction_session_timeout, and alert on oldest transaction age and dead tuple ratio.

All Real-World Interview questions Roadmap: Interview readiness

More on Latency