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-2023, 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/relfilelocator.h"
21 #include "storage/standbydefs.h"
22 
23 /* User-settable GUC parameters */
28 
29 extern void InitRecoveryTransactionEnvironment(void);
31 
32 extern void ResolveRecoveryConflictWithSnapshot(TransactionId snapshotConflictHorizon,
33  RelFileLocator locator);
34 extern void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId snapshotConflictHorizon,
35  RelFileLocator locator);
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,
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 */
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1549
#define PGDLLIMPORT
Definition: c.h:1303
uint32 TransactionId
Definition: c.h:636
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:31
ProcSignalReason
Definition: procsignal.h:31
RunningTransactionsData * RunningTransactions
Definition: standby.h:89
void StandbyTimeoutHandler(void)
Definition: standby.c:940
void ResolveRecoveryConflictWithBufferPin(void)
Definition: standby.c:788
void StandbyLockTimeoutHandler(void)
Definition: standby.c:949
void StandbyDeadLockHandler(void)
Definition: standby.c:931
XLogRecPtr LogStandbySnapshot(void)
Definition: standby.c:1273
void CheckRecoveryConflictDeadlock(void)
Definition: standby.c:900
void InitRecoveryTransactionEnvironment(void)
Definition: standby.c:96
void ResolveRecoveryConflictWithTablespace(Oid tsid)
Definition: standby.c:534
void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId snapshotConflictHorizon, RelFileLocator locator)
Definition: standby.c:510
void ResolveRecoveryConflictWithDatabase(Oid dbid)
Definition: standby.c:564
void StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId *subxids)
Definition: standby.c:1088
void StandbyReleaseOldLocks(TransactionId oldxid)
Definition: standby.c:1123
void ResolveRecoveryConflictWithSnapshot(TransactionId snapshotConflictHorizon, RelFileLocator locator)
Definition: standby.c:477
void LogAccessExclusiveLockPrepare(void)
Definition: standby.c:1428
void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInitFileInval)
Definition: standby.c:1450
void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid)
Definition: standby.c:981
void LogAccessExclusiveLock(Oid dbOid, Oid relOid)
Definition: standby.c:1411
PGDLLIMPORT bool log_recovery_conflict_waits
Definition: standby.c:43
void StandbyReleaseAllLocks(void)
Definition: standby.c:1102
PGDLLIMPORT int max_standby_archive_delay
Definition: standby.c:41
void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
Definition: standby.c:274
struct RunningTransactionsData RunningTransactionsData
void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict)
Definition: standby.c:618
PGDLLIMPORT int vacuum_defer_cleanup_age
Definition: standby.c:40
void ShutdownRecoveryTransactionEnvironment(void)
Definition: standby.c:161
PGDLLIMPORT int max_standby_streaming_delay
Definition: standby.c:42
Definition: lock.h:165
TransactionId oldestRunningXid
Definition: standby.h:83
TransactionId nextXid
Definition: standby.h:82
TransactionId latestCompletedXid
Definition: standby.h:84
TransactionId * xids
Definition: standby.h:86
uint64 XLogRecPtr
Definition: xlogdefs.h:21