1 /*-------------------------------------------------------------------------
4 * postgres transaction access method support code
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
17 #include "access/xlogdefs.h"
21 * Special transaction ID values
23 * BootstrapTransactionId is the XID for "bootstrap" operations, and
24 * FrozenTransactionId is used for very old tuples. Both should
25 * always be considered valid.
27 * FirstNormalTransactionId is the first "normal" transaction id.
28 * Note: if you need to change it, you must change pg_class.h as well.
31 #define InvalidTransactionId ((TransactionId) 0)
32 #define BootstrapTransactionId ((TransactionId) 1)
33 #define FrozenTransactionId ((TransactionId) 2)
34 #define FirstNormalTransactionId ((TransactionId) 3)
35 #define MaxTransactionId ((TransactionId) 0xFFFFFFFF)
38 * transaction ID manipulation macros
41 #define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId)
42 #define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId)
43 #define TransactionIdEquals(id1, id2) ((id1) == (id2))
44 #define TransactionIdStore(xid, dest) (*(dest) = (xid))
45 #define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
47 /* advance a transaction ID variable, handling wraparound correctly */
48 #define TransactionIdAdvance(dest) \
51 if ((dest) < FirstNormalTransactionId) \
52 (dest) = FirstNormalTransactionId; \
55 /* back up a transaction ID variable, handling wraparound correctly */
56 #define TransactionIdRetreat(dest) \
59 } while ((dest) < FirstNormalTransactionId)
63 * Object ID (OID) zero is InvalidOid.
65 * OIDs 1-9999 are reserved for manual assignment (see the files
66 * in src/include/catalog/).
68 * OIDS 10000-16383 are reserved for assignment during initdb
69 * using the OID generator. (We start the generator at 10000.)
71 * OIDs beginning at 16384 are assigned from the OID generator
72 * during normal multiuser operation. (We force the generator up to
73 * 16384 as soon as we are in normal operation.)
75 * The choices of 10000 and 16384 are completely arbitrary, and can be moved
76 * if we run low on OIDs in either category. Changing the macros below
77 * should be sufficient to do this.
79 * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
80 * and resume with 16384. This minimizes the odds of OID conflict, by not
81 * reassigning OIDs that might have been assigned during initdb.
84 #define FirstBootstrapObjectId 10000
85 #define FirstNormalObjectId 16384
88 * VariableCache is a data structure in shared memory that is used to track
89 * OID and XID assignment state. For largely historical reasons, there is
90 * just one struct with different fields that are protected by different
93 * Note: xidWrapLimit and limit_datname are not "active" values, but are
94 * used just to generate useful messages when xidWarnLimit or xidStopLimit
97 typedef struct VariableCacheData
100 * These fields are protected by OidGenLock.
102 Oid nextOid
; /* next OID to assign */
103 uint32 oidCount
; /* OIDs available before must do XLOG work */
106 * These fields are protected by XidGenLock.
108 TransactionId nextXid
; /* next XID to assign */
110 TransactionId oldestXid
; /* cluster-wide minimum datfrozenxid */
111 TransactionId xidVacLimit
; /* start forcing autovacuums here */
112 TransactionId xidWarnLimit
; /* start complaining here */
113 TransactionId xidStopLimit
; /* refuse to advance nextXid beyond here */
114 TransactionId xidWrapLimit
; /* where the world ends */
115 NameData limit_datname
; /* database that needs vacuumed first */
118 * These fields are protected by ProcArrayLock.
120 TransactionId latestCompletedXid
; /* newest XID that has committed or
124 typedef VariableCacheData
*VariableCache
;
128 * extern declarations
132 /* in transam/varsup.c */
133 extern VariableCache ShmemVariableCache
;
137 * prototypes for functions in transam/transam.c
139 extern bool TransactionIdDidCommit(TransactionId transactionId
);
140 extern bool TransactionIdDidAbort(TransactionId transactionId
);
141 extern bool TransactionIdIsKnownCompleted(TransactionId transactionId
);
142 extern void TransactionIdCommit(TransactionId transactionId
);
143 extern void TransactionIdAsyncCommit(TransactionId transactionId
, XLogRecPtr lsn
);
144 extern void TransactionIdAbort(TransactionId transactionId
);
145 extern void TransactionIdSubCommit(TransactionId transactionId
);
146 extern void TransactionIdCommitTree(int nxids
, TransactionId
*xids
);
147 extern void TransactionIdAsyncCommitTree(int nxids
, TransactionId
*xids
, XLogRecPtr lsn
);
148 extern void TransactionIdAbortTree(int nxids
, TransactionId
*xids
);
149 extern bool TransactionIdPrecedes(TransactionId id1
, TransactionId id2
);
150 extern bool TransactionIdPrecedesOrEquals(TransactionId id1
, TransactionId id2
);
151 extern bool TransactionIdFollows(TransactionId id1
, TransactionId id2
);
152 extern bool TransactionIdFollowsOrEquals(TransactionId id1
, TransactionId id2
);
153 extern TransactionId
TransactionIdLatest(TransactionId mainxid
,
154 int nxids
, const TransactionId
*xids
);
155 extern XLogRecPtr
TransactionIdGetCommitLSN(TransactionId xid
);
157 /* in transam/varsup.c */
158 extern TransactionId
GetNewTransactionId(bool isSubXact
);
159 extern TransactionId
ReadNewTransactionId(void);
160 extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid
,
161 Name oldest_datname
);
162 extern Oid
GetNewObjectId(void);
164 #endif /* TRAMSAM_H */