Fix pg_stat_get_backend_wait_event() for aux processes

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
This commit is contained in:
Heikki Linnakangas
2026-02-11 18:50:57 +02:00
parent 1d92e0c2cc
commit 78a5e3074b

View 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();