xlogutils.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * xlogutils.h
  3. *
  4. * Utilities for replaying WAL records.
  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/xlogutils.h
  10. */
  11. #ifndef XLOG_UTILS_H
  12. #define XLOG_UTILS_H
  13. #include "access/xlogreader.h"
  14. #include "storage/bufmgr.h"
  15. /*
  16. * Prior to 8.4, all activity during recovery was carried out by the startup
  17. * process. This local variable continues to be used in many parts of the
  18. * code to indicate actions taken by RecoveryManagers. Other processes that
  19. * potentially perform work during recovery should check RecoveryInProgress().
  20. * See XLogCtl notes in xlog.c.
  21. */
  22. extern PGDLLIMPORT bool InRecovery;
  23. /*
  24. * Like InRecovery, standbyState is only valid in the startup process.
  25. * In all other processes it will have the value STANDBY_DISABLED (so
  26. * InHotStandby will read as false).
  27. *
  28. * In DISABLED state, we're performing crash recovery or hot standby was
  29. * disabled in postgresql.conf.
  30. *
  31. * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but
  32. * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record
  33. * to initialize our primary-transaction tracking system.
  34. *
  35. * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING
  36. * state. The tracked information might still be incomplete, so we can't allow
  37. * connections yet, but redo functions must update the in-memory state when
  38. * appropriate.
  39. *
  40. * In SNAPSHOT_READY mode, we have full knowledge of transactions that are
  41. * (or were) running on the primary at the current WAL location. Snapshots
  42. * can be taken, and read-only queries can be run.
  43. */
  44. typedef enum
  45. {
  46. STANDBY_DISABLED,
  47. STANDBY_INITIALIZED,
  48. STANDBY_SNAPSHOT_PENDING,
  49. STANDBY_SNAPSHOT_READY
  50. } HotStandbyState;
  51. extern PGDLLIMPORT HotStandbyState standbyState;
  52. #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
  53. extern bool XLogHaveInvalidPages(void);
  54. extern void XLogCheckInvalidPages(void);
  55. extern void XLogDropRelation(RelFileNode rnode, ForkNumber forknum);
  56. extern void XLogDropDatabase(Oid dbid);
  57. extern void XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum,
  58. BlockNumber nblocks);
  59. /* Result codes for XLogReadBufferForRedo[Extended] */
  60. typedef enum
  61. {
  62. BLK_NEEDS_REDO, /* changes from WAL record need to be applied */
  63. BLK_DONE, /* block is already up-to-date */
  64. BLK_RESTORED, /* block was restored from a full-page image */
  65. BLK_NOTFOUND /* block was not found (and hence does not
  66. * need to be replayed) */
  67. } XLogRedoAction;
  68. /* Private data of the read_local_xlog_page_no_wait callback. */
  69. typedef struct ReadLocalXLogPageNoWaitPrivate
  70. {
  71. bool end_of_wal; /* true, when end of WAL is reached */
  72. } ReadLocalXLogPageNoWaitPrivate;
  73. extern XLogRedoAction XLogReadBufferForRedo(XLogReaderState *record,
  74. uint8 buffer_id, Buffer *buf);
  75. extern Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id);
  76. extern XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record,
  77. uint8 buffer_id,
  78. ReadBufferMode mode, bool get_cleanup_lock,
  79. Buffer *buf);
  80. extern Buffer XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
  81. BlockNumber blkno, ReadBufferMode mode,
  82. Buffer recent_buffer);
  83. extern Relation CreateFakeRelcacheEntry(RelFileNode rnode);
  84. extern void FreeFakeRelcacheEntry(Relation fakerel);
  85. extern int read_local_xlog_page(XLogReaderState *state,
  86. XLogRecPtr targetPagePtr, int reqLen,
  87. XLogRecPtr targetRecPtr, char *cur_page);
  88. extern int read_local_xlog_page_no_wait(XLogReaderState *state,
  89. XLogRecPtr targetPagePtr, int reqLen,
  90. XLogRecPtr targetRecPtr,
  91. char *cur_page);
  92. extern void wal_segment_open(XLogReaderState *state,
  93. XLogSegNo nextSegNo,
  94. TimeLineID *tli_p);
  95. extern void wal_segment_close(XLogReaderState *state);
  96. extern void XLogReadDetermineTimeline(XLogReaderState *state,
  97. XLogRecPtr wantPage,
  98. uint32 wantLength,
  99. TimeLineID currTLI);
  100. extern void WALReadRaiseError(WALReadError *errinfo);
  101. #endif