PostgreSQL Source Code git master
Loading...
Searching...
No Matches
xlogrecovery.h
Go to the documentation of this file.
1/*
2 * xlogrecovery.h
3 *
4 * Functions for WAL recovery and standby mode
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/access/xlogrecovery.h
10 */
11#ifndef XLOGRECOVERY_H
12#define XLOGRECOVERY_H
13
14#include "access/xlogreader.h"
15#include "catalog/pg_control.h"
16#include "lib/stringinfo.h"
18#include "storage/latch.h"
19#include "utils/timestamp.h"
20
21/*
22 * Recovery target type.
23 * Only set during a Point in Time recovery, not when in standby mode.
24 */
34
35/*
36 * Recovery target TimeLine goal
37 */
44
45/*
46 * Recovery target action.
47 */
54
55/* Recovery pause states */
57{
58 RECOVERY_NOT_PAUSED, /* pause not requested */
59 RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */
60 RECOVERY_PAUSED, /* recovery is paused */
62
63/*
64 * Shared-memory state for WAL recovery.
65 */
66typedef struct XLogRecoveryCtlData
67{
68 /*
69 * SharedHotStandbyActive indicates if we allow hot standby queries to be
70 * run. Protected by info_lck.
71 */
73
74 /*
75 * SharedPromoteIsTriggered indicates if a standby promotion has been
76 * triggered. Protected by info_lck.
77 */
79
80 /*
81 * recoveryWakeupLatch is used to wake up the startup process to continue
82 * WAL replay, if it is waiting for WAL to arrive or promotion to be
83 * requested.
84 *
85 * Note that the startup process also uses another latch, its procLatch,
86 * to wait for recovery conflict. If we get rid of recoveryWakeupLatch for
87 * signaling the startup process in favor of using its procLatch, which
88 * comports better with possible generic signal handlers using that latch.
89 * But we should not do that because the startup process doesn't assume
90 * that it's waken up by walreceiver process or SIGHUP signal handler
91 * while it's waiting for recovery conflict. The separate latches,
92 * recoveryWakeupLatch and procLatch, should be used for inter-process
93 * communication for WAL replay and recovery conflict, respectively.
94 */
96
97 /*
98 * Last record successfully replayed.
99 */
100 XLogRecPtr lastReplayedReadRecPtr; /* start position */
101 XLogRecPtr lastReplayedEndRecPtr; /* end+1 position */
103
104 /*
105 * When we're currently replaying a record, ie. in a redo function,
106 * replayEndRecPtr points to the end+1 of the record being replayed,
107 * otherwise it's equal to lastReplayedEndRecPtr.
108 */
111 /* timestamp of last COMMIT/ABORT record replayed (or being replayed) */
113
114 /*
115 * timestamp of when we started replaying the current chunk of WAL data,
116 * only relevant for replication or archive recovery
117 */
119 /* Recovery pause state */
122
123 slock_t info_lck; /* locks shared variables shown above */
125
127
128/* User-settable GUC parameters */
132extern PGDLLIMPORT char *PrimaryConnInfo;
133extern PGDLLIMPORT char *PrimarySlotName;
137
138/* indirectly set via GUC system */
142extern PGDLLIMPORT const char *recoveryTargetName;
149
150/* Have we already reached a consistent database state? */
152
153/* Are we currently in standby mode? */
154extern PGDLLIMPORT bool StandbyMode;
155
156extern Size XLogRecoveryShmemSize(void);
157extern void XLogRecoveryShmemInit(void);
158
161 bool *haveTblspcMap_ptr);
162extern void PerformWalRecovery(void);
163
164/*
165 * FinishWalRecovery() returns this. It contains information about the point
166 * where recovery ended, and why it ended.
167 */
168typedef struct
169{
170 /*
171 * Information about the last valid or applied record, after which new WAL
172 * can be appended. 'lastRec' is the position where the last record
173 * starts, and 'endOfLog' is its end. 'lastPage' is a copy of the last
174 * partial page that contains endOfLog (or NULL if endOfLog is exactly at
175 * page boundary). 'lastPageBeginPtr' is the position where the last page
176 * begins.
177 *
178 * endOfLogTLI is the TLI in the filename of the XLOG segment containing
179 * the last applied record. It could be different from lastRecTLI, if
180 * there was a timeline switch in that segment, and we were reading the
181 * old WAL from a segment belonging to a higher timeline.
182 */
183 XLogRecPtr lastRec; /* start of last valid or applied record */
185 XLogRecPtr endOfLog; /* end of last valid or applied record */
187
188 XLogRecPtr lastPageBeginPtr; /* LSN of page that contains endOfLog */
189 char *lastPage; /* copy of the last page, up to endOfLog */
190
191 /*
192 * abortedRecPtr is the start pointer of a broken record at end of WAL
193 * when recovery completes; missingContrecPtr is the location of the first
194 * contrecord that went missing. See CreateOverwriteContrecordRecord for
195 * details.
196 */
199
200 /* short human-readable string describing why recovery ended */
202
203 /*
204 * If standby or recovery signal file was found, these flags are set
205 * accordingly.
206 */
210
212extern void ShutdownWalRecovery(void);
213extern void RemovePromoteSignalFiles(void);
214
215extern bool HotStandbyActive(void);
216extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
218extern void SetRecoveryPause(bool recoveryPause);
220extern TimestampTz GetLatestXTime(void);
222extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);
223
224extern bool PromoteIsTriggered(void);
225extern bool CheckPromoteSignal(void);
226extern void WakeupRecovery(void);
227
228extern void StartupRequestWalReceiverRestart(void);
229extern void XLogRequestWalReceiverReply(void);
230
231extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue);
232
233extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);
234
235#endif /* XLOGRECOVERY_H */
#define PGDLLIMPORT
Definition c.h:1423
uint32 TransactionId
Definition c.h:738
size_t Size
Definition c.h:691
int64 TimestampTz
Definition timestamp.h:39
static char buf[DEFAULT_XLOG_SEG_SIZE]
static int fb(int x)
XLogRecPtr lastPageBeginPtr
XLogRecPtr missingContrecPtr
Definition latch.h:116
ConditionVariable recoveryNotPausedCV
XLogRecPtr lastReplayedEndRecPtr
TimeLineID replayEndTLI
TimeLineID lastReplayedTLI
TimestampTz currentChunkStartTime
XLogRecPtr replayEndRecPtr
TimestampTz recoveryLastXTime
RecoveryPauseState recoveryPauseState
XLogRecPtr lastReplayedReadRecPtr
static ControlFileData * ControlFile
Definition xlog.c:577
uint64 XLogRecPtr
Definition xlogdefs.h:21
uint32 TimeLineID
Definition xlogdefs.h:63
bool HotStandbyActive(void)
PGDLLIMPORT int recovery_min_apply_delay
void ShutdownWalRecovery(void)
RecoveryTargetAction
@ RECOVERY_TARGET_ACTION_PAUSE
@ RECOVERY_TARGET_ACTION_PROMOTE
@ RECOVERY_TARGET_ACTION_SHUTDOWN
PGDLLIMPORT TimeLineID recoveryTargetTLIRequested
PGDLLIMPORT TimeLineID recoveryTargetTLI
PGDLLIMPORT TimestampTz recoveryTargetTime
void StartupRequestWalReceiverRestart(void)
void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue)
void PerformWalRecovery(void)
bool CheckPromoteSignal(void)
PGDLLIMPORT char * PrimarySlotName
void SetRecoveryPause(bool recoveryPause)
XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI)
RecoveryTargetType
@ RECOVERY_TARGET_IMMEDIATE
@ RECOVERY_TARGET_TIME
@ RECOVERY_TARGET_UNSET
@ RECOVERY_TARGET_XID
@ RECOVERY_TARGET_LSN
@ RECOVERY_TARGET_NAME
void WakeupRecovery(void)
void xlog_outdesc(StringInfo buf, XLogReaderState *record)
bool PromoteIsTriggered(void)
TimestampTz GetCurrentChunkReplayStartTime(void)
PGDLLIMPORT XLogRecPtr recoveryTargetLSN
PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
PGDLLIMPORT bool wal_receiver_create_temp_slot
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
PGDLLIMPORT RecoveryTargetType recoveryTarget
RecoveryTargetTimeLineGoal
@ RECOVERY_TARGET_TIMELINE_NUMERIC
@ RECOVERY_TARGET_TIMELINE_CONTROLFILE
@ RECOVERY_TARGET_TIMELINE_LATEST
EndOfWalRecoveryInfo * FinishWalRecovery(void)
RecoveryPauseState
@ RECOVERY_PAUSED
@ RECOVERY_NOT_PAUSED
@ RECOVERY_PAUSE_REQUESTED
PGDLLIMPORT bool StandbyMode
void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, bool *haveBackupLabel_ptr, bool *haveTblspcMap_ptr)
Size XLogRecoveryShmemSize(void)
PGDLLIMPORT bool recoveryTargetInclusive
RecoveryPauseState GetRecoveryPauseState(void)
void XLogRecoveryShmemInit(void)
PGDLLIMPORT char * recoveryEndCommand
PGDLLIMPORT char * recovery_target_time_string
TimestampTz GetLatestXTime(void)
void XLogRequestWalReceiverReply(void)
PGDLLIMPORT const char * recoveryTargetName
PGDLLIMPORT bool reachedConsistency
void RemovePromoteSignalFiles(void)
PGDLLIMPORT TransactionId recoveryTargetXid
PGDLLIMPORT XLogRecoveryCtlData * XLogRecoveryCtl
PGDLLIMPORT char * PrimaryConnInfo
PGDLLIMPORT char * archiveCleanupCommand
PGDLLIMPORT char * recoveryRestoreCommand
PGDLLIMPORT int recoveryTargetAction