]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix pg_stat_get_backend_wait_event() for aux processes
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 11 Feb 2026 16:50:57 +0000 (18:50 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 11 Feb 2026 16:50:57 +0000 (18:50 +0200)
The pg_stat_activity view shows information for aux processes, but the
pg_stat_get_backend_wait_event() and
pg_stat_get_backend_wait_event_type() functions did not. To fix, call
AuxiliaryPidGetProc(pid) if BackendPidGetProc(pid) returns NULL, like
we do in pg_stat_get_activity().

In version 17 and above, it's a little silly to use those functions
when we already have the ProcNumber at hand, but it was necessary
before v17 because the backend ID was different from ProcNumber. I
have other plans for wait_event_info on master, so it doesn't seem
worth applying a different fix on different versions now.

Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/c0320e04-6e85-4c49-80c5-27cfb3a58108@iki.fi
Backpatch-through: 14

src/backend/utils/adt/pgstatfuncs.c

index 73ca0bb0b7f2890c2367492300a95cedc984c928..b1df96e7b0b5ebe23cef99bc017a5661b9f03fa4 100644 (file)
@@ -824,8 +824,14 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
                wait_event_type = "<backend information not available>";
        else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
                wait_event_type = "<insufficient privilege>";
-       else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
-               wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
+       else
+       {
+               proc = BackendPidGetProc(beentry->st_procpid);
+               if (!proc)
+                       proc = AuxiliaryPidGetProc(beentry->st_procpid);
+               if (proc)
+                       wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
+       }
 
        if (!wait_event_type)
                PG_RETURN_NULL();
@@ -845,8 +851,14 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
                wait_event = "<backend information not available>";
        else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
                wait_event = "<insufficient privilege>";
-       else if ((proc = BackendPidGetProc(beentry->st_procpid)) != NULL)
-               wait_event = pgstat_get_wait_event(proc->wait_event_info);
+       else
+       {
+               proc = BackendPidGetProc(beentry->st_procpid);
+               if (!proc)
+                       proc = AuxiliaryPidGetProc(beentry->st_procpid);
+               if (proc)
+                       wait_event = pgstat_get_wait_event(proc->wait_event_info);
+       }
 
        if (!wait_event)
                PG_RETURN_NULL();