codekingpro/portable-devtools
114k
1/*2 * xlogrecovery.h3 *4 * Functions for WAL recovery and standby mode5 *6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group7 * Portions Copyright (c) 1994, Regents of the University of California8 *9 * src/include/access/xlogrecovery.h10 */11#ifndef XLOGRECOVERY_H12#define XLOGRECOVERY_H13 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 enum24{25 RECOVERY_TARGET_UNSET,26 RECOVERY_TARGET_XID,27 RECOVERY_TARGET_TIME,28 RECOVERY_TARGET_NAME,29 RECOVERY_TARGET_LSN,30 RECOVERY_TARGET_IMMEDIATE31} RecoveryTargetType;32 33/*34 * Recovery target TimeLine goal35 */36typedef enum37{38 RECOVERY_TARGET_TIMELINE_CONTROLFILE,39 RECOVERY_TARGET_TIMELINE_LATEST,40 RECOVERY_TARGET_TIMELINE_NUMERIC41} RecoveryTargetTimeLineGoal;42 43/* Recovery pause states */44typedef enum RecoveryPauseState45{46 RECOVERY_NOT_PAUSED, /* pause not requested */47 RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */48 RECOVERY_PAUSED /* recovery is paused */49} RecoveryPauseState;50 51/* User-settable GUC parameters */52extern PGDLLIMPORT bool recoveryTargetInclusive;53extern PGDLLIMPORT int recoveryTargetAction;54extern PGDLLIMPORT int recovery_min_apply_delay;55extern PGDLLIMPORT char *PrimaryConnInfo;56extern PGDLLIMPORT char *PrimarySlotName;57extern PGDLLIMPORT char *recoveryRestoreCommand;58extern PGDLLIMPORT char *recoveryEndCommand;59extern PGDLLIMPORT char *archiveCleanupCommand;60 61/* indirectly set via GUC system */62extern PGDLLIMPORT TransactionId recoveryTargetXid;63extern PGDLLIMPORT char *recovery_target_time_string;64extern PGDLLIMPORT TimestampTz recoveryTargetTime;65extern PGDLLIMPORT const char *recoveryTargetName;66extern PGDLLIMPORT XLogRecPtr recoveryTargetLSN;67extern PGDLLIMPORT RecoveryTargetType recoveryTarget;68extern PGDLLIMPORT bool wal_receiver_create_temp_slot;69extern PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal;70extern PGDLLIMPORT TimeLineID recoveryTargetTLIRequested;71extern PGDLLIMPORT TimeLineID recoveryTargetTLI;72 73/* Have we already reached a consistent database state? */74extern PGDLLIMPORT bool reachedConsistency;75 76/* Are we currently in standby mode? */77extern PGDLLIMPORT bool StandbyMode;78 79extern Size XLogRecoveryShmemSize(void);80extern void XLogRecoveryShmemInit(void);81 82extern void InitWalRecovery(ControlFileData *ControlFile,83 bool *wasShutdown_ptr, bool *haveBackupLabel_ptr,84 bool *haveTblspcMap_ptr);85extern void PerformWalRecovery(void);86 87/*88 * FinishWalRecovery() returns this. It contains information about the point89 * where recovery ended, and why it ended.90 */91typedef struct92{93 /*94 * Information about the last valid or applied record, after which new WAL95 * can be appended. 'lastRec' is the position where the last record96 * starts, and 'endOfLog' is its end. 'lastPage' is a copy of the last97 * partial page that contains endOfLog (or NULL if endOfLog is exactly at98 * page boundary). 'lastPageBeginPtr' is the position where the last page99 * begins.100 *101 * endOfLogTLI is the TLI in the filename of the XLOG segment containing102 * the last applied record. It could be different from lastRecTLI, if103 * there was a timeline switch in that segment, and we were reading the104 * old WAL from a segment belonging to a higher timeline.105 */106 XLogRecPtr lastRec; /* start of last valid or applied record */107 TimeLineID lastRecTLI;108 XLogRecPtr endOfLog; /* end of last valid or applied record */109 TimeLineID endOfLogTLI;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 WAL116 * when recovery completes; missingContrecPtr is the location of the first117 * contrecord that went missing. See CreateOverwriteContrecordRecord for118 * details.119 */120 XLogRecPtr abortedRecPtr;121 XLogRecPtr missingContrecPtr;122 123 /* short human-readable string describing why recovery ended */124 char *recoveryStopReason;125 126 /*127 * If standby or recovery signal file was found, these flags are set128 * accordingly.129 */130 bool standby_signal_file_found;131 bool recovery_signal_file_found;132} EndOfWalRecoveryInfo;133 134extern EndOfWalRecoveryInfo *FinishWalRecovery(void);135extern void ShutdownWalRecovery(void);136extern void RemovePromoteSignalFiles(void);137 138extern bool HotStandbyActive(void);139extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);140extern RecoveryPauseState GetRecoveryPauseState(void);141extern void SetRecoveryPause(bool recoveryPause);142extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);143extern TimestampTz GetLatestXTime(void);144extern TimestampTz GetCurrentChunkReplayStartTime(void);145extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);146 147extern bool PromoteIsTriggered(void);148extern bool CheckPromoteSignal(void);149extern void WakeupRecovery(void);150 151extern void StartupRequestWalReceiverRestart(void);152extern void XLogRequestWalReceiverReply(void);153 154extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue);155 156extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);157 158#endif /* XLOGRECOVERY_H */159 