4 * Utilities for replaying WAL records.
6 * Portions Copyright (c) 1996-2021, 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 * Prior to 8.4, all activity during recovery was carried out by the startup
19 * process. This local variable continues to be used in many parts of the
20 * code to indicate actions taken by RecoveryManagers. Other processes that
21 * potentially perform work during recovery should check RecoveryInProgress().
22 * See XLogCtl notes in xlog.c.
24 extern bool InRecovery
;
27 * Like InRecovery, standbyState is only valid in the startup process.
28 * In all other processes it will have the value STANDBY_DISABLED (so
29 * InHotStandby will read as false).
31 * In DISABLED state, we're performing crash recovery or hot standby was
32 * disabled in postgresql.conf.
34 * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but
35 * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record
36 * to initialize our primary-transaction tracking system.
38 * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING
39 * state. The tracked information might still be incomplete, so we can't allow
40 * connections yet, but redo functions must update the in-memory state when
43 * In SNAPSHOT_READY mode, we have full knowledge of transactions that are
44 * (or were) running on the primary at the current WAL location. Snapshots
45 * can be taken, and read-only queries can be run.
51 STANDBY_SNAPSHOT_PENDING
,
52 STANDBY_SNAPSHOT_READY
55 extern HotStandbyState standbyState
;
57 #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
60 extern bool XLogHaveInvalidPages(void);
61 extern void XLogCheckInvalidPages(void);
63 extern void XLogDropRelation(RelFileNode rnode
, ForkNumber forknum
);
64 extern void XLogDropDatabase(Oid dbid
);
65 extern void XLogTruncateRelation(RelFileNode rnode
, ForkNumber forkNum
,
68 /* Result codes for XLogReadBufferForRedo[Extended] */
71 BLK_NEEDS_REDO
, /* changes from WAL record need to be applied */
72 BLK_DONE
, /* block is already up-to-date */
73 BLK_RESTORED
, /* block was restored from a full-page image */
74 BLK_NOTFOUND
/* block was not found (and hence does not
75 * need to be replayed) */
78 extern XLogRedoAction
XLogReadBufferForRedo(XLogReaderState
*record
,
79 uint8 buffer_id
, Buffer
*buf
);
80 extern Buffer
XLogInitBufferForRedo(XLogReaderState
*record
, uint8 block_id
);
81 extern XLogRedoAction
XLogReadBufferForRedoExtended(XLogReaderState
*record
,
83 ReadBufferMode mode
, bool get_cleanup_lock
,
86 extern Buffer
XLogReadBufferExtended(RelFileNode rnode
, ForkNumber forknum
,
87 BlockNumber blkno
, ReadBufferMode mode
);
89 extern Relation
CreateFakeRelcacheEntry(RelFileNode rnode
);
90 extern void FreeFakeRelcacheEntry(Relation fakerel
);
92 extern int read_local_xlog_page(XLogReaderState
*state
,
93 XLogRecPtr targetPagePtr
, int reqLen
,
94 XLogRecPtr targetRecPtr
, char *cur_page
);
95 extern void wal_segment_open(XLogReaderState
*state
,
98 extern void wal_segment_close(XLogReaderState
*state
);
100 extern void XLogReadDetermineTimeline(XLogReaderState
*state
,
101 XLogRecPtr wantPage
, uint32 wantLength
);
103 extern void WALReadRaiseError(WALReadError
*errinfo
);