> On Feb 2, 2026, at 22:38, Heikki Linnakangas <[email protected]> wrote:
> 
> pg_stat_get_backend_wait_event() and pg_stat_get_backend_wait_event_type() 
> functions don't work for aux processes:
> 
>> postgres=# select pid, backend_type, wait_event, wait_event_type from 
>> pg_stat_activity ;
>>   pid   |         backend_type         |     wait_event      | 
>> wait_event_type 
>> ---------+------------------------------+---------------------+-----------------
>> 3665058 | client backend               |                     |  3665051 | 
>> autovacuum launcher          | AutovacuumMain      | Activity
>> 3665052 | logical replication launcher | LogicalLauncherMain | Activity
>> 3665044 | io worker                    | IoWorkerMain        | Activity
>> 3665045 | io worker                    | IoWorkerMain        | Activity
>> 3665046 | io worker                    | IoWorkerMain        | Activity
>> 3665047 | checkpointer                 | CheckpointerMain    | Activity
>> 3665048 | background writer            | BgwriterMain        | Activity
>> 3665050 | walwriter                    | WalWriterMain       | Activity
>> (9 rows)
>> postgres=# SELECT pg_stat_get_backend_pid(backendid) AS pid,
>>       pg_stat_get_backend_wait_event_type(backendid) as wait_event_type,
>>       pg_stat_get_backend_wait_event(backendid) as wait_event
>> FROM pg_stat_get_backend_idset() AS backendid;
>>   pid   | wait_event_type |     wait_event      
>> ---------+-----------------+---------------------
>> 3665058 |                 |  3665051 | Activity        | AutovacuumMain
>> 3665052 | Activity        | LogicalLauncherMain
>> 3665044 |                 |  3665045 |                 |  3665046 |          
>>        |  3665047 |                 |  3665048 |                 |  3665050 
>> |                 | (9 rows)
> 
> We added aux processes to pg_stat_activity in commit fc70a4b0df, but 
> apparently forgot to do the same for those functions.
> 
> With the attached fix:
> 
>> postgres=# SELECT pg_stat_get_backend_pid(backendid) AS pid,
>>       pg_stat_get_backend_wait_event_type(backendid) as wait_event_type,
>>       pg_stat_get_backend_wait_event(backendid) as wait_event
>> FROM pg_stat_get_backend_idset() AS backendid;
>>   pid   | wait_event_type |     wait_event      
>> ---------+-----------------+---------------------
>> 3667552 |                 |  3667545 | Activity        | AutovacuumMain
>> 3667546 | Activity        | LogicalLauncherMain
>> 3667538 | Activity        | IoWorkerMain
>> 3667539 | Activity        | IoWorkerMain
>> 3667540 | Activity        | IoWorkerMain
>> 3667541 | Activity        | CheckpointerMain
>> 3667542 | Activity        | BgwriterMain
>> 3667544 | Activity        | WalWriterMain
>> (9 rows)
> 
> While looking at this, I noticed that pg_stat_activity has a "backend_type" 
> field, but there's no corresponding "pg_stat_get_backend_type(backend_id)" 
> function, similar to "pg_stat_get_backend_wait_event(backend_id)" et al. I 
> wonder if that was on purpose, or we just forgot to add it when we added it 
> to pg_stat_activity?
> 
> Another thing I didn't do in this patch yet: I feel we should replace 
> BackendPidGetProc() with a function like "PGPROC *PidGetPGProc(pid_t)", that 
> would work for backends and aux processes alike. It's a common pattern to 
> call BackendPidGetProc() followed by AuxiliaryPidGetProc() currently. Even 
> for the callers that specifically want to only check backend processes, I 
> think it would be more natural to call PidGetPGProc(), and then check the 
> process type.
> 
> - Heikki
> <0001-Fix-pg_stat_get_backend_wait_event-for-aux-processes.patch>

Hi Heikki,

I reviewed and tested the patch, it works well, and the code change looks solid 
to me.

I only have one small comment. In the following case:
```
        if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
                wait_event_type = "<backend information not available>";
```

With this patch, aux processes are now supported as well. Do we want to update 
this message?

For example, in my test system max_connections = 100, so procNumber >= 100 
corresponds to aux processes. If I run:
```
evantest=# select pg_stat_get_backend_wait_event(188);
   pg_stat_get_backend_wait_event
-------------------------------------
 <backend information not available>
(1 row)
```

Here 188 refers to an aux process, but the message still says “backend 
information”, which feels a bit misleading. Would it make sense to change this 
to something like “process information not available”?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Reply via email to