PostgreSQL Source Code  git master
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-2023, 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"
17 #include "utils/timestamp.h"
18 
19 /*
20  * Recovery target type.
21  * Only set during a Point in Time recovery, not when in standby mode.
22  */
23 typedef enum
24 {
32 
33 /*
34  * Recovery target TimeLine goal
35  */
36 typedef enum
37 {
42 
43 /* Recovery pause states */
44 typedef enum RecoveryPauseState
45 {
46  RECOVERY_NOT_PAUSED, /* pause not requested */
47  RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */
48  RECOVERY_PAUSED /* recovery is paused */
50 
51 /* User-settable GUC parameters */
55 extern PGDLLIMPORT char *PrimaryConnInfo;
56 extern PGDLLIMPORT char *PrimarySlotName;
58 extern PGDLLIMPORT char *recoveryEndCommand;
60 
61 /* indirectly set via GUC system */
65 extern PGDLLIMPORT const char *recoveryTargetName;
72 
73 /* Have we already reached a consistent database state? */
75 
76 /* Are we currently in standby mode? */
77 extern PGDLLIMPORT bool StandbyMode;
78 
79 extern Size XLogRecoveryShmemSize(void);
80 extern void XLogRecoveryShmemInit(void);
81 
83  bool *wasShutdown_ptr, bool *haveBackupLabel_ptr,
84  bool *haveTblspcMap_ptr);
85 extern void PerformWalRecovery(void);
86 
87 /*
88  * FinishWalRecovery() returns this. It contains information about the point
89  * where recovery ended, and why it ended.
90  */
91 typedef struct
92 {
93  /*
94  * Information about the last valid or applied record, after which new WAL
95  * can be appended. 'lastRec' is the position where the last record
96  * starts, and 'endOfLog' is its end. 'lastPage' is a copy of the last
97  * partial page that contains endOfLog (or NULL if endOfLog is exactly at
98  * page boundary). 'lastPageBeginPtr' is the position where the last page
99  * begins.
100  *
101  * endOfLogTLI is the TLI in the filename of the XLOG segment containing
102  * the last applied record. It could be different from lastRecTLI, if
103  * there was a timeline switch in that segment, and we were reading the
104  * old WAL from a segment belonging to a higher timeline.
105  */
106  XLogRecPtr lastRec; /* start of last valid or applied record */
108  XLogRecPtr endOfLog; /* end of last valid or applied record */
110 
111  XLogRecPtr lastPageBeginPtr; /* LSN of page that contains endOfLog */
112  char *lastPage; /* copy of the last page, up to endOfLog */
113 
114  /*
115  * abortedRecPtr is the start pointer of a broken record at end of WAL
116  * when recovery completes; missingContrecPtr is the location of the first
117  * contrecord that went missing. See CreateOverwriteContrecordRecord for
118  * details.
119  */
122 
123  /* short human-readable string describing why recovery ended */
125 
126  /*
127  * If standby or recovery signal file was found, these flags are set
128  * accordingly.
129  */
133 
135 extern void ShutdownWalRecovery(void);
136 extern void RemovePromoteSignalFiles(void);
137 
138 extern bool HotStandbyActive(void);
139 extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
141 extern void SetRecoveryPause(bool recoveryPause);
142 extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
143 extern TimestampTz GetLatestXTime(void);
145 extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);
146 
147 extern bool PromoteIsTriggered(void);
148 extern bool CheckPromoteSignal(void);
149 extern void WakeupRecovery(void);
150 
151 extern void StartupRequestWalReceiverRestart(void);
152 extern void XLogRequestWalReceiverReply(void);
153 
154 extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue);
155 
156 extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);
157 
158 #endif /* XLOGRECOVERY_H */
#define PGDLLIMPORT
Definition: c.h:1303
uint32 TransactionId
Definition: c.h:636
size_t Size
Definition: c.h:589
int64 TimestampTz
Definition: timestamp.h:39
static char * buf
Definition: pg_test_fsync.c:67
XLogRecPtr lastPageBeginPtr
Definition: xlogrecovery.h:111
XLogRecPtr abortedRecPtr
Definition: xlogrecovery.h:120
XLogRecPtr missingContrecPtr
Definition: xlogrecovery.h:121
TimeLineID endOfLogTLI
Definition: xlogrecovery.h:109
static ControlFileData * ControlFile
Definition: xlog.c:570
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:59
bool HotStandbyActive(void)
PGDLLIMPORT int recovery_min_apply_delay
Definition: xlogrecovery.c:93
void ShutdownWalRecovery(void)
PGDLLIMPORT TimeLineID recoveryTargetTLIRequested
Definition: xlogrecovery.c:121
PGDLLIMPORT TimeLineID recoveryTargetTLI
Definition: xlogrecovery.c:122
PGDLLIMPORT TimestampTz recoveryTargetTime
Definition: xlogrecovery.c:90
void StartupRequestWalReceiverRestart(void)
void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue)
void PerformWalRecovery(void)
bool CheckPromoteSignal(void)
PGDLLIMPORT char * PrimarySlotName
Definition: xlogrecovery.c:97
void SetRecoveryPause(bool recoveryPause)
EndOfWalRecoveryInfo * FinishWalRecovery(void)
XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI)
RecoveryTargetType
Definition: xlogrecovery.h:24
@ RECOVERY_TARGET_IMMEDIATE
Definition: xlogrecovery.h:30
@ RECOVERY_TARGET_TIME
Definition: xlogrecovery.h:27
@ RECOVERY_TARGET_UNSET
Definition: xlogrecovery.h:25
@ RECOVERY_TARGET_XID
Definition: xlogrecovery.h:26
@ RECOVERY_TARGET_LSN
Definition: xlogrecovery.h:29
@ RECOVERY_TARGET_NAME
Definition: xlogrecovery.h:28
void WakeupRecovery(void)
void xlog_outdesc(StringInfo buf, XLogReaderState *record)
bool PromoteIsTriggered(void)
TimestampTz GetCurrentChunkReplayStartTime(void)
PGDLLIMPORT XLogRecPtr recoveryTargetLSN
Definition: xlogrecovery.c:92
PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlogrecovery.c:120
PGDLLIMPORT bool wal_receiver_create_temp_slot
Definition: xlogrecovery.c:98
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
PGDLLIMPORT RecoveryTargetType recoveryTarget
Definition: xlogrecovery.c:85
RecoveryTargetTimeLineGoal
Definition: xlogrecovery.h:37
@ RECOVERY_TARGET_TIMELINE_NUMERIC
Definition: xlogrecovery.h:40
@ RECOVERY_TARGET_TIMELINE_CONTROLFILE
Definition: xlogrecovery.h:38
@ RECOVERY_TARGET_TIMELINE_LATEST
Definition: xlogrecovery.h:39
RecoveryPauseState
Definition: xlogrecovery.h:45
@ RECOVERY_PAUSED
Definition: xlogrecovery.h:48
@ RECOVERY_NOT_PAUSED
Definition: xlogrecovery.h:46
@ RECOVERY_PAUSE_REQUESTED
Definition: xlogrecovery.h:47
PGDLLIMPORT bool StandbyMode
Definition: xlogrecovery.c:147
void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, bool *haveBackupLabel_ptr, bool *haveTblspcMap_ptr)
Definition: xlogrecovery.c:512
Size XLogRecoveryShmemSize(void)
Definition: xlogrecovery.c:447
PGDLLIMPORT bool recoveryTargetInclusive
Definition: xlogrecovery.c:86
RecoveryPauseState GetRecoveryPauseState(void)
void XLogRecoveryShmemInit(void)
Definition: xlogrecovery.c:458
PGDLLIMPORT char * recoveryEndCommand
Definition: xlogrecovery.c:83
PGDLLIMPORT char * recovery_target_time_string
Definition: xlogrecovery.c:89
TimestampTz GetLatestXTime(void)
void XLogRequestWalReceiverReply(void)
PGDLLIMPORT const char * recoveryTargetName
Definition: xlogrecovery.c:91
PGDLLIMPORT bool reachedConsistency
Definition: xlogrecovery.c:294
void RemovePromoteSignalFiles(void)
PGDLLIMPORT TransactionId recoveryTargetXid
Definition: xlogrecovery.c:88
PGDLLIMPORT char * PrimaryConnInfo
Definition: xlogrecovery.c:96
PGDLLIMPORT char * archiveCleanupCommand
Definition: xlogrecovery.c:84
PGDLLIMPORT char * recoveryRestoreCommand
Definition: xlogrecovery.c:82
PGDLLIMPORT int recoveryTargetAction
Definition: xlogrecovery.c:87