Skip to content

Commit 68a5194

Browse files
[#28638] YSQL: Add additional columns to the rpcz endpoint
Summary: This diff adds additional columns pid and pss_mem_bytes to rpcz endpoint and corrects the logic for capturing leader_pid column. These columns are pid, pss_mm_bytes and leader_pid. The leader_pid field was already being captured internally in the yb_pg_metrics.c through the PostgreSQL lock group leader mechanism, but was failing to identify parallel workers. The new implementation identifies parallel workers by retrieving the PGPROC structure for backend processes and background workers. pid: Process ID of the process. pss_mem_bytes: PSS memory usage in bytes for the process. It returns -1 if unavailable or tracking is disabled. leader_pid: Leader PID if this is a parallel worker. This will be -1 for leaders and non-parallel backends. Test Plan: Output at http://localhost:13000/rpcz { "connections": [ { "process_start_time": "2025-11-04 13:39:01.277151+05:30", "application_name": "yb_ash collector", "backend_type": "background worker", "backend_status": "", "pid": 71979, "pss_mem_bytes": -1 }, { "db_oid": 16384, "db_name": "cdb", "query": "EXPLAIN ANALYSE SELECT COUNT(*) FROM test;", "query_id": 16749132132008374320, "leader_pid": 72084, "process_start_time": "2025-11-04 13:48:19.052474+05:30", "process_running_for_ms": 1722, "transaction_start_time": "2025-11-04 13:48:18.922652+05:30", "transaction_running_for_ms": 1852, "query_start_time": "2025-11-04 13:48:18.922652+05:30", "query_running_for_ms": 1852, "application_name": "ysqlsh", "backend_type": "background worker", "backend_status": "active", "pid": 72510, "pss_mem_bytes": -1 }, { "db_oid": 16384, "db_name": "cdb", "query": "EXPLAIN ANALYSE SELECT COUNT(*) FROM test;", "query_id": 16749132132008374320, "process_start_time": "2025-11-04 13:39:44.18782+05:30", "process_running_for_ms": 516587, "transaction_start_time": "2025-11-04 13:48:18.922652+05:30", "transaction_running_for_ms": 1852, "query_start_time": "2025-11-04 13:48:18.922652+05:30", "query_running_for_ms": 1852, "application_name": "ysqlsh", "backend_type": "client backend", "backend_status": "active", "host": "127.0.0.1", "port": "57558", "pid": 72084, "pss_mem_bytes": -1 }, { "db_oid": 16384, "db_name": "cdb", "query": "EXPLAIN ANALYSE SELECT COUNT(*) FROM test;", "query_id": 16749132132008374320, "leader_pid": 72084, "process_start_time": "2025-11-04 13:48:19.05245+05:30", "process_running_for_ms": 1722, "transaction_start_time": "2025-11-04 13:48:18.922652+05:30", "transaction_running_for_ms": 1852, "query_start_time": "2025-11-04 13:48:18.922652+05:30", "query_running_for_ms": 1852, "application_name": "ysqlsh", "backend_type": "background worker", "backend_status": "active", "pid": 72509, "pss_mem_bytes": -1 }, { "process_start_time": "2025-11-04 13:39:01.271293+05:30", "application_name": "", "backend_type": "checkpointer", "backend_status": "", "pid": 71976, "pss_mem_bytes": -1 } ] } Reviewers: asaha, ishan.chhangani, hbhanawat, cagrawal Reviewed By: asaha Subscribers: svc_phabricator, yql Differential Revision: https://phorge.dev.yugabyte.com/D47924
1 parent a1515ed commit 68a5194

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/postgres/yb-extensions/yb_pg_metrics/yb_pg_metrics.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ pullRpczEntries(void)
590590
PGPROC *proc = NULL;
591591

592592
if (beentry->st_backendType == B_BACKEND ||
593+
beentry->st_backendType == B_BG_WORKER ||
593594
beentry->st_backendType == YB_AUTO_ANALYZE_BACKEND)
594595
proc = BackendPidGetProc(rpcz[i].proc_id);
595596
else if (beentry->st_backendType != YB_YSQL_CONN_MGR)
@@ -605,7 +606,11 @@ pullRpczEntries(void)
605606
{
606607
PGPROC *leader = proc->lockGroupLeader;
607608

608-
if (leader != NULL)
609+
/*
610+
* Show the leader only for active parallel workers. This leaves
611+
* the field as -1 (NULL equivalent) for the leader of a parallel group.
612+
*/
613+
if (leader != NULL && leader->pid != beentry->st_procpid)
609614
{
610615
rpcz[i].leader_pid = leader->pid;
611616
}
@@ -680,6 +685,11 @@ pullRpczEntries(void)
680685
rpcz[i].host = NULL;
681686
rpcz[i].port = NULL;
682687
}
688+
689+
int64_t rss_bytes, pss_bytes;
690+
YbPgGetCurRssPssMemUsage(rpcz[i].proc_id, &rss_bytes, &pss_bytes);
691+
rpcz[i].pss_mem_bytes = pss_bytes;
692+
683693
after_changecount = beentry->st_changecount;
684694

685695
if (before_changecount == after_changecount &&

src/yb/yql/pggate/webserver/ybc_pg_webserver_wrapper.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ static void PgRpczHandler(const Webserver::WebRequest &req, Webserver::WebRespon
455455
writer.String(entry->port);
456456
}
457457

458+
writer.String("pid");
459+
writer.Int(entry->proc_id);
460+
461+
writer.String("pss_mem_bytes");
462+
writer.Int64(entry->pss_mem_bytes);
463+
458464
writer.EndObject();
459465
}
460466
}

src/yb/yql/pggate/webserver/ybc_pg_webserver_wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef struct YbcRpczEntry {
6464
char *backend_status;
6565
char *host;
6666
char *port;
67+
int64 pss_mem_bytes;
6768
} YbcRpczEntry;
6869

6970
typedef struct {

0 commit comments

Comments
 (0)