4 * Utilities for replaying WAL records.
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/access/xlogutils.h
14 #include "access/xlogreader.h"
15 #include "storage/bufmgr.h"
18 extern PGDLLIMPORT
bool ignore_invalid_pages
;
21 * Prior to 8.4, all activity during recovery was carried out by the startup
22 * process. This local variable continues to be used in many parts of the
23 * code to indicate actions taken by RecoveryManagers. Other processes that
24 * potentially perform work during recovery should check RecoveryInProgress().
25 * See XLogCtl notes in xlog.c.
27 extern PGDLLIMPORT
bool InRecovery
;
30 * Like InRecovery, standbyState is only valid in the startup process.
31 * In all other processes it will have the value STANDBY_DISABLED (so
32 * InHotStandby will read as false).
34 * In DISABLED state, we're performing crash recovery or hot standby was
35 * disabled in postgresql.conf.
37 * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but
38 * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record
39 * to initialize our primary-transaction tracking system.
41 * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING
42 * state. The tracked information might still be incomplete, so we can't allow
43 * connections yet, but redo functions must update the in-memory state when
46 * In SNAPSHOT_READY mode, we have full knowledge of transactions that are
47 * (or were) running on the primary at the current WAL location. Snapshots
48 * can be taken, and read-only queries can be run.
54 STANDBY_SNAPSHOT_PENDING
,
55 STANDBY_SNAPSHOT_READY
,
58 extern PGDLLIMPORT HotStandbyState standbyState
;
60 #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
63 extern bool XLogHaveInvalidPages(void);
64 extern void XLogCheckInvalidPages(void);
66 extern void XLogDropRelation(RelFileLocator rlocator
, ForkNumber forknum
);
67 extern void XLogDropDatabase(Oid dbid
);
68 extern void XLogTruncateRelation(RelFileLocator rlocator
, ForkNumber forkNum
,
71 /* Result codes for XLogReadBufferForRedo[Extended] */
74 BLK_NEEDS_REDO
, /* changes from WAL record need to be applied */
75 BLK_DONE
, /* block is already up-to-date */
76 BLK_RESTORED
, /* block was restored from a full-page image */
77 BLK_NOTFOUND
, /* block was not found (and hence does not
78 * need to be replayed) */
81 /* Private data of the read_local_xlog_page_no_wait callback. */
82 typedef struct ReadLocalXLogPageNoWaitPrivate
84 bool end_of_wal
; /* true, when end of WAL is reached */
85 } ReadLocalXLogPageNoWaitPrivate
;
87 extern XLogRedoAction
XLogReadBufferForRedo(XLogReaderState
*record
,
88 uint8 block_id
, Buffer
*buf
);
89 extern Buffer
XLogInitBufferForRedo(XLogReaderState
*record
, uint8 block_id
);
90 extern XLogRedoAction
XLogReadBufferForRedoExtended(XLogReaderState
*record
,
92 ReadBufferMode mode
, bool get_cleanup_lock
,
95 extern Buffer
XLogReadBufferExtended(RelFileLocator rlocator
, ForkNumber forknum
,
96 BlockNumber blkno
, ReadBufferMode mode
,
97 Buffer recent_buffer
);
99 extern Relation
CreateFakeRelcacheEntry(RelFileLocator rlocator
);
100 extern void FreeFakeRelcacheEntry(Relation fakerel
);
102 extern int read_local_xlog_page(XLogReaderState
*state
,
103 XLogRecPtr targetPagePtr
, int reqLen
,
104 XLogRecPtr targetRecPtr
, char *cur_page
);
105 extern int read_local_xlog_page_no_wait(XLogReaderState
*state
,
106 XLogRecPtr targetPagePtr
, int reqLen
,
107 XLogRecPtr targetRecPtr
,
109 extern void wal_segment_open(XLogReaderState
*state
,
112 extern void wal_segment_close(XLogReaderState
*state
);
114 extern void XLogReadDetermineTimeline(XLogReaderState
*state
,
119 extern void WALReadRaiseError(WALReadError
*errinfo
);