On 6th of February 2020, Michael Paquier committed patch:
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
This is pretty cool. We have, for quite some time now, parallel queries. Now we're getting more visibility to them.
If I'd run a query that runs parallel workers, like
=$ EXPLAIN analyze SELECT COUNT(*) FROM test;
on large table, I see, in pg_stat_activity:
=$ SELECT pid, leader_pid, query FROM pg_stat_activity pid │ leader_pid │ query ───────┼────────────┼────────────────────────────────────────────────────── 19316 │ [NULL] │ SELECT pid, leader_pid, query FROM pg_stat_activity 19964 │ 19964 │ EXPLAIN analyze SELECT COUNT(*) FROM test; 23364 │ 19964 │ EXPLAIN analyze SELECT COUNT(*) FROM test; 23365 │ 19964 │ EXPLAIN analyze SELECT COUNT(*) FROM test; ...
This is great. Thanks to all involved.