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)
266267postExecProcNode_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 */
299279if (MyProcPid == trace_req -> traceable )
300280{
301- PGPROC * tracer = search_proc (trace_req -> tracer );
281+ PGPROC * tracer = BackendPidGetProc (trace_req -> tracer );
302282
303283Assert (tracer != NULL );
304284
@@ -583,7 +563,7 @@ pg_query_state(PG_FUNCTION_ARGS)
583563ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
584564errmsg ("attempt to extract state of current process" )));
585565
586- proc = search_proc (pid );
566+ proc = BackendPidGetProc (pid );
587567if (!proc || proc -> backendId == InvalidBackendId )
588568ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
589569errmsg ("backend with pid=%d not found" ,pid )));
@@ -743,7 +723,7 @@ exec_trace_cmd(pid_t pid, trace_cmd cmd)
743723ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
744724errmsg ("attempt to trace self process" )));
745725
746- proc = search_proc (pid );
726+ proc = BackendPidGetProc (pid );
747727if (!proc || proc -> backendId == InvalidBackendId )
748728ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
749729errmsg ("backend with pid=%d not found" ,pid )));