]> granicus.if.org Git - postgresql/blob - src/include/storage/standby.h
Allow read only connections during recovery, known as Hot Standby.
[postgresql] / src / include / storage / standby.h
1 /*-------------------------------------------------------------------------
2  *
3  * standby.h
4  *        Definitions for hot standby mode.
5  *
6  *
7  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/standby.h,v 1.1 2009/12/19 01:32:44 sriggs Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef STANDBY_H
15 #define STANDBY_H
16
17 #include "access/xlog.h"
18 #include "storage/lock.h"
19
20 extern int      vacuum_defer_cleanup_age;
21
22 /* cancel modes for ResolveRecoveryConflictWithVirtualXIDs */
23 #define CONFLICT_MODE_NOT_SET           0
24 #define CONFLICT_MODE_ERROR                     1       /* Conflict can be resolved by canceling query */
25 #define CONFLICT_MODE_FATAL                     2       /* Conflict can only be resolved by disconnecting session */
26
27 extern void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist,
28                                                                            char *reason, int cancel_mode);
29
30 extern void InitRecoveryTransactionEnvironment(void);
31 extern void ShutdownRecoveryTransactionEnvironment(void);
32
33 /*
34  * Standby Rmgr (RM_STANDBY_ID)
35  *
36  * Standby recovery manager exists to perform actions that are required
37  * to make hot standby work. That includes logging AccessExclusiveLocks taken
38  * by transactions and running-xacts snapshots.
39  */
40 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
41 extern void StandbyReleaseLockTree(TransactionId xid,
42                                                                    int nsubxids, TransactionId *subxids);
43 extern void StandbyReleaseAllLocks(void);
44 extern void StandbyReleaseOldLocks(TransactionId removeXid);
45
46 /*
47  * XLOG message types
48  */
49 #define XLOG_STANDBY_LOCK                       0x00
50 #define XLOG_RUNNING_XACTS                      0x10
51
52 typedef struct xl_standby_locks
53 {
54         int                             nlocks;         /* number of entries in locks array */
55         xl_standby_lock locks[1];       /* VARIABLE LENGTH ARRAY */
56 } xl_standby_locks;
57
58 /*
59  * When we write running xact data to WAL, we use this structure.
60  */
61 typedef struct xl_running_xacts
62 {
63         int                             xcnt;                           /* # of xact ids in xids[] */
64         bool                    subxid_overflow;        /* snapshot overflowed, subxids missing */
65         TransactionId   nextXid;                        /* copy of ShmemVariableCache->nextXid */
66         TransactionId   oldestRunningXid;       /* *not* oldestXmin */
67
68         TransactionId   xids[1];                /* VARIABLE LENGTH ARRAY */
69 } xl_running_xacts;
70
71 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
72
73
74 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
75 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
76 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
77
78 /*
79  * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
80  * not quite. This has nothing at all to do with visibility on this server,
81  * so this is completely separate from snapmgr.c and snapmgr.h
82  * This data is important for creating the initial snapshot state on a
83  * standby server. We need lots more information than a normal snapshot,
84  * hence we use a specific data structure for our needs. This data
85  * is written to WAL as a separate record immediately after each
86  * checkpoint. That means that wherever we start a standby from we will
87  * almost immediately see the data we need to begin executing queries.
88  */
89
90 typedef struct RunningTransactionsData
91 {
92         int                             xcnt;                           /* # of xact ids in xids[] */
93         bool                    subxid_overflow;        /* snapshot overflowed, subxids missing */
94         TransactionId   nextXid;                        /* copy of ShmemVariableCache->nextXid */
95         TransactionId   oldestRunningXid;       /* *not* oldestXmin */
96
97         TransactionId  *xids;                           /* array of (sub)xids still running */
98 } RunningTransactionsData;
99
100 typedef RunningTransactionsData *RunningTransactions;
101
102 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
103
104 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
105
106 #endif   /* STANDBY_H */