1 /*-------------------------------------------------------------------------
4 * Definitions for hot standby mode.
7 * Portions Copyright (c) 1996-2009, 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.1 2009/12/19 01:32:44 sriggs Exp $
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/lock.h"
20 extern int vacuum_defer_cleanup_age;
22 /* cancel modes for ResolveRecoveryConflictWithVirtualXIDs */
23 #define CONFLICT_MODE_NOT_SET 0
24 #define CONFLICT_MODE_ERROR 1 /* Conflict can be resolved by canceling query */
25 #define CONFLICT_MODE_FATAL 2 /* Conflict can only be resolved by disconnecting session */
27 extern void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist,
28 char *reason, int cancel_mode);
30 extern void InitRecoveryTransactionEnvironment(void);
31 extern void ShutdownRecoveryTransactionEnvironment(void);
34 * Standby Rmgr (RM_STANDBY_ID)
36 * Standby recovery manager exists to perform actions that are required
37 * to make hot standby work. That includes logging AccessExclusiveLocks taken
38 * by transactions and running-xacts snapshots.
40 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
41 extern void StandbyReleaseLockTree(TransactionId xid,
42 int nsubxids, TransactionId *subxids);
43 extern void StandbyReleaseAllLocks(void);
44 extern void StandbyReleaseOldLocks(TransactionId removeXid);
49 #define XLOG_STANDBY_LOCK 0x00
50 #define XLOG_RUNNING_XACTS 0x10
52 typedef struct xl_standby_locks
54 int nlocks; /* number of entries in locks array */
55 xl_standby_lock locks[1]; /* VARIABLE LENGTH ARRAY */
59 * When we write running xact data to WAL, we use this structure.
61 typedef struct xl_running_xacts
63 int xcnt; /* # of xact ids in xids[] */
64 bool subxid_overflow; /* snapshot overflowed, subxids missing */
65 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
66 TransactionId oldestRunningXid; /* *not* oldestXmin */
68 TransactionId xids[1]; /* VARIABLE LENGTH ARRAY */
71 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
74 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
75 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
76 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
79 * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
80 * not quite. This has nothing at all to do with visibility on this server,
81 * so this is completely separate from snapmgr.c and snapmgr.h
82 * This data is important for creating the initial snapshot state on a
83 * standby server. We need lots more information than a normal snapshot,
84 * hence we use a specific data structure for our needs. This data
85 * is written to WAL as a separate record immediately after each
86 * checkpoint. That means that wherever we start a standby from we will
87 * almost immediately see the data we need to begin executing queries.
90 typedef struct RunningTransactionsData
92 int xcnt; /* # of xact ids in xids[] */
93 bool subxid_overflow; /* snapshot overflowed, subxids missing */
94 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
95 TransactionId oldestRunningXid; /* *not* oldestXmin */
97 TransactionId *xids; /* array of (sub)xids still running */
98 } RunningTransactionsData;
100 typedef RunningTransactionsData *RunningTransactions;
102 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
104 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
106 #endif /* STANDBY_H */