seniorData platformPro answerTested in a controlled lab, with the output captured

n_live_tup and n_dead_tup are estimates. If I need the real number of tuples in a table, what do you reach for?

Ask what the number is for. To count the rows visible to a query right now, run SELECT count(*). It is exact for your snapshot and costs a scan. To count dead versions and free space, count(*) cannot help. Use the pgstattuple extension. n_live_tup, n_dead_tup and pg_class.reltuples are estimates and cannot answer either question exactly. This page shows how to separate the two meanings and how to choose between count(*), pgstattuple and pgstattuple_approx.

What the interviewer is scoring

Separate exact live rows from physical inspection. Name pgstattuple_approx as the cheaper option. State what a full heap scan costs.

In short: They're checking that you know the stats-view counters and the catalog row estimate are estimates, and that exact physical truth, plus the dead-tuple and free-space breakdown, comes from the pgstattuple extension.

ProFrom a real interview loop

The spoken answer, backed by captured output

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 “n_live_tup and n_dead_tup are estimates. If I need the real number of tuples in a table, what do you reach for?”, 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
  • Why: the mechanism, the decision points, and where the claim stops
  • Verification steps with output captured verbatim from a controlled PostgreSQL lab run.
  • Worked responses to the 3 follow-up probes listed above, plus the traps that lose the point
Get instant access — 7-Day Pass, $12

One-time payment. Does not auto-renew.

Compare plans

How to reason through it

  • Split the question first: exact visible rows is one thing, physical tuple and space accounting is another.
  • Say plainly that the catalog row estimate and the live/dead counters are estimates maintained by ANALYZE and autovacuum.
  • Reach for the pgstattuple extension for tuple count, dead tuple count and free space. It scans the whole table and applies its own visibility test, so its live count can differ slightly from count(*) while other transactions are running.
  • Offer pgstattuple_approx when a full scan is too expensive; it leans on the visibility map.
  • Note that count(*) gives exact live rows but no dead or free-space breakdown, and still costs a scan.

What I would verify

  • Decide what the number is for; a rebuild decision and a dashboard justify different instruments.
  • Compare the estimate against the measurement, because disagreement between them is itself a finding.
  • Check how much of the table is all-visible before assuming the approximate tool will be cheap.
  • Label approximate results as approximate wherever they are reported.

Follow-ups they push on

  • Why is the catalog row estimate sometimes exactly right?
  • The dead-tuple count is huge but pgstattuple says there are almost none. What happened?
  • When would you not run pgstattuple at all?

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

pgstattuplereltuples estimateBloat measurement

Learn it, run it, then say it

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

Questions that go with this one