PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2025, 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 */
23typedef enum
24{
32
33/*
34 * Recovery target TimeLine goal
35 */
36typedef enum
37{
42
43/*
44 * Recovery target action.
45 */
46typedef enum
47{
52
53/* Recovery pause states */
55{
56 RECOVERY_NOT_PAUSED, /* pause not requested */
57 RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */
58 RECOVERY_PAUSED, /* recovery is paused */
60
61/* User-settable GUC parameters */
65extern PGDLLIMPORT char *PrimaryConnInfo;
66extern PGDLLIMPORT char *PrimarySlotName;
70
71/* indirectly set via GUC system */
75extern PGDLLIMPORT const char *recoveryTargetName;
82
83/* Have we already reached a consistent database state? */
85
86/* Are we currently in standby mode? */
87extern PGDLLIMPORT bool StandbyMode;
88
89extern Size XLogRecoveryShmemSize(void);
90extern void XLogRecoveryShmemInit(void);
91
93 bool *wasShutdown_ptr, bool *haveBackupLabel_ptr,
94 bool *haveTblspcMap_ptr);
95extern void PerformWalRecovery(void);
96
97/*
98 * FinishWalRecovery() returns this. It contains information about the point
99 * where recovery ended, and why it ended.
100 */
101typedef struct
102{
103 /*
104 * Information about the last valid or applied record, after which new WAL
105 * can be appended. 'lastRec' is the position where the last record
106 * starts, and 'endOfLog' is its end. 'lastPage' is a copy of the last
107 * partial page that contains endOfLog (or NULL if endOfLog is exactly at
108 * page boundary). 'lastPageBeginPtr' is the position where the last page
109 * begins.
110 *
111 * endOfLogTLI is the TLI in the filename of the XLOG segment containing
112 * the last applied record. It could be different from lastRecTLI, if
113 * there was a timeline switch in that segment, and we were reading the
114 * old WAL from a segment belonging to a higher timeline.
115 */
116 XLogRecPtr lastRec; /* start of last valid or applied record */
118 XLogRecPtr endOfLog; /* end of last valid or applied record */
120
121 XLogRecPtr lastPageBeginPtr; /* LSN of page that contains endOfLog */
122 char *lastPage; /* copy of the last page, up to endOfLog */
123
124 /*
125 * abortedRecPtr is the start pointer of a broken record at end of WAL
126 * when recovery completes; missingContrecPtr is the location of the first
127 * contrecord that went missing. See CreateOverwriteContrecordRecord for
128 * details.
129 */
132
133 /* short human-readable string describing why recovery ended */
135
136 /*
137 * If standby or recovery signal file was found, these flags are set
138 * accordingly.
139 */
143
145extern void ShutdownWalRecovery(void);
146extern void RemovePromoteSignalFiles(void);
147
148extern bool HotStandbyActive(void);
149extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
151extern void SetRecoveryPause(bool recoveryPause);
152extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
153extern TimestampTz GetLatestXTime(void);
155extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);
156
157extern bool PromoteIsTriggered(void);
158extern bool CheckPromoteSignal(void);
159extern void WakeupRecovery(void);
160
161extern void StartupRequestWalReceiverRestart(void);
162extern void XLogRequestWalReceiverReply(void);
163
164extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue);
165
166extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);
167
168#endif /* XLOGRECOVERY_H */
#define PGDLLIMPORT
Definition: c.h:1319
uint32 TransactionId
Definition: c.h:657
size_t Size
Definition: c.h:610
int64 TimestampTz
Definition: timestamp.h:39
static char * buf
Definition: pg_test_fsync.c:72
XLogRecPtr lastPageBeginPtr
Definition: xlogrecovery.h:121
XLogRecPtr abortedRecPtr
Definition: xlogrecovery.h:130
XLogRecPtr missingContrecPtr
Definition: xlogrecovery.h:131
TimeLineID endOfLogTLI
Definition: xlogrecovery.h:119
static ControlFileData * ControlFile
Definition: xlog.c:574
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:62
bool HotStandbyActive(void)
PGDLLIMPORT int recovery_min_apply_delay
Definition: xlogrecovery.c:95
void ShutdownWalRecovery(void)
RecoveryTargetAction
Definition: xlogrecovery.h:47
@ RECOVERY_TARGET_ACTION_PAUSE
Definition: xlogrecovery.h:48
@ RECOVERY_TARGET_ACTION_PROMOTE
Definition: xlogrecovery.h:49
@ RECOVERY_TARGET_ACTION_SHUTDOWN
Definition: xlogrecovery.h:50
PGDLLIMPORT TimeLineID recoveryTargetTLIRequested
Definition: xlogrecovery.c:123
PGDLLIMPORT TimeLineID recoveryTargetTLI
Definition: xlogrecovery.c:124
PGDLLIMPORT TimestampTz recoveryTargetTime
Definition: xlogrecovery.c:92
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:99
void SetRecoveryPause(bool recoveryPause)
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:94
PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlogrecovery.c:122
PGDLLIMPORT bool wal_receiver_create_temp_slot
Definition: xlogrecovery.c:100
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
PGDLLIMPORT RecoveryTargetType recoveryTarget
Definition: xlogrecovery.c:87
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
EndOfWalRecoveryInfo * FinishWalRecovery(void)
RecoveryPauseState
Definition: xlogrecovery.h:55
@ RECOVERY_PAUSED
Definition: xlogrecovery.h:58
@ RECOVERY_NOT_PAUSED
Definition: xlogrecovery.h:56
@ RECOVERY_PAUSE_REQUESTED
Definition: xlogrecovery.h:57
PGDLLIMPORT bool StandbyMode
Definition: xlogrecovery.c:149
void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, bool *haveBackupLabel_ptr, bool *haveTblspcMap_ptr)
Definition: xlogrecovery.c:519
Size XLogRecoveryShmemSize(void)
Definition: xlogrecovery.c:454
PGDLLIMPORT bool recoveryTargetInclusive
Definition: xlogrecovery.c:88
RecoveryPauseState GetRecoveryPauseState(void)
void XLogRecoveryShmemInit(void)
Definition: xlogrecovery.c:465
PGDLLIMPORT char * recoveryEndCommand
Definition: xlogrecovery.c:85
PGDLLIMPORT char * recovery_target_time_string
Definition: xlogrecovery.c:91
TimestampTz GetLatestXTime(void)
void XLogRequestWalReceiverReply(void)
PGDLLIMPORT const char * recoveryTargetName
Definition: xlogrecovery.c:93
PGDLLIMPORT bool reachedConsistency
Definition: xlogrecovery.c:301
void RemovePromoteSignalFiles(void)
PGDLLIMPORT TransactionId recoveryTargetXid
Definition: xlogrecovery.c:90
PGDLLIMPORT char * PrimaryConnInfo
Definition: xlogrecovery.c:98
PGDLLIMPORT char * archiveCleanupCommand
Definition: xlogrecovery.c:86
PGDLLIMPORT char * recoveryRestoreCommand
Definition: xlogrecovery.c:84
PGDLLIMPORT int recoveryTargetAction
Definition: xlogrecovery.c:89