1 /*-------------------------------------------------------------------------
4 * per-process shared memory data structures
7 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.80 2005/07/31 17:19:22 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/lock.h"
19 #include "storage/pg_sema.h"
23 * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
24 * for non-aborted subtransactions of its current top transaction. These
25 * have to be treated as running XIDs by other backends.
27 * We also keep track of whether the cache overflowed (ie, the transaction has
28 * generated at least one subtransaction that didn't fit in the cache).
29 * If none of the caches have overflowed, we can assume that an XID that's not
30 * listed anywhere in the PGPROC array is not a running transaction. Else we
31 * have to look at pg_subtrans.
33 #define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */
39 TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
43 * Each backend has a PGPROC struct in shared memory. There is also a list of
44 * currently-unused PGPROC structs that will be reallocated to new backends.
46 * links: list link for any list the PGPROC is in. When waiting for a lock,
47 * the PGPROC is linked into that lock's waitProcs queue. A recycled PGPROC
48 * is linked into ProcGlobal's freeProcs list.
50 * Note: twophase.c also sets up a dummy PGPROC struct for each currently
51 * prepared transaction. These PGPROCs appear in the ProcArray data structure
52 * so that the prepared transactions appear to be still running and are
53 * correctly shown as holding locks. A prepared transaction PGPROC can be
54 * distinguished from a real one at need by the fact that it has pid == 0.
55 * The semaphore and lock-related fields in a prepared-xact PGPROC are unused.
59 /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
60 SHM_QUEUE links; /* list link if process is in a list */
62 PGSemaphoreData sem; /* ONE semaphore to sleep on */
63 int waitStatus; /* STATUS_OK or STATUS_ERROR after wakeup */
65 TransactionId xid; /* transaction currently being executed by
68 TransactionId xmin; /* minimal running XID as it was when we
69 * were starting our xact: vacuum must not
70 * remove tuples deleted by xid >= xmin ! */
72 int pid; /* This backend's process id, or 0 */
73 Oid databaseId; /* OID of database this backend is using */
74 Oid roleId; /* OID of role using this backend */
76 /* Info about LWLock the process is currently waiting for, if any. */
77 bool lwWaiting; /* true if waiting for an LW lock */
78 bool lwExclusive; /* true if waiting for exclusive access */
79 struct PGPROC *lwWaitLink; /* next waiter for same LW lock */
81 /* Info about lock the process is currently waiting for, if any. */
82 /* waitLock and waitProcLock are NULL if not currently waiting. */
83 LOCK *waitLock; /* Lock object we're sleeping on ... */
84 PROCLOCK *waitProcLock; /* Per-holder info for awaited lock */
85 LOCKMODE waitLockMode; /* type of lock we're waiting for */
86 LOCKMASK heldLocks; /* bitmask for lock types already held on
87 * this lock object by this backend */
89 SHM_QUEUE procLocks; /* list of PROCLOCK objects for locks held
90 * or awaited by this backend */
92 struct XidCache subxids; /* cache for subtransaction XIDs */
95 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
98 extern DLLIMPORT PGPROC *MyProc;
102 * There is one ProcGlobal struct for the whole installation.
104 typedef struct PROC_HDR
106 /* Head of list of free PGPROC structures */
107 SHMEM_OFFSET freeProcs;
111 #define DUMMY_PROC_DEFAULT 0
112 #define DUMMY_PROC_BGWRITER 1
113 #define NUM_DUMMY_PROCS 2
116 /* configurable options */
117 extern int DeadlockTimeout;
118 extern int StatementTimeout;
122 * Function Prototypes
124 extern int ProcGlobalSemas(void);
125 extern int ProcGlobalShmemSize(void);
126 extern void InitProcGlobal(void);
127 extern void InitProcess(void);
128 extern void InitDummyProcess(int proctype);
129 extern bool HaveNFreeProcs(int n);
130 extern void ProcReleaseLocks(bool isCommit);
132 extern void ProcQueueInit(PROC_QUEUE *queue);
133 extern int ProcSleep(LockMethod lockMethodTable, LOCKMODE lockmode,
134 LOCK *lock, PROCLOCK *proclock);
135 extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
136 extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
137 extern bool LockWaitCancel(void);
139 extern void ProcWaitForSignal(void);
140 extern void ProcCancelWaitForSignal(void);
141 extern void ProcSendSignal(int pid);
143 extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
144 extern bool disable_sig_alarm(bool is_statement_timeout);
145 extern void handle_sig_alarm(SIGNAL_ARGS);