1 /*-------------------------------------------------------------------------
4 * Definitions for hot standby mode.
7 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/standby.h
12 *-------------------------------------------------------------------------
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"
23 /* User-settable GUC parameters */
24 extern PGDLLIMPORT
int max_standby_archive_delay
;
25 extern PGDLLIMPORT
int max_standby_streaming_delay
;
26 extern PGDLLIMPORT
bool log_recovery_conflict_waits
;
28 extern void InitRecoveryTransactionEnvironment(void);
29 extern void ShutdownRecoveryTransactionEnvironment(void);
31 extern void ResolveRecoveryConflictWithSnapshot(TransactionId snapshotConflictHorizon
,
33 RelFileLocator locator
);
34 extern void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId snapshotConflictHorizon
,
36 RelFileLocator locator
);
37 extern void ResolveRecoveryConflictWithTablespace(Oid tsid
);
38 extern void ResolveRecoveryConflictWithDatabase(Oid dbid
);
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
,
47 TimestampTz now
, VirtualTransactionId
*wait_list
,
51 * Standby Rmgr (RM_STANDBY_ID)
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.
57 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid
, Oid dbOid
, Oid relOid
);
58 extern void StandbyReleaseLockTree(TransactionId xid
,
59 int nsubxids
, TransactionId
*subxids
);
60 extern void StandbyReleaseAllLocks(void);
61 extern void StandbyReleaseOldLocks(TransactionId oldxid
);
63 #define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids)
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.
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 */
84 } subxids_array_status
;
86 typedef struct RunningTransactionsData
88 int xcnt
; /* # of xact ids in xids[] */
89 int subxcnt
; /* # of subxact ids in xids[] */
90 subxids_array_status subxid_status
;
91 TransactionId nextXid
; /* xid from TransamVariables->nextXid */
92 TransactionId oldestRunningXid
; /* *not* oldestXmin */
93 TransactionId oldestDatabaseRunningXid
; /* same as above, but within the
95 TransactionId latestCompletedXid
; /* so we can set xmax */
97 TransactionId
*xids
; /* array of (sub)xids still running */
98 } RunningTransactionsData
;
100 typedef RunningTransactionsData
*RunningTransactions
;
102 extern void LogAccessExclusiveLock(Oid dbOid
, Oid relOid
);
103 extern void LogAccessExclusiveLockPrepare(void);
105 extern XLogRecPtr
LogStandbySnapshot(void);
106 extern void LogStandbyInvalidations(int nmsgs
, SharedInvalidationMessage
*msgs
,
107 bool relcacheInitFileInval
);
109 #endif /* STANDBY_H */