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.10 2010/05/13 11:15:38 sriggs Exp $
12 *-------------------------------------------------------------------------
17 #include "access/xlog.h"
18 #include "storage/lock.h"
19 #include "storage/procsignal.h"
20 #include "storage/relfilenode.h"
22 extern int vacuum_defer_cleanup_age;
24 extern void InitRecoveryTransactionEnvironment(void);
25 extern void ShutdownRecoveryTransactionEnvironment(void);
27 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
29 extern void ResolveRecoveryConflictWithRemovedTransactionId(void);
30 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
31 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
33 extern void ResolveRecoveryConflictWithBufferPin(void);
34 extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason);
35 extern void CheckRecoveryConflictDeadlock(LWLockId partitionLock);
38 * Standby Rmgr (RM_STANDBY_ID)
40 * Standby recovery manager exists to perform actions that are required
41 * to make hot standby work. That includes logging AccessExclusiveLocks taken
42 * by transactions and running-xacts snapshots.
44 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
45 extern void StandbyReleaseLockTree(TransactionId xid,
46 int nsubxids, TransactionId *subxids);
47 extern void StandbyReleaseAllLocks(void);
48 extern void StandbyReleaseOldLocks(TransactionId removeXid);
53 #define XLOG_STANDBY_LOCK 0x00
54 #define XLOG_RUNNING_XACTS 0x10
56 typedef struct xl_standby_locks
58 int nlocks; /* number of entries in locks array */
59 xl_standby_lock locks[1]; /* VARIABLE LENGTH ARRAY */
63 * When we write running xact data to WAL, we use this structure.
65 typedef struct xl_running_xacts
67 int xcnt; /* # of xact ids in xids[] */
68 bool subxid_overflow; /* snapshot overflowed, subxids missing */
69 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
70 TransactionId oldestRunningXid; /* *not* oldestXmin */
71 TransactionId latestCompletedXid; /* so we can set xmax */
73 TransactionId xids[1]; /* VARIABLE LENGTH ARRAY */
76 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
79 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
80 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
81 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
84 * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
85 * not quite. This has nothing at all to do with visibility on this server,
86 * so this is completely separate from snapmgr.c and snapmgr.h
87 * This data is important for creating the initial snapshot state on a
88 * standby server. We need lots more information than a normal snapshot,
89 * hence we use a specific data structure for our needs. This data
90 * is written to WAL as a separate record immediately after each
91 * checkpoint. That means that wherever we start a standby from we will
92 * almost immediately see the data we need to begin executing queries.
95 typedef struct RunningTransactionsData
97 int xcnt; /* # of xact ids in xids[] */
98 bool subxid_overflow; /* snapshot overflowed, subxids missing */
99 TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
100 TransactionId oldestRunningXid; /* *not* oldestXmin */
101 TransactionId latestCompletedXid; /* so we can set xmax */
103 TransactionId *xids; /* array of (sub)xids still running */
104 } RunningTransactionsData;
106 typedef RunningTransactionsData *RunningTransactions;
108 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
110 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
112 #endif /* STANDBY_H */