]> granicus.if.org Git - postgresql/blob - src/include/storage/standby.h
Stamp copyrights for year 2011.
[postgresql] / src / include / storage / standby.h
1 /*-------------------------------------------------------------------------
2  *
3  * standby.h
4  *        Definitions for hot standby mode.
5  *
6  *
7  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/standby.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef STANDBY_H
15 #define STANDBY_H
16
17 #include "access/xlog.h"
18 #include "storage/lock.h"
19 #include "storage/procsignal.h"
20 #include "storage/relfilenode.h"
21
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;
26
27 extern void InitRecoveryTransactionEnvironment(void);
28 extern void ShutdownRecoveryTransactionEnvironment(void);
29
30 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
31                                                                         RelFileNode node);
32 extern void ResolveRecoveryConflictWithRemovedTransactionId(void);
33 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
34 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
35
36 extern void ResolveRecoveryConflictWithBufferPin(void);
37 extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason);
38 extern void CheckRecoveryConflictDeadlock(LWLockId partitionLock);
39
40 /*
41  * Standby Rmgr (RM_STANDBY_ID)
42  *
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.
46  */
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);
52
53 /*
54  * XLOG message types
55  */
56 #define XLOG_STANDBY_LOCK                       0x00
57 #define XLOG_RUNNING_XACTS                      0x10
58
59 typedef struct xl_standby_locks
60 {
61         int                     nlocks;                 /* number of entries in locks array */
62         xl_standby_lock locks[1];       /* VARIABLE LENGTH ARRAY */
63 } xl_standby_locks;
64
65 /*
66  * When we write running xact data to WAL, we use this structure.
67  */
68 typedef struct xl_running_xacts
69 {
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 */
75
76         TransactionId xids[1];          /* VARIABLE LENGTH ARRAY */
77 } xl_running_xacts;
78
79 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
80
81
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);
85
86 /*
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.
96  */
97
98 typedef struct RunningTransactionsData
99 {
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 */
105
106         TransactionId *xids;            /* array of (sub)xids still running */
107 } RunningTransactionsData;
108
109 typedef RunningTransactionsData *RunningTransactions;
110
111 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
112 extern void LogAccessExclusiveLockPrepare(void);
113
114 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
115
116 #endif   /* STANDBY_H */