]> granicus.if.org Git - postgresql/blob - src/include/storage/standby.h
Cleanup initialization of Hot Standby. Clarify working with reanalysis
[postgresql] / src / include / storage / standby.h
1 /*-------------------------------------------------------------------------
2  *
3  * standby.h
4  *        Definitions for hot standby mode.
5  *
6  *
7  * Portions Copyright (c) 1996-2010, 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.10 2010/05/13 11:15:38 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 #include "storage/procsignal.h"
20 #include "storage/relfilenode.h"
21
22 extern int      vacuum_defer_cleanup_age;
23
24 extern void InitRecoveryTransactionEnvironment(void);
25 extern void ShutdownRecoveryTransactionEnvironment(void);
26
27 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
28                                                                         RelFileNode node);
29 extern void ResolveRecoveryConflictWithRemovedTransactionId(void);
30 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
31 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
32
33 extern void ResolveRecoveryConflictWithBufferPin(void);
34 extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason);
35 extern void CheckRecoveryConflictDeadlock(LWLockId partitionLock);
36
37 /*
38  * Standby Rmgr (RM_STANDBY_ID)
39  *
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.
43  */
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);
49
50 /*
51  * XLOG message types
52  */
53 #define XLOG_STANDBY_LOCK                       0x00
54 #define XLOG_RUNNING_XACTS                      0x10
55
56 typedef struct xl_standby_locks
57 {
58         int                     nlocks;                 /* number of entries in locks array */
59         xl_standby_lock locks[1];       /* VARIABLE LENGTH ARRAY */
60 } xl_standby_locks;
61
62 /*
63  * When we write running xact data to WAL, we use this structure.
64  */
65 typedef struct xl_running_xacts
66 {
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 */
72
73         TransactionId xids[1];          /* VARIABLE LENGTH ARRAY */
74 } xl_running_xacts;
75
76 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
77
78
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);
82
83 /*
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.
93  */
94
95 typedef struct RunningTransactionsData
96 {
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 */
102
103         TransactionId *xids;            /* array of (sub)xids still running */
104 } RunningTransactionsData;
105
106 typedef RunningTransactionsData *RunningTransactions;
107
108 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
109
110 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
111
112 #endif   /* STANDBY_H */