1 /*-------------------------------------------------------------------------
4 * Definitions for hot standby mode.
7 * Portions Copyright (c) 1996-2012, 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 ResolveRecoveryConflictWithTablespace(Oid tsid);
33 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
35 extern void ResolveRecoveryConflictWithBufferPin(void);
36 extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason);
37 extern void CheckRecoveryConflictDeadlock(void);
40 * Standby Rmgr (RM_STANDBY_ID)
42 * Standby recovery manager exists to perform actions that are required
43 * to make hot standby work. That includes logging AccessExclusiveLocks taken
44 * by transactions and running-xacts snapshots.
46 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
47 extern void StandbyReleaseLockTree(TransactionId xid,
48 int nsubxids, TransactionId *subxids);
49 extern void StandbyReleaseAllLocks(void);
50 extern void StandbyReleaseOldLocks(int nxids, TransactionId *xids);
55 #define XLOG_STANDBY_LOCK 0x00
56 #define XLOG_RUNNING_XACTS 0x10
58 typedef struct xl_standby_locks
60 int nlocks; /* number of entries in locks array */
61 xl_standby_lock locks[1]; /* VARIABLE LENGTH ARRAY */
65 * When we write running xact data to WAL, we use this structure.
67 typedef struct xl_running_xacts
69 int xcnt; /* # of xact ids in xids[] */
70 bool subxid_overflow; /* snapshot overflowed, subxids missing */
71 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
72 TransactionId oldestRunningXid; /* *not* oldestXmin */
73 TransactionId latestCompletedXid; /* so we can set xmax */
75 TransactionId xids[1]; /* VARIABLE LENGTH ARRAY */
78 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
81 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
82 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
83 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
86 * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
87 * not quite. This has nothing at all to do with visibility on this server,
88 * so this is completely separate from snapmgr.c and snapmgr.h.
89 * This data is important for creating the initial snapshot state on a
90 * standby server. We need lots more information than a normal snapshot,
91 * hence we use a specific data structure for our needs. This data
92 * is written to WAL as a separate record immediately after each
93 * checkpoint. That means that wherever we start a standby from we will
94 * almost immediately see the data we need to begin executing queries.
97 typedef struct RunningTransactionsData
99 int xcnt; /* # of xact ids in xids[] */
100 bool subxid_overflow; /* snapshot overflowed, subxids missing */
101 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
102 TransactionId oldestRunningXid; /* *not* oldestXmin */
103 TransactionId latestCompletedXid; /* so we can set xmax */
105 TransactionId *xids; /* array of (sub)xids still running */
106 } RunningTransactionsData;
108 typedef RunningTransactionsData *RunningTransactions;
110 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
111 extern void LogAccessExclusiveLockPrepare(void);
113 extern void LogStandbySnapshot(TransactionId *nextXid);
115 #endif /* STANDBY_H */