1 /*-------------------------------------------------------------------------
4 * Definitions for hot standby mode.
7 * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/storage/standby.h,v 1.4 2010/01/16 10:05:57 sriggs Exp $
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/lock.h"
20 extern int vacuum_defer_cleanup_age;
22 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid);
23 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
24 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
26 extern void InitRecoveryTransactionEnvironment(void);
27 extern void ShutdownRecoveryTransactionEnvironment(void);
30 * Standby Rmgr (RM_STANDBY_ID)
32 * Standby recovery manager exists to perform actions that are required
33 * to make hot standby work. That includes logging AccessExclusiveLocks taken
34 * by transactions and running-xacts snapshots.
36 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
37 extern void StandbyReleaseLockTree(TransactionId xid,
38 int nsubxids, TransactionId *subxids);
39 extern void StandbyReleaseAllLocks(void);
40 extern void StandbyReleaseOldLocks(TransactionId removeXid);
45 #define XLOG_STANDBY_LOCK 0x00
46 #define XLOG_RUNNING_XACTS 0x10
48 typedef struct xl_standby_locks
50 int nlocks; /* number of entries in locks array */
51 xl_standby_lock locks[1]; /* VARIABLE LENGTH ARRAY */
55 * When we write running xact data to WAL, we use this structure.
57 typedef struct xl_running_xacts
59 int xcnt; /* # of xact ids in xids[] */
60 bool subxid_overflow; /* snapshot overflowed, subxids missing */
61 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
62 TransactionId oldestRunningXid; /* *not* oldestXmin */
64 TransactionId xids[1]; /* VARIABLE LENGTH ARRAY */
67 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
70 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
71 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
72 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
75 * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
76 * not quite. This has nothing at all to do with visibility on this server,
77 * so this is completely separate from snapmgr.c and snapmgr.h
78 * This data is important for creating the initial snapshot state on a
79 * standby server. We need lots more information than a normal snapshot,
80 * hence we use a specific data structure for our needs. This data
81 * is written to WAL as a separate record immediately after each
82 * checkpoint. That means that wherever we start a standby from we will
83 * almost immediately see the data we need to begin executing queries.
86 typedef struct RunningTransactionsData
88 int xcnt; /* # of xact ids in xids[] */
89 bool subxid_overflow; /* snapshot overflowed, subxids missing */
90 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
91 TransactionId oldestRunningXid; /* *not* oldestXmin */
93 TransactionId *xids; /* array of (sub)xids still running */
94 } RunningTransactionsData;
96 typedef RunningTransactionsData *RunningTransactions;
98 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
100 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
102 #endif /* STANDBY_H */