Fix pg_stat_get_backend_wait_event() for aux processes

Поиск
Список
Период
Сортировка
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

Вложения

В списке pgsql-hackers по дате отправления: