xlogrecovery.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include "access/xlogreader.h"
  14. #include "catalog/pg_control.h"
  15. #include "lib/stringinfo.h"
  16. #include "utils/timestamp.h"
  17. /*
  18. * Recovery target type.
  19. * Only set during a Point in Time recovery, not when in standby mode.
  20. */
  21. typedef enum
  22. {
  23. RECOVERY_TARGET_UNSET,
  24. RECOVERY_TARGET_XID,
  25. RECOVERY_TARGET_TIME,
  26. RECOVERY_TARGET_NAME,
  27. RECOVERY_TARGET_LSN,
  28. RECOVERY_TARGET_IMMEDIATE
  29. } RecoveryTargetType;
  30. /*
  31. * Recovery target TimeLine goal
  32. */
  33. typedef enum
  34. {
  35. RECOVERY_TARGET_TIMELINE_CONTROLFILE,
  36. RECOVERY_TARGET_TIMELINE_LATEST,
  37. RECOVERY_TARGET_TIMELINE_NUMERIC
  38. } RecoveryTargetTimeLineGoal;
  39. /* Recovery pause states */
  40. typedef enum RecoveryPauseState
  41. {
  42. RECOVERY_NOT_PAUSED, /* pause not requested */
  43. RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */
  44. RECOVERY_PAUSED /* recovery is paused */
  45. } RecoveryPauseState;
  46. /* User-settable GUC parameters */
  47. extern PGDLLIMPORT bool recoveryTargetInclusive;
  48. extern PGDLLIMPORT int recoveryTargetAction;
  49. extern PGDLLIMPORT int recovery_min_apply_delay;
  50. extern PGDLLIMPORT char *PrimaryConnInfo;
  51. extern PGDLLIMPORT char *PrimarySlotName;
  52. extern PGDLLIMPORT char *recoveryRestoreCommand;
  53. extern PGDLLIMPORT char *recoveryEndCommand;
  54. extern PGDLLIMPORT char *archiveCleanupCommand;
  55. /* indirectly set via GUC system */
  56. extern PGDLLIMPORT TransactionId recoveryTargetXid;
  57. extern PGDLLIMPORT char *recovery_target_time_string;
  58. extern PGDLLIMPORT TimestampTz recoveryTargetTime;
  59. extern PGDLLIMPORT const char *recoveryTargetName;
  60. extern PGDLLIMPORT XLogRecPtr recoveryTargetLSN;
  61. extern PGDLLIMPORT RecoveryTargetType recoveryTarget;
  62. extern PGDLLIMPORT char *PromoteTriggerFile;
  63. extern PGDLLIMPORT bool wal_receiver_create_temp_slot;
  64. extern PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal;
  65. extern PGDLLIMPORT TimeLineID recoveryTargetTLIRequested;
  66. extern PGDLLIMPORT TimeLineID recoveryTargetTLI;
  67. /* Have we already reached a consistent database state? */
  68. extern PGDLLIMPORT bool reachedConsistency;
  69. /* Are we currently in standby mode? */
  70. extern PGDLLIMPORT bool StandbyMode;
  71. extern Size XLogRecoveryShmemSize(void);
  72. extern void XLogRecoveryShmemInit(void);
  73. extern void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdownPtr, bool *haveBackupLabel, bool *haveTblspcMap);
  74. extern void PerformWalRecovery(void);
  75. /*
  76. * FinishWalRecovery() returns this. It contains information about the point
  77. * where recovery ended, and why it ended.
  78. */
  79. typedef struct
  80. {
  81. /*
  82. * Information about the last valid or applied record, after which new WAL
  83. * can be appended. 'lastRec' is the position where the last record
  84. * starts, and 'endOfLog' is its end. 'lastPage' is a copy of the last
  85. * partial page that contains endOfLog (or NULL if endOfLog is exactly at
  86. * page boundary). 'lastPageBeginPtr' is the position where the last page
  87. * begins.
  88. *
  89. * endOfLogTLI is the TLI in the filename of the XLOG segment containing
  90. * the last applied record. It could be different from lastRecTLI, if
  91. * there was a timeline switch in that segment, and we were reading the
  92. * old WAL from a segment belonging to a higher timeline.
  93. */
  94. XLogRecPtr lastRec; /* start of last valid or applied record */
  95. TimeLineID lastRecTLI;
  96. XLogRecPtr endOfLog; /* end of last valid or applied record */
  97. TimeLineID endOfLogTLI;
  98. XLogRecPtr lastPageBeginPtr; /* LSN of page that contains endOfLog */
  99. char *lastPage; /* copy of the last page, up to endOfLog */
  100. /*
  101. * abortedRecPtr is the start pointer of a broken record at end of WAL
  102. * when recovery completes; missingContrecPtr is the location of the first
  103. * contrecord that went missing. See CreateOverwriteContrecordRecord for
  104. * details.
  105. */
  106. XLogRecPtr abortedRecPtr;
  107. XLogRecPtr missingContrecPtr;
  108. /* short human-readable string describing why recovery ended */
  109. char *recoveryStopReason;
  110. /*
  111. * If standby or recovery signal file was found, these flags are set
  112. * accordingly.
  113. */
  114. bool standby_signal_file_found;
  115. bool recovery_signal_file_found;
  116. } EndOfWalRecoveryInfo;
  117. extern EndOfWalRecoveryInfo *FinishWalRecovery(void);
  118. extern void ShutdownWalRecovery(void);
  119. extern void RemovePromoteSignalFiles(void);
  120. extern bool HotStandbyActive(void);
  121. extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI);
  122. extern RecoveryPauseState GetRecoveryPauseState(void);
  123. extern void SetRecoveryPause(bool recoveryPause);
  124. extern void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream);
  125. extern TimestampTz GetLatestXTime(void);
  126. extern TimestampTz GetCurrentChunkReplayStartTime(void);
  127. extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);
  128. extern bool PromoteIsTriggered(void);
  129. extern bool CheckPromoteSignal(void);
  130. extern void WakeupRecovery(void);
  131. extern void StartupRequestWalReceiverRestart(void);
  132. extern void XLogRequestWalReceiverReply(void);
  133. extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue);
  134. extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);
  135. #endif /* XLOGRECOVERY_H */