mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Take the statistics collector out of the loop for monitoring backends'
current commands; instead, store current-status information in shared memory. This substantially reduces the overhead of stats_command_string and also ensures that pg_stat_activity is fully up to date at all times. Per my recent proposal.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.83 2006/05/08 00:00:10 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.84 2006/06/19 01:51:21 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -21,6 +21,7 @@
|
||||
#include "access/twophase.h"
|
||||
#include "access/xlog.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "postmaster/bgwriter.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/bufmgr.h"
|
||||
@ -86,6 +87,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
|
||||
size = add_size(size, MultiXactShmemSize());
|
||||
size = add_size(size, LWLockShmemSize());
|
||||
size = add_size(size, ProcArrayShmemSize());
|
||||
size = add_size(size, BackendStatusShmemSize());
|
||||
size = add_size(size, SInvalShmemSize());
|
||||
size = add_size(size, FreeSpaceShmemSize());
|
||||
size = add_size(size, BgWriterShmemSize());
|
||||
@ -167,6 +169,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
|
||||
if (!IsUnderPostmaster)
|
||||
InitProcGlobal();
|
||||
CreateSharedProcArray();
|
||||
CreateSharedBackendStatus();
|
||||
|
||||
/*
|
||||
* Set up shared-inval messaging
|
||||
|
@ -23,7 +23,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.11 2006/03/05 15:58:37 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.12 2006/06/19 01:51:21 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -732,42 +732,6 @@ IsBackendPid(int pid)
|
||||
return (BackendPidGetProc(pid) != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* GetAllBackendPids -- get an array of all current backends' PIDs
|
||||
*
|
||||
* The result is a palloc'd array with the number of active backends in
|
||||
* entry [0], their PIDs in entries [1] .. [n]. The caller must bear in
|
||||
* mind that the result may already be obsolete when returned.
|
||||
*/
|
||||
int *
|
||||
GetAllBackendPids(void)
|
||||
{
|
||||
int *result;
|
||||
int npids;
|
||||
ProcArrayStruct *arrayP = procArray;
|
||||
int index;
|
||||
|
||||
result = (int *) palloc((MaxBackends + 1) * sizeof(int));
|
||||
npids = 0;
|
||||
|
||||
LWLockAcquire(ProcArrayLock, LW_SHARED);
|
||||
|
||||
for (index = 0; index < arrayP->numProcs; index++)
|
||||
{
|
||||
PGPROC *proc = arrayP->procs[index];
|
||||
|
||||
if (proc->pid != 0) /* ignore dummy procs */
|
||||
result[++npids] = proc->pid;
|
||||
}
|
||||
|
||||
LWLockRelease(ProcArrayLock);
|
||||
|
||||
Assert(npids <= MaxBackends);
|
||||
|
||||
result[0] = npids;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* CountActiveBackends --- count backends (other than myself) that are in
|
||||
* active transactions. This is used as a heuristic to decide if
|
||||
|
Reference in New Issue
Block a user