PostgreSQL 16's pg_stat_io: Read the I/O Story Before Tuning shared_buffers
PostgreSQL 16 added pg_stat_io, a system view for inspecting I/O activity across backend types and object contexts. It gives operators a more structured view than inferring everything from a single database-wide counter. The useful question is not “which number is high?” but “which kind of process is doing what work, and is that expected for this workload?”
Start with a snapshot, run a representative workload, and take a second snapshot. Look at the change over time rather than totals accumulated since the last statistics reset. Compare read and write counts, relation versus temporary-file activity, and backend classes. A spike in temporary reads during a report may point toward sorts or hashes spilling to disk; it does not automatically prove that work_mem should be raised globally.
Be careful with units and interpretation. Counters describe operations, not business latency. A workload can issue many small reads that remain fast in cache, or a few large reads that dominate response time. Pair pg_stat_io with query plans, operating-system metrics, storage latency, and application-level timings. Resetting statistics for a before-and-after experiment can disturb other observers, so use a controlled test environment when possible.
The view is especially useful when comparing connection pools, batch jobs, autovacuum, and interactive traffic. If background maintenance is responsible for a change, tune maintenance behavior or scheduling instead of optimizing request queries blindly. If the same query is responsible, inspect its plan and buffer behavior next.
pg_stat_io is an observability tool, not an automatic tuning system. It narrows the investigation; it does not explain the root cause by itself.
See the PostgreSQL 16 release notes and the monitoring statistics documentation for the view’s columns and interpretation.