Skip to content
RED SAGSkills
hardDatabase Administrator interview question

A critical 1 TB PostgreSQL table is 60 percent bloat and queries are slowing. How do you fix it without downtime and stop it coming back?

What the interviewer wants to hear

  • Measure bloat with pgstattuple or estimates, and find the cause
  • Remove what blocks vacuum: long transactions, abandoned slots, prepared transactions, hot_standby_feedback
  • Rebuild online with pg_repack, or REINDEX CONCURRENTLY for indexes, after checking disk space
  • Tune per-table autovacuum: lower scale factor, higher cost limit
  • Consider fillfactor for HOT updates or partitioning for retention

Model answer

First I would confirm the bloat with pgstattuple or a reliable estimate, and separate table bloat from index bloat. Then I would find why vacuum fell behind: very long or idle-in-transaction sessions, an abandoned replication slot, old prepared transactions, or hot_standby_feedback from a replica running long reports. Fixing that comes before any rebuild, otherwise the bloat returns. To recover space online I would use pg_repack, which builds a new copy and swaps it in with brief locks, after checking there is enough free disk and replica lag headroom; for indexes REINDEX CONCURRENTLY is enough. To prevent it, I would set per-table autovacuum settings with a much lower scale factor and higher cost limit, lower fillfactor if updates are frequent so HOT updates work, add timeouts for idle transactions, and alert on dead tuple counts.

Can you answer it under time pressure?

Take a timed hard round and get scored on every answer.

Start mock interview

More hard Database Administrator questions