1 /*-------------------------------------------------------------------------
2  *
3  * standby.h
4  *	  Definitions for hot standby mode.
5  *
6  *
7  * Portions Copyright (c) 1996-2020, 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 "storage/lock.h"
18 #include "storage/procsignal.h"
19 #include "storage/relfilenode.h"
20 #include "storage/standbydefs.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 ResolveRecoveryConflictWithTablespace(Oid tsid);
33 extern void ResolveRecoveryConflictWithDatabase(Oid dbid);
34 
35 extern void ResolveRecoveryConflictWithLock(LOCKTAG locktag);
36 extern void ResolveRecoveryConflictWithBufferPin(void);
37 extern void CheckRecoveryConflictDeadlock(void);
38 extern void StandbyDeadLockHandler(void);
39 extern void StandbyTimeoutHandler(void);
40 extern void StandbyLockTimeoutHandler(void);
41 
42 /*
43  * Standby Rmgr (RM_STANDBY_ID)
44  *
45  * Standby recovery manager exists to perform actions that are required
46  * to make hot standby work. That includes logging AccessExclusiveLocks taken
47  * by transactions and running-xacts snapshots.
48  */
49 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
50 extern void StandbyReleaseLockTree(TransactionId xid,
51 								   int nsubxids, TransactionId *subxids);
52 extern void StandbyReleaseAllLocks(void);
53 extern void StandbyReleaseOldLocks(TransactionId oldxid);
54 
55 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
56 
57 
58 /*
59  * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
60  * not quite. This has nothing at all to do with visibility on this server,
61  * so this is completely separate from snapmgr.c and snapmgr.h.
62  * This data is important for creating the initial snapshot state on a
63  * standby server. We need lots more information than a normal snapshot,
64  * hence we use a specific data structure for our needs. This data
65  * is written to WAL as a separate record immediately after each
66  * checkpoint. That means that wherever we start a standby from we will
67  * almost immediately see the data we need to begin executing queries.
68  */
69 
70 typedef struct RunningTransactionsData
71 {
72 	int			xcnt;			/* # of xact ids in xids[] */
73 	int			subxcnt;		/* # of subxact ids in xids[] */
74 	bool		subxid_overflow;	/* snapshot overflowed, subxids missing */
75 	TransactionId nextXid;		/* xid from ShmemVariableCache->nextFullXid */
76 	TransactionId oldestRunningXid; /* *not* oldestXmin */
77 	TransactionId latestCompletedXid;	/* so we can set xmax */
78 
79 	TransactionId *xids;		/* array of (sub)xids still running */
80 } RunningTransactionsData;
81 
82 typedef RunningTransactionsData *RunningTransactions;
83 
84 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
85 extern void LogAccessExclusiveLockPrepare(void);
86 
87 extern XLogRecPtr LogStandbySnapshot(void);
88 extern void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs,
89 									bool relcacheInitFileInval);
90 
91 #endif							/* STANDBY_H */
92