I'd like to know how many pages (table + index, if any) are read from disk (and not from cache) when running a single Postgres query. Even better, if there is any way to extract this info from an EXPLAIN ANALYZE.
How many disk pages are read by a query in Postgres?
1.2k views Asked by Settembre Nero At
2
There are 2 answers
0
On
There is an extension that is supposed to separate true disk reads from FS cache reads, but it appears to only give data in aggregate, like pg_stat_statements does, and not in individual executions like EXPLAIN (ANALYZE, BUFFERS) does.
You can also use set log_executor_stats TO on;
, perhaps combined with set client_min_messages TO log;
to get top-level actual disk reads for each execution. The user experience here is pretty gross, though.
That information is available when you add the
buffers
option:explain (analyze, buffers) select ...
e.g.
You can see that a total of 412 pages (=blocks) were needed. 5 of them had to be fetched from the file system ("read=5") - those 5 were needed because of the Index Scan on
employees_pkey