Re: RFC: Allow EXPLAIN to Output Page Fault Information
Re: RFC: Allow EXPLAIN to Output Page Fault Information
От:
vellaipandiyan sm <vellaipandiyan.sm@gmail.com>
Дата:
Hello hackers,
I reviewed the EXPLAIN storage I/O patch and the overall direction seems useful, especially for distinguishing shared-buffer hits from actual storage reads during query analysis.
One concern that stood out to me from the later discussion is the interaction with asynchronous I/O and worker-based I/O accounting.
Since the patch currently relies on per-process getrusage() statistics, it seems possible that the reported values could become partial or misleading once I/O is performed outside the backend process context. In particular, worker-based AIO could undercount storage reads/writes while still returning non-zero values, which may make the output appear more accurate than it actually is.
I also wonder whether this should affect the semantics/documentation of the feature itself — i.e. whether the reported numbers should be described more explicitly as “backend-observed synchronous storage I/O” rather than total query I/O.
That said, the examples showing differences between OS cache hits and actual storage reads were quite compelling, especially for query performance debugging.
Thanks for working on the patch.
Regards,
Vellaipandiyan
I reviewed the EXPLAIN storage I/O patch and the overall direction seems useful, especially for distinguishing shared-buffer hits from actual storage reads during query analysis.
One concern that stood out to me from the later discussion is the interaction with asynchronous I/O and worker-based I/O accounting.
Since the patch currently relies on per-process getrusage() statistics, it seems possible that the reported values could become partial or misleading once I/O is performed outside the backend process context. In particular, worker-based AIO could undercount storage reads/writes while still returning non-zero values, which may make the output appear more accurate than it actually is.
I also wonder whether this should affect the semantics/documentation of the feature itself — i.e. whether the reported numbers should be described more explicitly as “backend-observed synchronous storage I/O” rather than total query I/O.
That said, the examples showing differences between OS cache hits and actual storage reads were quite compelling, especially for query performance debugging.
Thanks for working on the patch.
Regards,
Vellaipandiyan
On Thu, May 21, 2026 at 11:07 AM torikoshia <torikoshia@oss.nttdata.com> wrote:
Hi,
When reading the output of EXPLAIN (ANALYZE) to diagnose slow queries
for our customers, I often want to know how many page faults occurred,
especially major page faults, which involve disk access.
Currently, the BUFFERS option in EXPLAIN provides information on whether
a page was found in the shared buffers, but it doesn't provide insight
into whether the page was found in the OS cache or not and disk I/O
occurred.
Since page faults especially major one impact performance compared to
shared buffer and OS cache hits, it would be helpful to track these
events.
I have attached a PoC patch that modifies EXPLAIN to include page fault
information during both the planning and execution phases of a query.
The output would look like this:
=# EXPLAIN (ANALYZE, PAGEFAULTS)
SELECT * FROM pgbench_branches b
JOIN pgbench_accounts a ON b.bid = a.bid ORDER BY a.aid;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.58..335386.98 rows=4999917 width=197) (actual
time=3.785..5590.294 rows=5000000 loops=1)
... (omitted)
Planning:
Buffers: shared hit=50 read=48 dirtied=4 written=2
Page Faults: minor=30 major=19 <-ADDED
Planning Time: 22.080 ms
Execution:
Page Faults: minor=49 major=5 <-ADDED
Execution Time: 5794.356 ms
The patch has not yet added this functionality to auto_explain, but I
believe this feature would be more useful in auto_explain than in the
EXPLAIN command itself. I plan to add it to auto_explain if there's
interest in including page fault information in EXPLAIN.
While GUCs like log_statement_stats allow logging of getrusage(2)
information, including page faults, always enabling this can lead to
excessive log output. It would be better to log this data only when
queries are slow. Therefore, adding this feature to auto_explain seems
like a good solution.
The patch introduces a new option, PAGEFAULTS, but it may be more
appropriate to include the page fault information in another option,
such as SUMMARY, especially if there are other useful resources that can
be obtained from getrusage(2).
The patch cannot be applied to Windows because getrusage() in PostgreSQL
ported for Windows currently only tracks CPU times. I'm not sure if
information on major and minor page faults is accessible on Windows, but
it might be acceptable to treat it similarly to log_statement_stats and
exclude it from Windows support.
I also tried to add page faults information for each plan node, similar
to the BUFFERS option, but I decided against this approach due to the
performance impact. The frequent calls to getrusage(2), i.e. each time
getting one row, created significant overhead.
Any feedback would be greatly appreciated.
--
Regards,
--
Atsushi Torikoshi
Seconded from NTT DATA GROUP CORPORATION to SRA OSS K.K.
Re: RFC: Allow EXPLAIN to Output Page Fault Information
Thanks for the review! On Thu, May 21, 2026 at 2:38 PM vellaipandiyan sm wrote: > > Hello hackers, > > I reviewed the EXPLAIN storage I/O patch and the overall direction seems useful, especially for distinguishing shared-buffer hits from actual storage reads during query analysis. > > One concern that stood out to me from the later discussion is the interaction with asynchronous I/O and worker-based I/O accounting. > > Since the patch currently relies on per-process getrusage() statistics, it seems possible that the reported values could become partial or misleading once I/O is performed outside the backend process context. In particular, worker-based AIO could undercount storage reads/writes while still returning non-zero values, which may make the output appear more accurate than it actually is. Yeah, to avoid reporting the misleadingly underestimated values, no output is shown when worker-based AIO is used, as described in the docs: + ..Also, when + is set to worker, no output + will be shown, as I/O handled by asynchronous workers cannot be measured + accurately. > I also wonder whether this should affect the semantics/documentation of the feature itself — i.e. whether the reported numbers should be described more explicitly as “backend-observed synchronous storage I/O” rather than total query I/O. Updated the patch to clarify that the reported values include not only the backend process executing the query, but also any parallel query worker processes involved in the query. -- Regards, Atsushi Torikoshi
Re: RFC: Allow EXPLAIN to Output Page Fault Information
От:
Jelte Fennema-Nio <postgres@jeltef.nl>
Дата:
On Fri, 22 May 2026 at 18:07, Atsushi Torikoshi wrote: > Updated the patch to clarify that the reported values include not only > the backend process executing the query, but also any parallel query > worker processes involved in the query. For PG19 Tomas added an IO option to EXPLAIN. I think it would be better to have the Storage IO tracking be enabled by the IO option, rather than the BUFFERS option.
Re: RFC: Allow EXPLAIN to Output Page Fault Information
От:
Atsushi Torikoshi <torikoshia.tech@gmail.com>
Дата:
On Sun, May 24, 2026 at 6:50 PM Jelte Fennema-Nio wrote: > > On Fri, 22 May 2026 at 18:07, Atsushi Torikoshi > wrote: > > Updated the patch to clarify that the reported values include not only > > the backend process executing the query, but also any parallel query > > worker processes involved in the query. > > For PG19 Tomas added an IO option to EXPLAIN. I think it would be > better to have the Storage IO tracking be enabled by the IO option, > rather than the BUFFERS option. Thank you for pointing that out. I agree that having this under the IO option seems more intuitive. One thing I am slightly concerned about, though, is that according to the documentation, the IO option reports only I/O performed by scan nodes: > Include information on I/O performed by scan nodes providing such information. In contrast, the information produced by this patch is based on getrusage(), so it includes all Storage I/O performed by the backend and parallel workers, not just scan nodes. For example, it would also include temporary file I/O generated by operations such as sorts that spill to disk when they exceed work_mem. I suppose this could be clarified in the documentation, but I would be interested to hear if anyone has concerns or objections about that approach. -- Regards, Atsushi Torikoshi
Re: RFC: Allow EXPLAIN to Output Page Fault Information
От:
Lukas Fittl <lukas@fittl.com>
Дата:
On Fri, May 22, 2026 at 9:07 AM Atsushi Torikoshi wrote: > > Thanks for the review! > > On Thu, May 21, 2026 at 2:38 PM vellaipandiyan sm > wrote: > > > > Hello hackers, > > > > I reviewed the EXPLAIN storage I/O patch and the overall direction seems useful, especially for distinguishing shared-buffer hits from actual storage reads during query analysis. > > > > One concern that stood out to me from the later discussion is the interaction with asynchronous I/O and worker-based I/O accounting. > > > > Since the patch currently relies on per-process getrusage() statistics, it seems possible that the reported values could become partial or misleading once I/O is performed outside the backend process context. In particular, worker-based AIO could undercount storage reads/writes while still returning non-zero values, which may make the output appear more accurate than it actually is. > > Yeah, to avoid reporting the misleadingly underestimated values, no > output is shown when worker-based AIO is used, as described in the > docs: I think having something like this patch proposes would be extremely valuable, but: Do we even have a path forward here if this simply won't work with I/O workers? This was discussed before on this thread, but if anything it seems to me the situation has become more clear that I/O workers are going to be used for the majority of Postgres 19+ installations. At least for my part, I've seen both managed providers only offering I/O workers (e.g. AWS RDS/Aurora), as well as challenges in container environments where io_uring is not enabled. Maybe we should try to figure out what would be needed to do better I/O tracking on the Linux side in a way that is compatible with I/O workers? e.g. I assume rusage is too expensive to run on individual I/Os that the workers process (so its not just a communication problem) -- but would be good to benchmark. Thanks, Lukas -- Lukas Fittl
Re: RFC: Allow EXPLAIN to Output Page Fault Information
От:
Atsushi Torikoshi <torikoshia.tech@gmail.com>
Дата:
On Tue, May 26, 2026 at 3:44 AM Lukas Fittl wrote: Thanks for your comment! > Maybe we should try to figure out what would be needed to do better > I/O tracking on the Linux side in a way that is compatible with I/O > workers? That may well be true. Unfortunately, I do not currently have a good idea of how to achieve this in a way that works with I/O workers. I'll keep thinking about whether there might be another approach. > e.g. I assume rusage is too expensive to run on individual I/Os that > the workers process (so its not just a communication problem) -- but > would be good to benchmark. Yes, I suspect that would be the case. Although this is somewhat different from the current discussion, I once experimented with an implementation that called getrusage() for each plan node, and the overhead was high enough that it was not practically usable. [1] I agree that many users will choose, or be required to choose, io_method = worker. However, there are also users who will continue to use sync or choose io_uring, so I do not think providing I/O statistics for those users would be without value. In particular, from a performance perspective, io_uring seems likely to be the preferred option in the long run. In high-performance on-premises environments, for example, it would not be surprising to see users selecting io_uring. Those users would also be among those most interested in understanding how much I/O is being generated against storage, which is the motivation behind this proposal. On Sat, May 30, 2026 at 6:45 PM Ilmar Y wrote: Thanks for your review! > The patch applies cleanly on current master at > db5ed03217b9c238703df8b4b286115d6e940488, but git am warned about trailing > whitespace. git diff --check origin/master...HEAD reports: > src/test/modules/test_misc/t/011_explain_storage_io.pl:47: trailing whitespace > src/test/modules/test_misc/t/011_explain_storage_io.pl:55: trailing whitespace > src/test/modules/test_misc/t/011_explain_storage_io.pl:61: trailing whitespace I'll fix it. > A second thing I noticed is that, with io_method=sync, structured EXPLAIN > output can show an Execution Storage I/O section even when ANALYZE is not > used. We are currently considering moving this functionality to a new IO option that, unlike BUFFERS, would require ANALYZE to be specified.[2] [1] https://www.postgresql.org/message-id/CAGXjcj%3DhnEZCCDDMRv06EQnDcv0mRe6%2BPh1gv8%3DHb7NEc51y5A%40mail.gmail.com [2] https://www.postgresql.org/message-id/CAM6-o%3DBL59LgruKXm3DCjzFzvr7TTJPtryEPj51YeGMFrWO0EQ%40mail.gmail.com --- Regards, Atsushi Torikoshi