Skip to content

Commit ac92c4a

Browse files
committed
Merge commit 'cd5f485d3d375f20c62fabce953e0a16dc5c300f' into PGPRO9_5
2 parents 7680c9f + cd5f485 commit ac92c4a

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

contrib/pg_query_state/pg_query_state.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "miscadmin.h"
1818
#include "pgstat.h"
1919
#include "storage/ipc.h"
20+
#include "storage/procarray.h"
2021
#include "storage/procsignal.h"
2122
#include "storage/shm_toc.h"
2223
#include "utils/guc.h"
@@ -266,27 +267,6 @@ _PG_fini(void)
266267
postExecProcNode_hook = prev_postExecProcNode;
267268
}
268269

269-
/*
270-
* Find PGPROC entry
271-
*/
272-
static PGPROC *
273-
search_proc(int pid)
274-
{
275-
int i;
276-
277-
if (pid <= 0)
278-
return NULL;
279-
280-
for (i = 0; i < ProcGlobal->allProcCount; i++)
281-
{
282-
PGPROC *proc = &ProcGlobal->allProcs[i];
283-
if (proc->pid == pid)
284-
return proc;
285-
}
286-
287-
return NULL;
288-
}
289-
290270
/*
291271
* In trace mode suspend query execution until other backend resumes it
292272
*/
@@ -298,7 +278,7 @@ suspend_traceable_query()
298278
/* Check whether current backend is traced */
299279
if (MyProcPid == trace_req->traceable)
300280
{
301-
PGPROC *tracer = search_proc(trace_req->tracer);
281+
PGPROC *tracer = BackendPidGetProc(trace_req->tracer);
302282

303283
Assert(tracer != NULL);
304284

@@ -583,7 +563,7 @@ pg_query_state(PG_FUNCTION_ARGS)
583563
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
584564
errmsg("attempt to extract state of current process")));
585565

586-
proc = search_proc(pid);
566+
proc = BackendPidGetProc(pid);
587567
if (!proc || proc->backendId == InvalidBackendId)
588568
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
589569
errmsg("backend with pid=%d not found", pid)));
@@ -743,7 +723,7 @@ exec_trace_cmd(pid_t pid, trace_cmd cmd)
743723
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
744724
errmsg("attempt to trace self process")));
745725

746-
proc = search_proc(pid);
726+
proc = BackendPidGetProc(pid);
747727
if (!proc || proc->backendId == InvalidBackendId)
748728
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
749729
errmsg("backend with pid=%d not found", pid)));

0 commit comments

Comments
 (0)