seniorPostgreSQL Performance / MVCC OperationsPro answerTested in a controlled lab, summarised

A query became slow after a deploy. Show a safe production triage that separates estimate error, execution or I/O cost, lock waits, and a cleanup horizon. Then explain what VACUUM can reclaim, how freezing protects availability, and how you would prove physical bloat.

This prompt is deliberately oversized: it asks for a triage sequence and then for the vacuum mechanics behind one of its branches. Trying to cover both at once produces a shapeless answer, so the strongest response takes the triage first, says clearly which branch it is parking, and offers to continue. Within the triage itself, the scored decision is the order. Reaching for an index or an autovacuum setting before establishing causality is the common failure, and it is expensive because both are changes to a system nobody has finished diagnosing. There is also a safety point that has to be said out loud, because the obvious diagnostic tool executes the statement it is measuring. This page covers the ordering, the safety, and the mechanics behind the branch.

What the interviewer is scoring

Weak answer: “add an index,” “autovacuum is on,” cancels an unknown backend, drops a required slot, or treats the dead-tuple estimate as a measurement.

In short: Read the plan without guessing from one field. Prove a horizon holder before acting, and distinguish reusable space, file shrink, XID safety, exact inspection, and planner statistics.

ProFrom a real interview loop

The spoken answer and the reasoning behind it

The question, the intro, what the interviewer is scoring, the reasoning outline, what you would verify and the follow-up probes are all open above. Pro unlocks the spoken answer to A query became slow after a deploy. Show a safe production triage that separates estimate error, execution or I/O cost, lock waits, and a cleanup horizon. Then explain what VACUUM can reclaim, how freezing protects availability, and how you would prove physical bloat., the reasoning behind it, and the verification that backs it.
  • The full 90-second answer, written first person, the way you would actually say it
  • How I reason through it: the mechanism, the decision points, and where the claim stops
  • Verification steps with a written summary of what a controlled lab run showed, labelled as a summary rather than a transcript.
  • Worked responses to the 3 follow-up probes listed above, plus the traps that lose the point

Card required. Cancel before day 7 and you are not charged.

Compare plans

How to reason through it

  • Preserve query text/parameters, plan-affecting settings, baseline, and safety constraints; remember that EXPLAIN ANALYZE executes the statement.
  • Find the first material estimated-versus-actual row divergence; separately inspect loops, time, buffers, temporary I/O, spills, and wait events.
  • Prove the specific cleanup horizon: a backend's snapshot, a replication slot position, or a prepared transaction; use a holder-specific and owner-approved remediation.
  • Explain that MVCC updates/deletes leave old row versions; ordinary VACUUM removes versions no snapshot needs and usually makes space reusable inside the relation rather than shrinking its file.
  • Explain that VACUUM FULL rewrites and shrinks a relation under ACCESS EXCLUSIVE, while freezing protects old row versions from 32-bit ID wraparound and is an availability safeguard.
  • Choose the exact bloat measurement only when a full-relation read is acceptable; otherwise use the approximate form and say which results are approximate.
  • Keep cumulative activity counters separate from planner statistics: a per-table counter reset clears activity, while ANALYZE refreshes planner statistics.

What I would verify

  • Capture the plan-affecting settings and the parameters before changing anything, so there is a baseline to compare against.
  • Use a plan-only explain first when executing the statement would not be safe.
  • Locate the first node where estimated and actual rows separate, reading upward from the leaves.
  • Name the specific horizon holder before proposing any vacuum change, and check whether you are allowed to remove it.
  • Separate a dead-tuple estimate from a physical measurement before calling anything bloat.

Follow-ups they push on

  • Why not just run EXPLAIN ANALYZE straight away?
  • Dead tuples are climbing and autovacuum is running. What is your next move?
  • How would you prove the bloat rather than assert it?

The probes are open. Pro carries the spoken answer, the reasoning behind it, and the verification steps, including a worked response to each of these.

Concepts tested

EXPLAIN safetycardinality estimationbuffers and spillwait eventsMVCC dead versionsvacuum horizonspace reuse vs file shrinkXID freezingexact vs approximate bloatcumulative vs planner statistics

Learn it, run it, then say it

Three steps, in order. Nothing here is a detour.

Questions that go with this one