17
17
#include "miscadmin.h"
18
18
#include "pgstat.h"
19
19
#include "storage/ipc.h"
20
+ #include "storage/procarray.h"
20
21
#include "storage/procsignal.h"
21
22
#include "storage/shm_toc.h"
22
23
#include "utils/guc.h"
@@ -266,27 +267,6 @@ _PG_fini(void)
266
267
postExecProcNode_hook = prev_postExecProcNode ;
267
268
}
268
269
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
-
290
270
/*
291
271
* In trace mode suspend query execution until other backend resumes it
292
272
*/
@@ -298,7 +278,7 @@ suspend_traceable_query()
298
278
/* Check whether current backend is traced */
299
279
if (MyProcPid == trace_req -> traceable )
300
280
{
301
- PGPROC * tracer = search_proc (trace_req -> tracer );
281
+ PGPROC * tracer = BackendPidGetProc (trace_req -> tracer );
302
282
303
283
Assert (tracer != NULL );
304
284
@@ -583,7 +563,7 @@ pg_query_state(PG_FUNCTION_ARGS)
583
563
ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
584
564
errmsg ("attempt to extract state of current process" )));
585
565
586
- proc = search_proc (pid );
566
+ proc = BackendPidGetProc (pid );
587
567
if (!proc || proc -> backendId == InvalidBackendId )
588
568
ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
589
569
errmsg ("backend with pid=%d not found" ,pid )));
@@ -743,7 +723,7 @@ exec_trace_cmd(pid_t pid, trace_cmd cmd)
743
723
ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
744
724
errmsg ("attempt to trace self process" )));
745
725
746
- proc = search_proc (pid );
726
+ proc = BackendPidGetProc (pid );
747
727
if (!proc || proc -> backendId == InvalidBackendId )
748
728
ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
749
729
errmsg ("backend with pid=%d not found" ,pid )));