1 /*-------------------------------------------------------------------------
4 * Definitions for hot standby mode.
7 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/standby.h
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/lock.h"
19 #include "storage/procsignal.h"
20 #include "storage/relfilenode.h"
22 /* User-settable GUC parameters */
23 extern int vacuum_defer_cleanup_age;
24 extern int max_standby_archive_delay;
25 extern int max_standby_streaming_delay;
27 extern void InitRecoveryTransactionEnvironment(void);
28 extern void ShutdownRecoveryTransactionEnvironment(void);
30 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
32 extern void ResolveRecoveryConflictWithRemovedTransactionId(void);
33 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
34 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
36 extern void ResolveRecoveryConflictWithBufferPin(void);
37 extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason);
38 extern void CheckRecoveryConflictDeadlock(LWLockId partitionLock);
41 * Standby Rmgr (RM_STANDBY_ID)
43 * Standby recovery manager exists to perform actions that are required
44 * to make hot standby work. That includes logging AccessExclusiveLocks taken
45 * by transactions and running-xacts snapshots.
47 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
48 extern void StandbyReleaseLockTree(TransactionId xid,
49 int nsubxids, TransactionId *subxids);
50 extern void StandbyReleaseAllLocks(void);
51 extern void StandbyReleaseOldLocks(TransactionId removeXid);
56 #define XLOG_STANDBY_LOCK 0x00
57 #define XLOG_RUNNING_XACTS 0x10
59 typedef struct xl_standby_locks
61 int nlocks; /* number of entries in locks array */
62 xl_standby_lock locks[1]; /* VARIABLE LENGTH ARRAY */
66 * When we write running xact data to WAL, we use this structure.
68 typedef struct xl_running_xacts
70 int xcnt; /* # of xact ids in xids[] */
71 bool subxid_overflow; /* snapshot overflowed, subxids missing */
72 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
73 TransactionId oldestRunningXid; /* *not* oldestXmin */
74 TransactionId latestCompletedXid; /* so we can set xmax */
76 TransactionId xids[1]; /* VARIABLE LENGTH ARRAY */
79 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
82 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
83 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
84 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
87 * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
88 * not quite. This has nothing at all to do with visibility on this server,
89 * so this is completely separate from snapmgr.c and snapmgr.h.
90 * This data is important for creating the initial snapshot state on a
91 * standby server. We need lots more information than a normal snapshot,
92 * hence we use a specific data structure for our needs. This data
93 * is written to WAL as a separate record immediately after each
94 * checkpoint. That means that wherever we start a standby from we will
95 * almost immediately see the data we need to begin executing queries.
98 typedef struct RunningTransactionsData
100 int xcnt; /* # of xact ids in xids[] */
101 bool subxid_overflow; /* snapshot overflowed, subxids missing */
102 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
103 TransactionId oldestRunningXid; /* *not* oldestXmin */
104 TransactionId latestCompletedXid; /* so we can set xmax */
106 TransactionId *xids; /* array of (sub)xids still running */
107 } RunningTransactionsData;
109 typedef RunningTransactionsData *RunningTransactions;
111 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
112 extern void LogAccessExclusiveLockPrepare(void);
114 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
116 #endif /* STANDBY_H */