Skip to content

Commit 11a68e4

Browse files
committed
Tweak behavior of pg_stat_activity.leader_pid
The initial implementation of leader_pid in pg_stat_activity added by b025f32 took the approach to strictly print what a PGPROC entry includes. In short, if a backend has been involved in parallel query at least once, leader_pid would remain set as long as the backend is alive. For a parallel group leader, this means that the field would always be set after it participated at least once in parallel query, and after more discussions this could be confusing if using for example a connection pooler. This commit changes the data printed so as leader_pid becomes always NULL for a parallel group leader, showing up a non-NULL value only for the parallel workers, and actually as long as a parallel query is running as workers are shut down once the query has completed. This does not change the definition of any catalog, so no catalog bump is needed. Per discussion with Justin Pryzby, Álvaro Herrera, Julien Rouhaud and me. Discussion: https://postgr.es/m/[email protected] Backpatch-through: 13
1 parent 15e4419 commit 11a68e4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

doc/src/sgml/monitoring.sgml

+3-6
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,9 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
687687
<structfield>leader_pid</structfield> <type>integer</type>
688688
</para>
689689
<para>
690-
Process ID of the parallel group leader if this process is or
691-
has been involved in parallel query, or null. This field is set
692-
when a process wants to cooperate with parallel workers, and
693-
remains set as long as the process exists. For a parallel group leader,
694-
this field is set to its own process ID. For a parallel worker,
695-
this field is set to the process ID of the parallel group leader.
690+
Process ID of the parallel group leader, if this process is a
691+
parallel query worker. <literal>NULL</literal> if this process is a
692+
parallel group leader or does not participate in parallel query.
696693
</para></entry>
697694
</row>
698695

src/backend/utils/adt/pgstatfuncs.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,13 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
735735
wait_event = pgstat_get_wait_event(raw_wait_event);
736736

737737
leader = proc->lockGroupLeader;
738-
if (leader)
738+
739+
/*
740+
* Show the leader only for active parallel workers. This
741+
* leaves the field as NULL for the leader of a parallel
742+
* group.
743+
*/
744+
if (leader && leader->pid != beentry->st_procpid)
739745
{
740746
values[29] = Int32GetDatum(leader->pid);
741747
nulls[29] = false;

0 commit comments

Comments
 (0)