From 5195f193bcd348f03c662da1a0ebaa3a6bbf16fb Mon Sep 17 00:00:00 2001 From: Pavan Krishna Rampalli Date: Tue, 1 Dec 2026 12:32:53 +0000 Subject: [PATCH v1] Exclude B_IO_WORKER from pg_stat_io pgstat_tracks_io_bktype() returned true for B_IO_WORKER, causing pg_stat_io to expose eight rows for backend_type = 'io worker' (including impossible combinations such as temp relation and WAL). Asynchronous I/O statistics are attributed to the submitting backend rather than to the IO worker process: IoWorkerMain() does not record pg_stat_io counters, and pgstat_tracks_backend_bktype() already returns false for B_IO_WORKER. Consequently, these pg_stat_io rows could never accumulate non-zero counts. Move B_IO_WORKER to the return-false group in pgstat_tracks_io_bktype() and update the expected output of the stats regression test. Reported-by: Wren Discussion: https://postgr.es/m/19953-1b7093dad1f8093f@postgresql.org --- src/backend/utils/activity/pgstat_io.c | 4 +++- src/test/regress/expected/stats.out | 10 +--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.c index cec5759..234cd9a 100644 --- a/src/backend/utils/activity/pgstat_io.c +++ b/src/backend/utils/activity/pgstat_io.c @@ -332,6 +332,8 @@ pgstat_io_snapshot_cb(void) * - Syslogger because it is not connected to shared memory * - Archiver because most relevant archiving IO is delegated to a * specialized command or module + * - IO worker because asynchronous IO statistics are attributed to the + * submitting backend rather than the worker * * Function returns true if BackendType participates in the cumulative stats * subsystem for IO and false if it does not. @@ -351,6 +353,7 @@ pgstat_tracks_io_bktype(BackendType bktype) case B_INVALID: case B_DEAD_END_BACKEND: case B_ARCHIVER: + case B_IO_WORKER: case B_LOGGER: return false; @@ -362,7 +365,6 @@ pgstat_tracks_io_bktype(BackendType bktype) case B_BG_WORKER: case B_BG_WRITER: case B_CHECKPOINTER: - case B_IO_WORKER: case B_SLOTSYNC_WORKER: case B_STANDALONE_BACKEND: case B_STARTUP: diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out index 0e54cf0..c10cb7e 100644 --- a/src/test/regress/expected/stats.out +++ b/src/test/regress/expected/stats.out @@ -60,14 +60,6 @@ datachecksums worker|relation|normal datachecksums worker|relation|vacuum datachecksums worker|wal|init datachecksums worker|wal|normal -io worker|relation|bulkread -io worker|relation|bulkwrite -io worker|relation|init -io worker|relation|normal -io worker|relation|vacuum -io worker|temp relation|normal -io worker|wal|init -io worker|wal|normal slotsync worker|relation|bulkread slotsync worker|relation|bulkwrite slotsync worker|relation|init @@ -105,7 +97,7 @@ walsummarizer|wal|init walsummarizer|wal|normal walwriter|wal|init walwriter|wal|normal -(89 rows) +(81 rows) \a -- List of registered statistics kinds. SELECT id, name, fixed_amount, -- 2.56.1.839.g22a8290db9-goog