PostgreSQL Source Code  git master
standby.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * standby.h
4  * Definitions for hot standby mode.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, 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 "datatype/timestamp.h"
18 #include "storage/lock.h"
19 #include "storage/procsignal.h"
20 #include "storage/relfilenode.h"
21 #include "storage/standbydefs.h"
22 
23 /* User-settable GUC parameters */
24 extern int vacuum_defer_cleanup_age;
25 extern int max_standby_archive_delay;
27 extern bool log_recovery_conflict_waits;
28 
29 extern void InitRecoveryTransactionEnvironment(void);
31 
32 extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid,
33  RelFileNode node);
34 extern void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId latestRemovedFullXid,
35  RelFileNode node);
38 
39 extern void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict);
40 extern void ResolveRecoveryConflictWithBufferPin(void);
41 extern void CheckRecoveryConflictDeadlock(void);
42 extern void StandbyDeadLockHandler(void);
43 extern void StandbyTimeoutHandler(void);
44 extern void StandbyLockTimeoutHandler(void);
45 extern void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start,
46  TimestampTz cur_ts, VirtualTransactionId *wait_list,
47  bool still_waiting);
48 
49 /*
50  * Standby Rmgr (RM_STANDBY_ID)
51  *
52  * Standby recovery manager exists to perform actions that are required
53  * to make hot standby work. That includes logging AccessExclusiveLocks taken
54  * by transactions and running-xacts snapshots.
55  */
56 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
58  int nsubxids, TransactionId *subxids);
59 extern void StandbyReleaseAllLocks(void);
60 extern void StandbyReleaseOldLocks(TransactionId oldxid);
61 
62 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
63 
64 
65 /*
66  * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
67  * not quite. This has nothing at all to do with visibility on this server,
68  * so this is completely separate from snapmgr.c and snapmgr.h.
69  * This data is important for creating the initial snapshot state on a
70  * standby server. We need lots more information than a normal snapshot,
71  * hence we use a specific data structure for our needs. This data
72  * is written to WAL as a separate record immediately after each
73  * checkpoint. That means that wherever we start a standby from we will
74  * almost immediately see the data we need to begin executing queries.
75  */
76 
78 {
79  int xcnt; /* # of xact ids in xids[] */
80  int subxcnt; /* # of subxact ids in xids[] */
81  bool subxid_overflow; /* snapshot overflowed, subxids missing */
82  TransactionId nextXid; /* xid from ShmemVariableCache->nextXid */
83  TransactionId oldestRunningXid; /* *not* oldestXmin */
84  TransactionId latestCompletedXid; /* so we can set xmax */
85 
86  TransactionId *xids; /* array of (sub)xids still running */
88 
90 
91 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
92 extern void LogAccessExclusiveLockPrepare(void);
93 
94 extern XLogRecPtr LogStandbySnapshot(void);
95 extern void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs,
96  bool relcacheInitFileInval);
97 
98 #endif /* STANDBY_H */
TransactionId oldestRunningXid
Definition: standby.h:83
void StandbyReleaseOldLocks(TransactionId oldxid)
Definition: standby.c:1070
void ResolveRecoveryConflictWithDatabase(Oid dbid)
Definition: standby.c:529
uint32 TransactionId
Definition: c.h:587
int vacuum_defer_cleanup_age
Definition: standby.c:39
int64 TimestampTz
Definition: timestamp.h:39
void ResolveRecoveryConflictWithBufferPin(void)
Definition: standby.c:753
RunningTransactionsData * RunningTransactions
Definition: standby.h:89
Definition: lock.h:166
void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start, TimestampTz cur_ts, VirtualTransactionId *wait_list, bool still_waiting)
Definition: standby.c:249
TransactionId * xids
Definition: standby.h:86
unsigned int Oid
Definition: postgres_ext.h:31
void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, RelFileNode node)
Definition: standby.c:443
int max_standby_archive_delay
Definition: standby.c:40
void InitRecoveryTransactionEnvironment(void)
Definition: standby.c:81
TransactionId latestCompletedXid
Definition: standby.h:84
void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId latestRemovedFullXid, RelFileNode node)
Definition: standby.c:475
void LogAccessExclusiveLock(Oid dbOid, Oid relOid)
Definition: standby.c:1358
struct RunningTransactionsData RunningTransactionsData
int max_standby_streaming_delay
Definition: standby.c:41
void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict)
Definition: standby.c:583
XLogRecPtr LogStandbySnapshot(void)
Definition: standby.c:1220
void StandbyReleaseAllLocks(void)
Definition: standby.c:1049
void LogAccessExclusiveLockPrepare(void)
Definition: standby.c:1375
void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid)
Definition: standby.c:948
void StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId *subxids)
Definition: standby.c:1035
void CheckRecoveryConflictDeadlock(void)
Definition: standby.c:862
void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInitFileInval)
Definition: standby.c:1397
void StandbyLockTimeoutHandler(void)
Definition: standby.c:916
void StandbyDeadLockHandler(void)
Definition: standby.c:893
void ShutdownRecoveryTransactionEnvironment(void)
Definition: standby.c:138
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void ResolveRecoveryConflictWithTablespace(Oid tsid)
Definition: standby.c:499
bool log_recovery_conflict_waits
Definition: standby.c:42
TransactionId nextXid
Definition: standby.h:82
ProcSignalReason
Definition: procsignal.h:30
void StandbyTimeoutHandler(void)
Definition: standby.c:904