From fb3dbdf986f0ab56e0a5177966bb0dec1f93444c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 16 Dec 2005 04:03:40 +0000 Subject: Rethink prior patch to filter out dead backend entries from the pgstats file. The original code probed the PGPROC array separately for each PID, which was not good for large numbers of backends: not only is the runtime O(N^2) but most of it is spent holding ProcArrayLock. Instead, take the lock just once and copy the active PIDs into an array, then use qsort and bsearch so that the lookup time is more like O(N log N). --- src/include/storage/procarray.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/include') diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index 68c615afc6e..61441bbf49e 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.6 2005/10/15 02:49:46 momjian Exp $ + * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.7 2005/12/16 04:03:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,7 @@ extern TransactionId GetOldestXmin(bool allDbs); extern PGPROC *BackendPidGetProc(int pid); extern int BackendXidGetPid(TransactionId xid); extern bool IsBackendPid(int pid); +extern int *GetAllBackendPids(void); extern bool DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself); extern int CountActiveBackends(void); -- cgit v1.2.3