Interview Q&A / PostgreSQL

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What does EXPLAIN (ANALYZE, BUFFERS) add and what do shared hit and read mean?

SHORT ANSWER

BUFFERS reports how many 8 kB pages each plan node touched. shared hit means the page was already in PostgreSQL's cache, shared read means it came from the operating system or disk. It shows I/O cost that timing alone hides.

Explain it simply

Timing tells you a query took 400 ms. It does not say why. BUFFERS says how much data it touched. Think of two students who both took an hour on an exam: one had every book on the desk (cache hits), the other walked to the library for each fact (reads).

Each buffer is one 8 kB page. shared hit=500 means 500 pages found in shared_buffers. shared read=9000 means 9000 pages had to be fetched, which is slow on a cold cache.

Example

sql
EXPLAIN (ANALYZE, BUFFERS)
SELECT count(*) FROM orders WHERE created_at > now() - interval '7 days';

-- Seq Scan on orders (actual time=0.02..310.5 rows=52000 loops=1)
--   Buffers: shared hit=120 read=18450
-- Planning Time: 0.2 ms
-- Execution Time: 312.9 ms

Run it twice. If the second run shows hits instead of reads and runs much faster, the first run was slow because of a cold cache, not a bad plan. Other fields: dirtied and written appear when a query modifies pages.

What to say in the interview

"BUFFERS shows page counts per node: shared hit is cache, shared read is I/O. I compare runs to separate a cold cache from a bad plan, and I look for nodes reading far more pages than rows they return."

Common mistakes

  • Judging a query from one cold-cache run.

#postgresql#explain#performance

Related questions

Practise more PostgreSQL questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open PostgreSQL quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.