PostgreSQL Source Code: src/include/access/xlogrecovery.h Source File

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-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 */
23 typedef enum
24{
25 RECOVERY_TARGET_UNSET,
26 RECOVERY_TARGET_XID,
27 RECOVERY_TARGET_TIME,
28 RECOVERY_TARGET_NAME,
29 RECOVERY_TARGET_LSN,
30 RECOVERY_TARGET_IMMEDIATE,
31} RecoveryTargetType;
32
33/*
34 * Recovery target TimeLine goal
35 */
36 typedef enum
37{
38 RECOVERY_TARGET_TIMELINE_CONTROLFILE,
39 RECOVERY_TARGET_TIMELINE_LATEST,
40 RECOVERY_TARGET_TIMELINE_NUMERIC,
41} RecoveryTargetTimeLineGoal;
42
43/*
44 * Recovery target action.
45 */
46 typedef enum
47{
48 RECOVERY_TARGET_ACTION_PAUSE,
49 RECOVERY_TARGET_ACTION_PROMOTE,
50 RECOVERY_TARGET_ACTION_SHUTDOWN,
51} RecoveryTargetAction;
52
53/* Recovery pause states */
54 typedef enum RecoveryPauseState
55{
56 RECOVERY_NOT_PAUSED, /* pause not requested */
57 RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */
58 RECOVERY_PAUSED, /* recovery is paused */
59 } RecoveryPauseState;
60
61/* User-settable GUC parameters */
62extern PGDLLIMPORT bool recoveryTargetInclusive;
63extern PGDLLIMPORT int recoveryTargetAction;
64extern PGDLLIMPORT int recovery_min_apply_delay;
65extern PGDLLIMPORT char *PrimaryConnInfo;
66extern PGDLLIMPORT char *PrimarySlotName;
67extern PGDLLIMPORT char *recoveryRestoreCommand;
68extern PGDLLIMPORT char *recoveryEndCommand;
69extern PGDLLIMPORT char *archiveCleanupCommand;
70
71/* indirectly set via GUC system */
72extern PGDLLIMPORT TransactionId recoveryTargetXid;
73extern PGDLLIMPORT char *recovery_target_time_string;
74extern PGDLLIMPORT TimestampTz recoveryTargetTime;
75extern PGDLLIMPORT const char *recoveryTargetName;
76extern PGDLLIMPORT XLogRecPtr recoveryTargetLSN;
77extern PGDLLIMPORT RecoveryTargetType recoveryTarget;
78extern PGDLLIMPORT bool wal_receiver_create_temp_slot;
79extern PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal;
80extern PGDLLIMPORT TimeLineID recoveryTargetTLIRequested;
81extern PGDLLIMPORT TimeLineID recoveryTargetTLI;
82
83/* Have we already reached a consistent database state? */
84extern PGDLLIMPORT bool reachedConsistency;
85
86/* Are we currently in standby mode? */
87extern PGDLLIMPORT bool StandbyMode;
88
89extern Size XLogRecoveryShmemSize(void);
90extern void XLogRecoveryShmemInit(void);
91
92extern void InitWalRecovery(ControlFileData *ControlFile,
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 */
101 typedef 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 */
117 TimeLineID lastRecTLI;
118 XLogRecPtr endOfLog; /* end of last valid or applied record */
119 TimeLineID endOfLogTLI;
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 */
130 XLogRecPtr abortedRecPtr;
131 XLogRecPtr missingContrecPtr;
132
133 /* short human-readable string describing why recovery ended */
134 char *recoveryStopReason;
135
136 /*
137 * If standby or recovery signal file was found, these flags are set
138 * accordingly.
139 */
140 bool standby_signal_file_found;
141 bool recovery_signal_file_found;
142} EndOfWalRecoveryInfo;
143
144extern EndOfWalRecoveryInfo *FinishWalRecovery(void);
145extern void ShutdownWalRecovery(void);
146extern void RemovePromoteSignalFiles(void);
147
148extern bool HotStandbyActive(void);
149extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
150extern RecoveryPauseState GetRecoveryPauseState(void);
151extern void SetRecoveryPause(bool recoveryPause);
152extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
153extern TimestampTz GetLatestXTime(void);
154extern TimestampTz GetCurrentChunkReplayStartTime(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
bool standby_signal_file_found
Definition: xlogrecovery.h:140
XLogRecPtr lastRec
Definition: xlogrecovery.h:116
XLogRecPtr endOfLog
Definition: xlogrecovery.h:118
TimeLineID lastRecTLI
Definition: xlogrecovery.h:117
XLogRecPtr lastPageBeginPtr
Definition: xlogrecovery.h:121
XLogRecPtr abortedRecPtr
Definition: xlogrecovery.h:130
char * recoveryStopReason
Definition: xlogrecovery.h:134
XLogRecPtr missingContrecPtr
Definition: xlogrecovery.h:131
TimeLineID endOfLogTLI
Definition: xlogrecovery.h:119
bool recovery_signal_file_found
Definition: xlogrecovery.h:141
static ControlFileData * ControlFile
Definition: xlog.c:574
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:62
bool HotStandbyActive(void)
Definition: xlogrecovery.c:4524
PGDLLIMPORT int recovery_min_apply_delay
Definition: xlogrecovery.c:95
void ShutdownWalRecovery(void)
Definition: xlogrecovery.c:1617
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)
Definition: xlogrecovery.c:4397
void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue)
Definition: xlogrecovery.c:4681
void PerformWalRecovery(void)
Definition: xlogrecovery.c:1662
bool CheckPromoteSignal(void)
Definition: xlogrecovery.c:4485
PGDLLIMPORT char * PrimarySlotName
Definition: xlogrecovery.c:99
void SetRecoveryPause(bool recoveryPause)
Definition: xlogrecovery.c:3103
XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI)
Definition: xlogrecovery.c:4584
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)
Definition: xlogrecovery.c:4500
void xlog_outdesc(StringInfo buf, XLogReaderState *record)
Definition: xlogrecovery.c:2310
bool PromoteIsTriggered(void)
Definition: xlogrecovery.c:4416
TimestampTz GetCurrentChunkReplayStartTime(void)
Definition: xlogrecovery.c:4648
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)
Definition: xlogrecovery.c:4561
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
Definition: xlogrecovery.c:4664
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)
Definition: xlogrecovery.c:1467
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)
Definition: xlogrecovery.c:3083
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)
Definition: xlogrecovery.c:4618
void XLogRequestWalReceiverReply(void)
Definition: xlogrecovery.c:4509
PGDLLIMPORT const char * recoveryTargetName
Definition: xlogrecovery.c:93
PGDLLIMPORT bool reachedConsistency
Definition: xlogrecovery.c:301
void RemovePromoteSignalFiles(void)
Definition: xlogrecovery.c:4476
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

AltStyle によって変換されたページ (->オリジナル) /