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.5 2010/01/23 16:37:12 sriggs Exp $
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/lock.h"
20 extern int vacuum_defer_cleanup_age;
22 extern void InitRecoveryTransactionEnvironment(void);
23 extern void ShutdownRecoveryTransactionEnvironment(void);
25 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid);
26 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
27 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
29 extern void ResolveRecoveryConflictWithBufferPin(void);
30 extern void SendRecoveryConflictWithBufferPin(void);
33 * Standby Rmgr (RM_STANDBY_ID)
35 * Standby recovery manager exists to perform actions that are required
36 * to make hot standby work. That includes logging AccessExclusiveLocks taken
37 * by transactions and running-xacts snapshots.
39 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
40 extern void StandbyReleaseLockTree(TransactionId xid,
41 int nsubxids, TransactionId *subxids);
42 extern void StandbyReleaseAllLocks(void);
43 extern void StandbyReleaseOldLocks(TransactionId removeXid);
48 #define XLOG_STANDBY_LOCK 0x00
49 #define XLOG_RUNNING_XACTS 0x10
51 typedef struct xl_standby_locks
53 int nlocks; /* number of entries in locks array */
54 xl_standby_lock locks[1]; /* VARIABLE LENGTH ARRAY */
58 * When we write running xact data to WAL, we use this structure.
60 typedef struct xl_running_xacts
62 int xcnt; /* # of xact ids in xids[] */
63 bool subxid_overflow; /* snapshot overflowed, subxids missing */
64 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
65 TransactionId oldestRunningXid; /* *not* oldestXmin */
67 TransactionId xids[1]; /* VARIABLE LENGTH ARRAY */
70 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
73 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
74 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
75 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
78 * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
79 * not quite. This has nothing at all to do with visibility on this server,
80 * so this is completely separate from snapmgr.c and snapmgr.h
81 * This data is important for creating the initial snapshot state on a
82 * standby server. We need lots more information than a normal snapshot,
83 * hence we use a specific data structure for our needs. This data
84 * is written to WAL as a separate record immediately after each
85 * checkpoint. That means that wherever we start a standby from we will
86 * almost immediately see the data we need to begin executing queries.
89 typedef struct RunningTransactionsData
91 int xcnt; /* # of xact ids in xids[] */
92 bool subxid_overflow; /* snapshot overflowed, subxids missing */
93 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
94 TransactionId oldestRunningXid; /* *not* oldestXmin */
96 TransactionId *xids; /* array of (sub)xids still running */
97 } RunningTransactionsData;
99 typedef RunningTransactionsData *RunningTransactions;
101 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
103 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
105 #endif /* STANDBY_H */