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-2022, 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;
68 extern PGDLLIMPORT char *PromoteTriggerFile;
73 
74 /* Have we already reached a consistent database state? */
76 
77 /* Are we currently in standby mode? */
78 extern PGDLLIMPORT bool StandbyMode;
79 
80 extern Size XLogRecoveryShmemSize(void);
81 extern void XLogRecoveryShmemInit(void);
82 
83 extern void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdownPtr, bool *haveBackupLabel, bool *haveTblspcMap);
84 extern void PerformWalRecovery(void);
85 
86 /*
87  * FinishWalRecovery() returns this. It contains information about the point
88  * where recovery ended, and why it ended.
89  */
90 typedef struct
91 {
92  /*
93  * Information about the last valid or applied record, after which new WAL
94  * can be appended. 'lastRec' is the position where the last record
95  * starts, and 'endOfLog' is its end. 'lastPage' is a copy of the last
96  * partial page that contains endOfLog (or NULL if endOfLog is exactly at
97  * page boundary). 'lastPageBeginPtr' is the position where the last page
98  * begins.
99  *
100  * endOfLogTLI is the TLI in the filename of the XLOG segment containing
101  * the last applied record. It could be different from lastRecTLI, if
102  * there was a timeline switch in that segment, and we were reading the
103  * old WAL from a segment belonging to a higher timeline.
104  */
105  XLogRecPtr lastRec; /* start of last valid or applied record */
107  XLogRecPtr endOfLog; /* end of last valid or applied record */
109 
110  XLogRecPtr lastPageBeginPtr; /* LSN of page that contains endOfLog */
111  char *lastPage; /* copy of the last page, up to endOfLog */
112 
113  /*
114  * abortedRecPtr is the start pointer of a broken record at end of WAL
115  * when recovery completes; missingContrecPtr is the location of the first
116  * contrecord that went missing. See CreateOverwriteContrecordRecord for
117  * details.
118  */
121 
122  /* short human-readable string describing why recovery ended */
124 
125  /*
126  * If standby or recovery signal file was found, these flags are set
127  * accordingly.
128  */
132 
134 extern void ShutdownWalRecovery(void);
135 extern void RemovePromoteSignalFiles(void);
136 
137 extern bool HotStandbyActive(void);
138 extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
140 extern void SetRecoveryPause(bool recoveryPause);
141 extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
142 extern TimestampTz GetLatestXTime(void);
144 extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);
145 
146 extern bool PromoteIsTriggered(void);
147 extern bool CheckPromoteSignal(void);
148 extern void WakeupRecovery(void);
149 
150 extern void StartupRequestWalReceiverRestart(void);
151 extern void XLogRequestWalReceiverReply(void);
152 
153 extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue);
154 
155 extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);
156 
157 #endif /* XLOGRECOVERY_H */
#define PGDLLIMPORT
Definition: c.h:1331
uint32 TransactionId
Definition: c.h:587
size_t Size
Definition: c.h:540
int64 TimestampTz
Definition: timestamp.h:39
static char * buf
Definition: pg_test_fsync.c:67
XLogRecPtr lastPageBeginPtr
Definition: xlogrecovery.h:110
XLogRecPtr abortedRecPtr
Definition: xlogrecovery.h:119
XLogRecPtr missingContrecPtr
Definition: xlogrecovery.h:120
TimeLineID endOfLogTLI
Definition: xlogrecovery.h:108
static ControlFileData * ControlFile
Definition: xlog.c:566
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:59
bool HotStandbyActive(void)
PGDLLIMPORT int recovery_min_apply_delay
Definition: xlogrecovery.c:89
void ShutdownWalRecovery(void)
PGDLLIMPORT TimeLineID recoveryTargetTLIRequested
Definition: xlogrecovery.c:118
PGDLLIMPORT TimeLineID recoveryTargetTLI
Definition: xlogrecovery.c:119
PGDLLIMPORT TimestampTz recoveryTargetTime
Definition: xlogrecovery.c:86
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:93
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:88
void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdownPtr, bool *haveBackupLabel, bool *haveTblspcMap)
Definition: xlogrecovery.c:490
PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlogrecovery.c:117
PGDLLIMPORT bool wal_receiver_create_temp_slot
Definition: xlogrecovery.c:95
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
PGDLLIMPORT RecoveryTargetType recoveryTarget
Definition: xlogrecovery.c:81
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:144
Size XLogRecoveryShmemSize(void)
Definition: xlogrecovery.c:443
PGDLLIMPORT bool recoveryTargetInclusive
Definition: xlogrecovery.c:82
RecoveryPauseState GetRecoveryPauseState(void)
PGDLLIMPORT char * PromoteTriggerFile
Definition: xlogrecovery.c:94
void XLogRecoveryShmemInit(void)
Definition: xlogrecovery.c:454
PGDLLIMPORT char * recoveryEndCommand
Definition: xlogrecovery.c:79
PGDLLIMPORT char * recovery_target_time_string
Definition: xlogrecovery.c:85
TimestampTz GetLatestXTime(void)
void XLogRequestWalReceiverReply(void)
PGDLLIMPORT const char * recoveryTargetName
Definition: xlogrecovery.c:87
PGDLLIMPORT bool reachedConsistency
Definition: xlogrecovery.c:291
void RemovePromoteSignalFiles(void)
PGDLLIMPORT TransactionId recoveryTargetXid
Definition: xlogrecovery.c:84
PGDLLIMPORT char * PrimaryConnInfo
Definition: xlogrecovery.c:92
PGDLLIMPORT char * archiveCleanupCommand
Definition: xlogrecovery.c:80
PGDLLIMPORT char * recoveryRestoreCommand
Definition: xlogrecovery.c:78
PGDLLIMPORT int recoveryTargetAction
Definition: xlogrecovery.c:83