]> granicus.if.org Git - postgresql/blob - src/include/storage/standby.h
In HS, Startup process sets SIGALRM when waiting for buffer pin. If
[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.5 2010/01/23 16:37:12 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 extern void InitRecoveryTransactionEnvironment(void);
23 extern void ShutdownRecoveryTransactionEnvironment(void);
24
25 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid);
26 extern void ResolveRecoveryConflictWithTablespace(Oid tsid);
27 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
28
29 extern void ResolveRecoveryConflictWithBufferPin(void);
30 extern void SendRecoveryConflictWithBufferPin(void);
31
32 /*
33  * Standby Rmgr (RM_STANDBY_ID)
34  *
35  * Standby recovery manager exists to perform actions that are required
36  * to make hot standby work. That includes logging AccessExclusiveLocks taken
37  * by transactions and running-xacts snapshots.
38  */
39 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
40 extern void StandbyReleaseLockTree(TransactionId xid,
41                                                                    int nsubxids, TransactionId *subxids);
42 extern void StandbyReleaseAllLocks(void);
43 extern void StandbyReleaseOldLocks(TransactionId removeXid);
44
45 /*
46  * XLOG message types
47  */
48 #define XLOG_STANDBY_LOCK                       0x00
49 #define XLOG_RUNNING_XACTS                      0x10
50
51 typedef struct xl_standby_locks
52 {
53         int                             nlocks;         /* number of entries in locks array */
54         xl_standby_lock locks[1];       /* VARIABLE LENGTH ARRAY */
55 } xl_standby_locks;
56
57 /*
58  * When we write running xact data to WAL, we use this structure.
59  */
60 typedef struct xl_running_xacts
61 {
62         int                             xcnt;                           /* # of xact ids in xids[] */
63         bool                    subxid_overflow;        /* snapshot overflowed, subxids missing */
64         TransactionId   nextXid;                        /* copy of ShmemVariableCache->nextXid */
65         TransactionId   oldestRunningXid;       /* *not* oldestXmin */
66
67         TransactionId   xids[1];                /* VARIABLE LENGTH ARRAY */
68 } xl_running_xacts;
69
70 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
71
72
73 /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */
74 extern void standby_redo(XLogRecPtr lsn, XLogRecord *record);
75 extern void standby_desc(StringInfo buf, uint8 xl_info, char *rec);
76
77 /*
78  * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
79  * not quite. This has nothing at all to do with visibility on this server,
80  * so this is completely separate from snapmgr.c and snapmgr.h
81  * This data is important for creating the initial snapshot state on a
82  * standby server. We need lots more information than a normal snapshot,
83  * hence we use a specific data structure for our needs. This data
84  * is written to WAL as a separate record immediately after each
85  * checkpoint. That means that wherever we start a standby from we will
86  * almost immediately see the data we need to begin executing queries.
87  */
88
89 typedef struct RunningTransactionsData
90 {
91         int                             xcnt;                           /* # of xact ids in xids[] */
92         bool                    subxid_overflow;        /* snapshot overflowed, subxids missing */
93         TransactionId   nextXid;                        /* copy of ShmemVariableCache->nextXid */
94         TransactionId   oldestRunningXid;       /* *not* oldestXmin */
95
96         TransactionId  *xids;                           /* array of (sub)xids still running */
97 } RunningTransactionsData;
98
99 typedef RunningTransactionsData *RunningTransactions;
100
101 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
102
103 extern void LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid);
104
105 #endif   /* STANDBY_H */