| 1 | /*------------------------------------------------------------------------- | 
|---|
| 2 | * | 
|---|
| 3 | * procarray.h | 
|---|
| 4 | *	  POSTGRES process array definitions. | 
|---|
| 5 | * | 
|---|
| 6 | * | 
|---|
| 7 | * Portions Copyright (c) 1996-2019, 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 | 
|---|
| 31 | * vacuum */ | 
|---|
| 32 | #define		PROCARRAY_ANALYZE_FLAG			0x04	/* currently running | 
|---|
| 33 | * analyze */ | 
|---|
| 34 | #define		PROCARRAY_LOGICAL_DECODING_FLAG 0x10	/* currently doing logical | 
|---|
| 35 | * decoding outside xact */ | 
|---|
| 36 |  | 
|---|
| 37 | #define		PROCARRAY_SLOTS_XMIN			0x20	/* replication slot xmin, | 
|---|
| 38 | * catalog_xmin */ | 
|---|
| 39 | /* | 
|---|
| 40 | * Only flags in PROCARRAY_PROC_FLAGS_MASK are considered when matching | 
|---|
| 41 | * PGXACT->vacuumFlags. Other flags are used for different purposes and | 
|---|
| 42 | * have no corresponding PROC flag equivalent. | 
|---|
| 43 | */ | 
|---|
| 44 | #define		PROCARRAY_PROC_FLAGS_MASK	(PROCARRAY_VACUUM_FLAG | \ | 
|---|
| 45 | PROCARRAY_ANALYZE_FLAG | \ | 
|---|
| 46 | PROCARRAY_LOGICAL_DECODING_FLAG) | 
|---|
| 47 |  | 
|---|
| 48 | /* Use the following flags as an input "flags" to GetOldestXmin function */ | 
|---|
| 49 | /* Consider all backends except for logical decoding ones which manage xmin separately */ | 
|---|
| 50 | #define		PROCARRAY_FLAGS_DEFAULT			PROCARRAY_LOGICAL_DECODING_FLAG | 
|---|
| 51 | /* Ignore vacuum backends */ | 
|---|
| 52 | #define		PROCARRAY_FLAGS_VACUUM			PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG | 
|---|
| 53 | /* Ignore analyze backends */ | 
|---|
| 54 | #define		PROCARRAY_FLAGS_ANALYZE			PROCARRAY_FLAGS_DEFAULT | PROCARRAY_ANALYZE_FLAG | 
|---|
| 55 | /* Ignore both vacuum and analyze backends */ | 
|---|
| 56 | #define		PROCARRAY_FLAGS_VACUUM_ANALYZE	PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG | PROCARRAY_ANALYZE_FLAG | 
|---|
| 57 |  | 
|---|
| 58 | extern Size ProcArrayShmemSize(void); | 
|---|
| 59 | extern void CreateSharedProcArray(void); | 
|---|
| 60 | extern void ProcArrayAdd(PGPROC *proc); | 
|---|
| 61 | extern void ProcArrayRemove(PGPROC *proc, TransactionId latestXid); | 
|---|
| 62 |  | 
|---|
| 63 | extern void ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid); | 
|---|
| 64 | extern void ProcArrayClearTransaction(PGPROC *proc); | 
|---|
| 65 |  | 
|---|
| 66 | extern void ProcArrayInitRecovery(TransactionId initializedUptoXID); | 
|---|
| 67 | extern void ProcArrayApplyRecoveryInfo(RunningTransactions running); | 
|---|
| 68 | extern void ProcArrayApplyXidAssignment(TransactionId topxid, | 
|---|
| 69 | int nsubxids, TransactionId *subxids); | 
|---|
| 70 |  | 
|---|
| 71 | extern void RecordKnownAssignedTransactionIds(TransactionId xid); | 
|---|
| 72 | extern void ExpireTreeKnownAssignedTransactionIds(TransactionId xid, | 
|---|
| 73 | int nsubxids, TransactionId *subxids, | 
|---|
| 74 | TransactionId max_xid); | 
|---|
| 75 | extern void ExpireAllKnownAssignedTransactionIds(void); | 
|---|
| 76 | extern void ExpireOldKnownAssignedTransactionIds(TransactionId xid); | 
|---|
| 77 |  | 
|---|
| 78 | extern int	GetMaxSnapshotXidCount(void); | 
|---|
| 79 | extern int	GetMaxSnapshotSubxidCount(void); | 
|---|
| 80 |  | 
|---|
| 81 | extern Snapshot GetSnapshotData(Snapshot snapshot); | 
|---|
| 82 |  | 
|---|
| 83 | extern bool ProcArrayInstallImportedXmin(TransactionId xmin, | 
|---|
| 84 | VirtualTransactionId *sourcevxid); | 
|---|
| 85 | extern bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc); | 
|---|
| 86 |  | 
|---|
| 87 | extern RunningTransactions GetRunningTransactionData(void); | 
|---|
| 88 |  | 
|---|
| 89 | extern bool TransactionIdIsInProgress(TransactionId xid); | 
|---|
| 90 | extern bool TransactionIdIsActive(TransactionId xid); | 
|---|
| 91 | extern TransactionId GetOldestXmin(Relation rel, int flags); | 
|---|
| 92 | extern TransactionId GetOldestActiveTransactionId(void); | 
|---|
| 93 | extern TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly); | 
|---|
| 94 |  | 
|---|
| 95 | extern VirtualTransactionId *GetVirtualXIDsDelayingChkpt(int *nvxids); | 
|---|
| 96 | extern bool HaveVirtualXIDsDelayingChkpt(VirtualTransactionId *vxids, int nvxids); | 
|---|
| 97 |  | 
|---|
| 98 | extern PGPROC *BackendPidGetProc(int pid); | 
|---|
| 99 | extern PGPROC *BackendPidGetProcWithLock(int pid); | 
|---|
| 100 | extern int	BackendXidGetPid(TransactionId xid); | 
|---|
| 101 | extern bool IsBackendPid(int pid); | 
|---|
| 102 |  | 
|---|
| 103 | extern VirtualTransactionId *GetCurrentVirtualXIDs(TransactionId limitXmin, | 
|---|
| 104 | bool excludeXmin0, bool allDbs, int excludeVacuum, | 
|---|
| 105 | int *nvxids); | 
|---|
| 106 | extern VirtualTransactionId *GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid); | 
|---|
| 107 | extern pid_t CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode); | 
|---|
| 108 |  | 
|---|
| 109 | extern bool MinimumActiveBackends(int min); | 
|---|
| 110 | extern int	CountDBBackends(Oid databaseid); | 
|---|
| 111 | extern int	CountDBConnections(Oid databaseid); | 
|---|
| 112 | extern void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending); | 
|---|
| 113 | extern int	CountUserBackends(Oid roleid); | 
|---|
| 114 | extern bool CountOtherDBBackends(Oid databaseId, | 
|---|
| 115 | int *nbackends, int *nprepared); | 
|---|
| 116 |  | 
|---|
| 117 | extern void XidCacheRemoveRunningXids(TransactionId xid, | 
|---|
| 118 | int nxids, const TransactionId *xids, | 
|---|
| 119 | TransactionId latestXid); | 
|---|
| 120 |  | 
|---|
| 121 | extern void ProcArraySetReplicationSlotXmin(TransactionId xmin, | 
|---|
| 122 | TransactionId catalog_xmin, bool already_locked); | 
|---|
| 123 |  | 
|---|
| 124 | extern void ProcArrayGetReplicationSlotXmin(TransactionId *xmin, | 
|---|
| 125 | TransactionId *catalog_xmin); | 
|---|
| 126 |  | 
|---|
| 127 | #endif							/* PROCARRAY_H */ | 
|---|
| 128 |  | 
|---|