1996-08-27 23:50:29 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* transam.h
|
2001-07-12 06:11:13 +02:00
|
|
|
* postgres transaction access method support code
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2007-01-05 23:20:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2007-09-08 22:31:15 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/transam.h,v 1.62 2007/09/08 20:31:15 tgl Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TRANSAM_H
|
|
|
|
#define TRANSAM_H
|
|
|
|
|
2007-08-02 00:45:09 +02:00
|
|
|
#include "access/xlogdefs.h"
|
|
|
|
|
2001-07-12 06:11:13 +02:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/* ----------------
|
2001-07-12 06:11:13 +02:00
|
|
|
* Special transaction ID values
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2001-08-25 20:52:43 +02:00
|
|
|
* BootstrapTransactionId is the XID for "bootstrap" operations, and
|
|
|
|
* FrozenTransactionId is used for very old tuples. Both should
|
2001-08-24 01:06:38 +02:00
|
|
|
* always be considered valid.
|
2001-07-12 06:11:13 +02:00
|
|
|
*
|
2001-08-24 01:06:38 +02:00
|
|
|
* FirstNormalTransactionId is the first "normal" transaction id.
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
* Note: if you need to change it, you must change pg_class.h as well.
|
2001-07-12 06:11:13 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2001-08-24 01:06:38 +02:00
|
|
|
#define InvalidTransactionId ((TransactionId) 0)
|
2001-08-25 20:52:43 +02:00
|
|
|
#define BootstrapTransactionId ((TransactionId) 1)
|
|
|
|
#define FrozenTransactionId ((TransactionId) 2)
|
|
|
|
#define FirstNormalTransactionId ((TransactionId) 3)
|
2001-08-26 18:56:03 +02:00
|
|
|
#define MaxTransactionId ((TransactionId) 0xFFFFFFFF)
|
2001-07-12 06:11:13 +02:00
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* transaction ID manipulation macros
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2001-08-24 01:06:38 +02:00
|
|
|
#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId)
|
|
|
|
#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId)
|
2001-08-26 18:56:03 +02:00
|
|
|
#define TransactionIdEquals(id1, id2) ((id1) == (id2))
|
2001-08-24 01:06:38 +02:00
|
|
|
#define TransactionIdStore(xid, dest) (*(dest) = (xid))
|
2001-10-25 07:50:21 +02:00
|
|
|
#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
|
2007-09-08 22:31:15 +02:00
|
|
|
|
2001-08-24 01:06:38 +02:00
|
|
|
/* advance a transaction ID variable, handling wraparound correctly */
|
|
|
|
#define TransactionIdAdvance(dest) \
|
|
|
|
do { \
|
|
|
|
(dest)++; \
|
|
|
|
if ((dest) < FirstNormalTransactionId) \
|
|
|
|
(dest) = FirstNormalTransactionId; \
|
|
|
|
} while(0)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2007-09-08 22:31:15 +02:00
|
|
|
/* back up a transaction ID variable, handling wraparound correctly */
|
|
|
|
#define TransactionIdRetreat(dest) \
|
|
|
|
do { \
|
|
|
|
(dest)--; \
|
|
|
|
} while ((dest) < FirstNormalTransactionId)
|
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/* ----------
|
2001-08-10 20:57:42 +02:00
|
|
|
* Object ID (OID) zero is InvalidOid.
|
|
|
|
*
|
|
|
|
* OIDs 1-9999 are reserved for manual assignment (see the files
|
|
|
|
* in src/include/catalog/).
|
|
|
|
*
|
2005-04-13 20:54:57 +02:00
|
|
|
* OIDS 10000-16383 are reserved for assignment during initdb
|
|
|
|
* using the OID generator. (We start the generator at 10000.)
|
2001-08-10 20:57:42 +02:00
|
|
|
*
|
2005-04-13 20:54:57 +02:00
|
|
|
* OIDs beginning at 16384 are assigned from the OID generator
|
2005-10-15 04:49:52 +02:00
|
|
|
* during normal multiuser operation. (We force the generator up to
|
2005-04-13 20:54:57 +02:00
|
|
|
* 16384 as soon as we are in normal operation.)
|
2001-08-10 20:57:42 +02:00
|
|
|
*
|
|
|
|
* The choices of 10000 and 16384 are completely arbitrary, and can be moved
|
|
|
|
* if we run low on OIDs in either category. Changing the macros below
|
|
|
|
* should be sufficient to do this.
|
|
|
|
*
|
2005-04-13 20:54:57 +02:00
|
|
|
* NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
|
2001-08-10 20:57:42 +02:00
|
|
|
* and resume with 16384. This minimizes the odds of OID conflict, by not
|
|
|
|
* reassigning OIDs that might have been assigned during initdb.
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------
|
|
|
|
*/
|
2005-04-13 20:54:57 +02:00
|
|
|
#define FirstBootstrapObjectId 10000
|
|
|
|
#define FirstNormalObjectId 16384
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-07-21 08:17:39 +02:00
|
|
|
/*
|
2007-09-08 22:31:15 +02:00
|
|
|
* VariableCache is a data structure in shared memory that is used to track
|
|
|
|
* OID and XID assignment state. For largely historical reasons, there is
|
|
|
|
* just one struct with different fields that are protected by different
|
|
|
|
* LWLocks.
|
2005-02-20 03:22:07 +01:00
|
|
|
*
|
|
|
|
* Note: xidWrapLimit and limit_datname are not "active" values, but are
|
|
|
|
* used just to generate useful messages when xidWarnLimit or xidStopLimit
|
|
|
|
* are exceeded.
|
1998-07-21 08:17:39 +02:00
|
|
|
*/
|
|
|
|
typedef struct VariableCacheData
|
|
|
|
{
|
2007-09-08 22:31:15 +02:00
|
|
|
/*
|
|
|
|
* These fields are protected by OidGenLock.
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid nextOid; /* next OID to assign */
|
|
|
|
uint32 oidCount; /* OIDs available before must do XLOG work */
|
2007-09-08 22:31:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These fields are protected by XidGenLock.
|
|
|
|
*/
|
2005-02-20 03:22:07 +01:00
|
|
|
TransactionId nextXid; /* next XID to assign */
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
|
|
|
|
TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
|
|
|
|
TransactionId xidVacLimit; /* start forcing autovacuums here */
|
2005-10-15 04:49:52 +02:00
|
|
|
TransactionId xidWarnLimit; /* start complaining here */
|
|
|
|
TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
|
|
|
|
TransactionId xidWrapLimit; /* where the world ends */
|
2005-02-20 03:22:07 +01:00
|
|
|
NameData limit_datname; /* database that needs vacuumed first */
|
2007-09-08 22:31:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These fields are protected by ProcArrayLock.
|
|
|
|
*/
|
|
|
|
TransactionId latestCompletedXid; /* newest XID that has committed or
|
|
|
|
* aborted */
|
1999-05-26 00:43:53 +02:00
|
|
|
} VariableCacheData;
|
1998-07-21 08:17:39 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
typedef VariableCacheData *VariableCache;
|
1998-07-21 08:17:39 +02:00
|
|
|
|
2001-07-12 06:11:13 +02:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* extern declarations
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
2002-05-25 22:00:12 +02:00
|
|
|
/* in transam/varsup.c */
|
|
|
|
extern VariableCache ShmemVariableCache;
|
|
|
|
|
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/*
|
|
|
|
* prototypes for functions in transam/transam.c
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool TransactionIdDidCommit(TransactionId transactionId);
|
|
|
|
extern bool TransactionIdDidAbort(TransactionId transactionId);
|
|
|
|
extern void TransactionIdCommit(TransactionId transactionId);
|
2007-08-02 00:45:09 +02:00
|
|
|
extern void TransactionIdAsyncCommit(TransactionId transactionId, XLogRecPtr lsn);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void TransactionIdAbort(TransactionId transactionId);
|
2004-07-01 02:52:04 +02:00
|
|
|
extern void TransactionIdSubCommit(TransactionId transactionId);
|
|
|
|
extern void TransactionIdCommitTree(int nxids, TransactionId *xids);
|
2007-08-02 00:45:09 +02:00
|
|
|
extern void TransactionIdAsyncCommitTree(int nxids, TransactionId *xids, XLogRecPtr lsn);
|
2004-07-01 02:52:04 +02:00
|
|
|
extern void TransactionIdAbortTree(int nxids, TransactionId *xids);
|
2001-08-26 18:56:03 +02:00
|
|
|
extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2);
|
|
|
|
extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);
|
|
|
|
extern bool TransactionIdFollows(TransactionId id1, TransactionId id2);
|
|
|
|
extern bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2);
|
2007-09-08 22:31:15 +02:00
|
|
|
extern TransactionId TransactionIdLatest(TransactionId mainxid,
|
|
|
|
int nxids, const TransactionId *xids);
|
2007-08-02 00:45:09 +02:00
|
|
|
extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/* in transam/varsup.c */
|
2004-07-01 02:52:04 +02:00
|
|
|
extern TransactionId GetNewTransactionId(bool isSubXact);
|
2001-08-25 20:52:43 +02:00
|
|
|
extern TransactionId ReadNewTransactionId(void);
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
|
2005-10-15 04:49:52 +02:00
|
|
|
Name oldest_datname);
|
2001-08-10 20:57:42 +02:00
|
|
|
extern Oid GetNewObjectId(void);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* TRAMSAM_H */
|