PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
procarray.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * procarray.h
4  * POSTGRES process array definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/procarray.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PROCARRAY_H
15 #define PROCARRAY_H
16 
17 #include "storage/lock.h"
18 #include "storage/standby.h"
19 #include "utils/relcache.h"
20 #include "utils/snapshot.h"
21 
22 
23 /*
24  * These are to implement PROCARRAY_FLAGS_XXX
25  *
26  * Note: These flags are cloned from PROC_XXX flags in src/include/storage/proc.h
27  * to avoid forcing to include proc.h when including procarray.h. So if you modify
28  * PROC_XXX flags, you need to modify these flags.
29  */
30 #define PROCARRAY_VACUUM_FLAG 0x02 /* currently running lazy vacuum */
31 #define PROCARRAY_ANALYZE_FLAG 0x04 /* currently running analyze */
32 #define PROCARRAY_LOGICAL_DECODING_FLAG 0x10 /* currently doing logical
33  * decoding outside xact */
34 
35 #define PROCARRAY_SLOTS_XMIN 0x20 /* replication slot xmin,
36  * catalog_xmin */
37 /*
38  * Only flags in PROCARRAY_PROC_FLAGS_MASK are considered when matching
39  * PGXACT->vacuumFlags. Other flags are used for different purposes and
40  * have no corresponding PROC flag equivalent.
41  */
42 #define PROCARRAY_PROC_FLAGS_MASK (PROCARRAY_VACUUM_FLAG | \
43  PROCARRAY_ANALYZE_FLAG | \
44  PROCARRAY_LOGICAL_DECODING_FLAG)
45 
46 /* Use the following flags as an input "flags" to GetOldestXmin function */
47 /* Consider all backends except for logical decoding ones which manage xmin separately */
48 #define PROCARRAY_FLAGS_DEFAULT PROCARRAY_LOGICAL_DECODING_FLAG
49 /* Ignore vacuum backends */
50 #define PROCARRAY_FLAGS_VACUUM PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG
51 /* Ignore analyze backends */
52 #define PROCARRAY_FLAGS_ANALYZE PROCARRAY_FLAGS_DEFAULT | PROCARRAY_ANALYZE_FLAG
53 /* Ignore both vacuum and analyze backends */
54 #define PROCARRAY_FLAGS_VACUUM_ANALYZE PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG | PROCARRAY_ANALYZE_FLAG
55 
56 extern Size ProcArrayShmemSize(void);
57 extern void CreateSharedProcArray(void);
58 extern void ProcArrayAdd(PGPROC *proc);
59 extern void ProcArrayRemove(PGPROC *proc, TransactionId latestXid);
60 
61 extern void ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid);
62 extern void ProcArrayClearTransaction(PGPROC *proc);
63 
64 extern void ProcArrayInitRecovery(TransactionId initializedUptoXID);
67  int nsubxids, TransactionId *subxids);
68 
71  int nsubxids, TransactionId *subxids,
72  TransactionId max_xid);
73 extern void ExpireAllKnownAssignedTransactionIds(void);
75 
76 extern int GetMaxSnapshotXidCount(void);
77 extern int GetMaxSnapshotSubxidCount(void);
78 
79 extern Snapshot GetSnapshotData(Snapshot snapshot);
80 
82  TransactionId sourcexid);
83 extern bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc);
84 
86 
88 extern bool TransactionIdIsActive(TransactionId xid);
89 extern TransactionId GetOldestXmin(Relation rel, int flags);
91 extern TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly);
92 
94 extern bool HaveVirtualXIDsDelayingChkpt(VirtualTransactionId *vxids, int nvxids);
95 
96 extern PGPROC *BackendPidGetProc(int pid);
97 extern PGPROC *BackendPidGetProcWithLock(int pid);
98 extern int BackendXidGetPid(TransactionId xid);
99 extern bool IsBackendPid(int pid);
100 
102  bool excludeXmin0, bool allDbs, int excludeVacuum,
103  int *nvxids);
106 
107 extern bool MinimumActiveBackends(int min);
108 extern int CountDBBackends(Oid databaseid);
109 extern int CountDBConnections(Oid databaseid);
110 extern void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending);
111 extern int CountUserBackends(Oid roleid);
112 extern bool CountOtherDBBackends(Oid databaseId,
113  int *nbackends, int *nprepared);
114 
116  int nxids, const TransactionId *xids,
117  TransactionId latestXid);
118 
120  TransactionId catalog_xmin, bool already_locked);
121 
123  TransactionId *catalog_xmin);
124 
125 #endif /* PROCARRAY_H */
bool TransactionIdIsActive(TransactionId xid)
Definition: procarray.c:1215
void ProcArrayInitRecovery(TransactionId initializedUptoXID)
Definition: procarray.c:636
TransactionId GetOldestXmin(Relation rel, int flags)
Definition: procarray.c:1314
bool IsBackendPid(int pid)
Definition: procarray.c:2437
uint32 TransactionId
Definition: c.h:397
void ProcArraySetReplicationSlotXmin(TransactionId xmin, TransactionId catalog_xmin, bool already_locked)
Definition: procarray.c:2960
PGPROC * BackendPidGetProcWithLock(int pid)
Definition: procarray.c:2365
void CreateSharedProcArray(void)
Definition: procarray.c:221
bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc)
Definition: procarray.c:1868
Size ProcArrayShmemSize(void)
Definition: procarray.c:179
int BackendXidGetPid(TransactionId xid)
Definition: procarray.c:2402
int CountUserBackends(Oid roleid)
Definition: procarray.c:2836
VirtualTransactionId * GetCurrentVirtualXIDs(TransactionId limitXmin, bool excludeXmin0, bool allDbs, int excludeVacuum, int *nvxids)
Definition: procarray.c:2470
unsigned int Oid
Definition: postgres_ext.h:31
int GetMaxSnapshotXidCount(void)
Definition: procarray.c:1455
void ExpireOldKnownAssignedTransactionIds(TransactionId xid)
Definition: procarray.c:3279
int GetMaxSnapshotSubxidCount(void)
Definition: procarray.c:1466
RunningTransactions GetRunningTransactionData(void)
Definition: procarray.c:1930
bool HaveVirtualXIDsDelayingChkpt(VirtualTransactionId *vxids, int nvxids)
Definition: procarray.c:2295
Snapshot GetSnapshotData(Snapshot snapshot)
Definition: procarray.c:1508
void ProcArrayAdd(PGPROC *proc)
Definition: procarray.c:274
pid_t CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode)
Definition: procarray.c:2633
TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly)
Definition: procarray.c:2154
TransactionId GetOldestActiveTransactionId(void)
Definition: procarray.c:2088
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:914
bool CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
Definition: procarray.c:2886
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:2342
void ProcArrayApplyRecoveryInfo(RunningTransactions running)
Definition: procarray.c:667
bool ProcArrayInstallImportedXmin(TransactionId xmin, TransactionId sourcexid)
Definition: procarray.c:1796
int CountDBConnections(Oid databaseid)
Definition: procarray.c:2765
void XidCacheRemoveRunningXids(TransactionId xid, int nxids, const TransactionId *xids, TransactionId latestXid)
Definition: procarray.c:3012
void ProcArrayRemove(PGPROC *proc, TransactionId latestXid)
Definition: procarray.c:332
void ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid)
Definition: procarray.c:395
void RecordKnownAssignedTransactionIds(TransactionId xid)
Definition: procarray.c:3169
size_t Size
Definition: c.h:356
bool MinimumActiveBackends(int min)
Definition: procarray.c:2681
VirtualTransactionId * GetVirtualXIDsDelayingChkpt(int *nvxids)
Definition: procarray.c:2250
void ProcArrayClearTransaction(PGPROC *proc)
Definition: procarray.c:604
int CountDBBackends(Oid databaseid)
Definition: procarray.c:2735
void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
Definition: procarray.c:2796
void ExpireTreeKnownAssignedTransactionIds(TransactionId xid, int nsubxids, TransactionId *subxids, TransactionId max_xid)
Definition: procarray.c:3242
ProcSignalReason
Definition: procsignal.h:30
void ProcArrayGetReplicationSlotXmin(TransactionId *xmin, TransactionId *catalog_xmin)
Definition: procarray.c:2982
void ExpireAllKnownAssignedTransactionIds(void)
Definition: procarray.c:3267
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:998
Definition: proc.h:94
VirtualTransactionId * GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid)
Definition: procarray.c:2558