skip to content

In PEV2, what do the buffers and IO views reveal about a PostgreSQL plan node, and why can the IO view be unavailable?

level: middleimportance: should knowfreq 22%

answer

  1. each node's own blocks
  2. hit, read, dirtied, written
  3. temp blocks mean a spill
  4. times need a superuser setting

basics

~20 s

PEV2 subtracts children's counts to show each node's own shared, temp and local blocks hit, read, dirtied and written. Its IO view needs per-node I/O times, which PostgreSQL records only with track_io_timing on, and it is off by default.

solid answer

~50 s

With `BUFFERS`, which is automatic under `EXPLAIN ANALYZE` from PostgreSQL 18, each node reports blocks. **Shared** blocks are tables and indexes, **local** blocks are temporary tables, and **temp** blocks are sort and hash spill files. A hit means the block was already in shared buffers; a read was requested from the OS, possibly served from its page cache. The raw counts include all children and are totals across loops. PEV2 subtracts the children to give each node its own blocks, and shows them in the Diagram's buffers metric (with Shared, Temp and Local tabs), the Grid and the node detail. Temp blocks on a Sort or Hash mean a spill, and a hash with several batches gets its own hint. The IO metric needs read and write times, which exist only if `track_io_timing` was on during capture. It is off by default and superuser-settable, so PEV2 disables the IO metric and shows a hint.

code

sql · 10 lines
sql
-- needs superuser, or: GRANT SET ON PARAMETER track_io_timing TO report_reviewer;
SET track_io_timing = on;

EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
SELECT c.region, count(*) AS invoice_count
FROM invoices i
JOIN customers c ON c.id = i.customer_id
WHERE i.issued_on >= date '2026-09-01'
GROUP BY c.region
ORDER BY invoice_count DESC;

go deeper

for a junior

Recall the three kinds of block (shared, local, temp) and that hit means the block was already in cache. PEV2 shows each node's own share.

for a middle

Explain that raw counts include the children and are totals across loops, that PEV2 subtracts the children, and that I/O times need track_io_timing.

for a senior

Read the patterns: temp blocks mean a spill, reads with tiny I/O time mean the OS cache served them, dirtied blocks on a SELECT mean hint bits. Enable timing deliberately, aware of its overhead.

for a principal

Decide whether track_io_timing stays on fleet-wide after measuring its overhead, since plan reviews and the statistics views both depend on it.

## What BUFFERS records With `BUFFERS`, each node reports block counts in PostgreSQL's block size (8 kB by default) for three kinds of storage. `BUFFERS` is automatic under `EXPLAIN ANALYZE` from PostgreSQL 18, and must be requested explicitly on 16 and 17. | Kind | Holds | Counters | |---|---|---| | **shared** | regular tables and indexes, through shared buffers | hit, read, dirtied, written | | **local** | temporary tables and their indexes, private to the session | hit, read, dirtied, written | | **temp** | short-lived working files for sorts, hashes and Materialize nodes | read, written | A **hit** is a block found already in shared buffers. A **read** is a block PostgreSQL had to request from the operating system, and the kernel's page cache may still have served it rather than the disk. **Dirtied** counts blocks this query changed for the first time. **Written** counts dirty blocks this backend had to evict and write itself. Two properties of the raw counters matter when you read them. They are **totals across all loops**, not per-loop averages like time and rows. And a node's counters **include all of its children's**, so the root's line is the whole query's I/O. ## What PEV2 does with them PEV2 subtracts each child's counters from its parent's to get the node's **own** blocks, the same exclusive treatment it gives time and cost. It then offers several views: - the Diagram pane's **buffers** metric, with Shared, Temp and Local sub-tabs, drawing a bar per node scaled to the busiest node of that kind; - the per-node detail, with hit, read, dirtied and written figures; - block columns in the **Grid** tab; - planning buffers in the header, when the input includes the `Planning:` section. Patterns worth recognising: 1. **High shared read on one scan**: that node is pulling in data that was not in shared buffers. The cache may be cold, or the table may be bigger than the cache. 2. **Any temp read or written on a Sort, Hash or HashAggregate**: the operation did not fit in its memory budget and spilled to temporary files. PEV2 also flags a hash that needed more than one batch, and suggests `work_mem` or `hash_mem_multiplier`. 3. **Local blocks**: the query touched a temporary table. 4. **Dirtied blocks on a read-only query**: often the first read after a bulk load setting hint bits. **Written** blocks on one mean the backend had to evict dirty pages itself, a sign of cache pressure. ## The IO metric and track_io_timing Block counts say how much was read, not how long it took. Read and write **times** appear only if the server parameter `track_io_timing` was on when the plan was captured. It is **off by default**, because timing every I/O reads the clock repeatedly, and that costs something on some platforms; `pg_test_timing` measures how much. Only a superuser, or a role granted `SET` on the parameter, can turn it on for a session, and an administrator can turn it on server-wide. When the input has no I/O times, PEV2 disables the Diagram's **IO** metric and shows a hint to activate `track_io_timing`. With timings present, it shows read and write time per node and derives an average throughput from blocks and time. That is how you tell a node that read many blocks quickly, probably served from the operating system's cache, from one that waited on storage. ## Release notes that change the picture - **18**: `BUFFERS` comes with `ANALYZE` by default. - **17**: I/O timings are split into shared, local and temp, because 17 added local-block timings. PEV2 maps each timing to the matching block counts. - **16**: request `BUFFERS` explicitly; I/O times are reported for shared and local blocks combined, plus temp blocks. - In every release, text format prints only non-zero counters while JSON names each one, which is one reason to give PEV2 JSON. Some questions are not PEV2's to answer and belong to their own topics: what each counter means inside the buffer manager, how to size `work_mem` to stop a spill, and the server-wide views such as `pg_stat_io`. What PEV2 contributes is putting the per-node numbers side by side, so the node that did the I/O is obvious.

  • In PEV2, a Seq Scan shows a large shared read count but almost no I/O read time. What does that tell you?
    The blocks were not in shared buffers, so PostgreSQL asked the operating system for them, but the kernel's page cache served them almost instantly. The scan is moving a lot of data rather than waiting on storage, so the next question is why it reads so many blocks at all, not how fast the disks are.
  • Why can a parent node's own block count in PEV2 be near zero when its raw Buffers line is large?
    EXPLAIN's per-node counts include every child's. PEV2 subtracts the children to get the node's own blocks. A Hash Join that only probes an in-memory hash table owns very little I/O, while the scans beneath it own the reads. The large raw number was theirs.

  • A read in EXPLAIN's Buffers line always means a physical disk read
  • EXPLAIN's buffer counts are per-loop averages like time and rows
  • VERBOSE is what makes PEV2's IO metric available
  • Temp blocks on a Sort mean the query created a temporary table
  • The root node's Buffers line shows only the root's own I/O

Assumes PostgreSQL 18, where EXPLAIN ANALYZE includes BUFFERS automatically; on 16 and 17 BUFFERS must be requested, and separate local-block I/O timings exist only from 17.