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