diff options
author | Michael Paquier <michael@paquier.xyz> | 2020-02-06 09:18:06 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2020-02-06 09:18:06 +0900 |
commit | b025f32e0b5d7668daec9bfa957edf3599f4baa8 (patch) | |
tree | f0bf150285ba5f704826db1910c675b63a9a1ff2 /src/backend/utils/adt/pgstatfuncs.c | |
parent | bf6cc19e347d4cb8dfc8f05a59171ac06e18b5e5 (diff) | |
download | postgresql-b025f32e0b5d7668daec9bfa957edf3599f4baa8.tar.gz postgresql-b025f32e0b5d7668daec9bfa957edf3599f4baa8.zip |
Add leader_pid to pg_stat_activity
This new field tracks the PID of the group leader used with parallel
query. For parallel workers and the leader, the value is set to the
PID of the group leader. So, for the group leader, the value is the
same as its own PID. Note that this reflects what PGPROC stores in
shared memory, so as leader_pid is NULL if a backend has never been
involved in parallel query. If the backend is using parallel query or
has used it at least once, the value is set until the backend exits.
Author: Julien Rouhaud
Reviewed-by: Sergei Kornilov, Guillaume Lelarge, Michael Paquier, Tomas
Vondra
Discussion: https://postgr.es/m/CAOBaU_Yy5bt0vTPZ2_LUM6cUcGeqmYNoJ8-Rgto+c2+w3defYA@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 7b2da2b36f8..7e6a3c17741 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -547,7 +547,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS) Datum pg_stat_get_activity(PG_FUNCTION_ARGS) { -#define PG_STAT_GET_ACTIVITY_COLS 29 +#define PG_STAT_GET_ACTIVITY_COLS 30 int num_backends = pgstat_fetch_stat_numbackends(); int curr_backend; int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0); @@ -686,33 +686,40 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) values[5] = CStringGetTextDatum(clipped_activity); pfree(clipped_activity); - proc = BackendPidGetProc(beentry->st_procpid); - if (proc != NULL) - { - uint32 raw_wait_event; + /* leader_pid */ + nulls[29] = true; - raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info); - wait_event_type = pgstat_get_wait_event_type(raw_wait_event); - wait_event = pgstat_get_wait_event(raw_wait_event); + proc = BackendPidGetProc(beentry->st_procpid); - } - else if (beentry->st_backendType != B_BACKEND) + if (proc == NULL && (beentry->st_backendType != B_BACKEND)) { /* * For an auxiliary process, retrieve process info from * AuxiliaryProcs stored in shared-memory. */ proc = AuxiliaryPidGetProc(beentry->st_procpid); + } - if (proc != NULL) - { - uint32 raw_wait_event; + /* + * If a PGPROC entry was retrieved, display wait events and lock + * group leader information if any. To avoid extra overhead, no + * extra lock is being held, so there is no guarantee of + * consistency across multiple rows. + */ + if (proc != NULL) + { + uint32 raw_wait_event; + PGPROC *leader; - raw_wait_event = - UINT32_ACCESS_ONCE(proc->wait_event_info); - wait_event_type = - pgstat_get_wait_event_type(raw_wait_event); - wait_event = pgstat_get_wait_event(raw_wait_event); + raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info); + wait_event_type = pgstat_get_wait_event_type(raw_wait_event); + wait_event = pgstat_get_wait_event(raw_wait_event); + + leader = proc->lockGroupLeader; + if (leader) + { + values[29] = Int32GetDatum(leader->pid); + nulls[29] = false; } } @@ -908,6 +915,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) nulls[26] = true; nulls[27] = true; nulls[28] = true; + nulls[29] = true; } tuplestore_putvalues(tupstore, tupdesc, values, nulls); |