mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Display the leader apply worker's PID for parallel apply workers.
Add leader_pid to pg_stat_subscription. leader_pid is the process ID of the leader apply worker if this process is a parallel apply worker. If this field is NULL, it indicates that the process is a leader apply worker or a synchronization worker. The new column makes it easier to distinguish parallel apply workers from other kinds of workers and helps to identify the leader for the parallel workers corresponding to a particular subscription. Additionally, update the leader_pid column in pg_stat_activity as well to display the PID of the leader apply worker for parallel apply workers. Author: Hou Zhijie Reviewed-by: Peter Smith, Sawada Masahiko, Amit Kapila, Shveta Mallik Discussion: https://postgr.es/m/CAA4eK1+wyN6zpaHUkCLorEWNx75MG0xhMwcFhvjqm2KURZEAGw@mail.gmail.com
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include "pgstat.h"
|
||||
#include "postmaster/bgworker_internals.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "replication/logicallauncher.h"
|
||||
#include "storage/proc.h"
|
||||
#include "storage/procarray.h"
|
||||
#include "utils/acl.h"
|
||||
@ -409,9 +410,9 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* group leader or apply 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)
|
||||
{
|
||||
@ -426,14 +427,24 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* Show the leader only for active parallel workers. This
|
||||
* leaves the field as NULL for the leader of a parallel
|
||||
* group.
|
||||
* leaves the field as NULL for the leader of a parallel group
|
||||
* or the leader of parallel apply workers.
|
||||
*/
|
||||
if (leader && leader->pid != beentry->st_procpid)
|
||||
{
|
||||
values[28] = Int32GetDatum(leader->pid);
|
||||
nulls[28] = false;
|
||||
}
|
||||
else if (beentry->st_backendType == B_BG_WORKER)
|
||||
{
|
||||
int leader_pid = GetLeaderApplyWorkerPid(beentry->st_procpid);
|
||||
|
||||
if (leader_pid != InvalidPid)
|
||||
{
|
||||
values[28] = Int32GetDatum(leader_pid);
|
||||
nulls[28] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wait_event_type)
|
||||
|
Reference in New Issue
Block a user