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-2024, 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 */
27 
28 extern void InitRecoveryTransactionEnvironment(void);
30 
31 extern void ResolveRecoveryConflictWithSnapshot(TransactionId snapshotConflictHorizon,
32  bool isCatalogRel,
33  RelFileLocator locator);
34 extern void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId snapshotConflictHorizon,
35  bool isCatalogRel,
36  RelFileLocator locator);
39 
40 extern void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict);
41 extern void ResolveRecoveryConflictWithBufferPin(void);
42 extern void CheckRecoveryConflictDeadlock(void);
43 extern void StandbyDeadLockHandler(void);
44 extern void StandbyTimeoutHandler(void);
45 extern void StandbyLockTimeoutHandler(void);
46 extern void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start,
48  bool still_waiting);
49 
50 /*
51  * Standby Rmgr (RM_STANDBY_ID)
52  *
53  * Standby recovery manager exists to perform actions that are required
54  * to make hot standby work. That includes logging AccessExclusiveLocks taken
55  * by transactions and running-xacts snapshots.
56  */
57 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
59  int nsubxids, TransactionId *subxids);
60 extern void StandbyReleaseAllLocks(void);
61 extern void StandbyReleaseOldLocks(TransactionId oldxid);
62 
63 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
64 
65 
66 /*
67  * Declarations for GetRunningTransactionData(). Similar to Snapshots, but
68  * not quite. This has nothing at all to do with visibility on this server,
69  * so this is completely separate from snapmgr.c and snapmgr.h.
70  * This data is important for creating the initial snapshot state on a
71  * standby server. We need lots more information than a normal snapshot,
72  * hence we use a specific data structure for our needs. This data
73  * is written to WAL as a separate record immediately after each
74  * checkpoint. That means that wherever we start a standby from we will
75  * almost immediately see the data we need to begin executing queries.
76  */
77 
78 typedef enum
79 {
80  SUBXIDS_IN_ARRAY, /* xids array includes all running subxids */
81  SUBXIDS_MISSING, /* snapshot overflowed, subxids are missing */
82  SUBXIDS_IN_SUBTRANS, /* subxids are not included in 'xids', but
83  * pg_subtrans is fully up-to-date */
85 
87 {
88  int xcnt; /* # of xact ids in xids[] */
89  int subxcnt; /* # of subxact ids in xids[] */
91  TransactionId nextXid; /* xid from TransamVariables->nextXid */
92  TransactionId oldestRunningXid; /* *not* oldestXmin */
93  TransactionId oldestDatabaseRunningXid; /* same as above, but within the
94  * current database */
95  TransactionId latestCompletedXid; /* so we can set xmax */
96 
97  TransactionId *xids; /* array of (sub)xids still running */
99 
101 
102 extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
103 extern void LogAccessExclusiveLockPrepare(void);
104 
105 extern XLogRecPtr LogStandbySnapshot(void);
106 extern void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs,
107  bool relcacheInitFileInval);
108 
109 #endif /* STANDBY_H */
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1608
#define PGDLLIMPORT
Definition: c.h:1319
uint32 TransactionId
Definition: c.h:655
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:31
ProcSignalReason
Definition: procsignal.h:31
void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId snapshotConflictHorizon, bool isCatalogRel, RelFileLocator locator)
Definition: standby.c:511
RunningTransactionsData * RunningTransactions
Definition: standby.h:100
void StandbyTimeoutHandler(void)
Definition: standby.c:944
void ResolveRecoveryConflictWithBufferPin(void)
Definition: standby.c:792
void StandbyLockTimeoutHandler(void)
Definition: standby.c:953
void StandbyDeadLockHandler(void)
Definition: standby.c:935
XLogRecPtr LogStandbySnapshot(void)
Definition: standby.c:1281
void CheckRecoveryConflictDeadlock(void)
Definition: standby.c:904
void InitRecoveryTransactionEnvironment(void)
Definition: standby.c:94
void ResolveRecoveryConflictWithTablespace(Oid tsid)
Definition: standby.c:538
void ResolveRecoveryConflictWithDatabase(Oid dbid)
Definition: standby.c:568
void StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId *subxids)
Definition: standby.c:1091
void StandbyReleaseOldLocks(TransactionId oldxid)
Definition: standby.c:1129
void ResolveRecoveryConflictWithSnapshot(TransactionId snapshotConflictHorizon, bool isCatalogRel, RelFileLocator locator)
Definition: standby.c:467
void LogAccessExclusiveLockPrepare(void)
Definition: standby.c:1436
void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInitFileInval)
Definition: standby.c:1458
void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid)
Definition: standby.c:985
void LogAccessExclusiveLock(Oid dbOid, Oid relOid)
Definition: standby.c:1419
PGDLLIMPORT bool log_recovery_conflict_waits
Definition: standby.c:41
subxids_array_status
Definition: standby.h:79
@ SUBXIDS_IN_SUBTRANS
Definition: standby.h:82
@ SUBXIDS_MISSING
Definition: standby.h:81
@ SUBXIDS_IN_ARRAY
Definition: standby.h:80
void StandbyReleaseAllLocks(void)
Definition: standby.c:1105
PGDLLIMPORT int max_standby_archive_delay
Definition: standby.c:39
void LogRecoveryConflict(ProcSignalReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
Definition: standby.c:273
struct RunningTransactionsData RunningTransactionsData
void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict)
Definition: standby.c:622
void ShutdownRecoveryTransactionEnvironment(void)
Definition: standby.c:160
PGDLLIMPORT int max_standby_streaming_delay
Definition: standby.c:40
Definition: lock.h:165
TransactionId oldestRunningXid
Definition: standby.h:92
TransactionId nextXid
Definition: standby.h:91
TransactionId oldestDatabaseRunningXid
Definition: standby.h:93
TransactionId latestCompletedXid
Definition: standby.h:95
subxids_array_status subxid_status
Definition: standby.h:90
TransactionId * xids
Definition: standby.h:97
uint64 XLogRecPtr
Definition: xlogdefs.h:21