PostgreSQL Source Code  git master
xlogutils.h
Go to the documentation of this file.
1 /*
2  * xlogutils.h
3  *
4  * Utilities for replaying WAL records.
5  *
6  * Portions Copyright (c) 1996-2024, 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 
14 #include "access/xlogreader.h"
15 #include "storage/bufmgr.h"
16 
17 /* GUC variable */
19 
20 /*
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.
26  */
27 extern PGDLLIMPORT bool InRecovery;
28 
29 /*
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).
33  *
34  * In DISABLED state, we're performing crash recovery or hot standby was
35  * disabled in postgresql.conf.
36  *
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.
40  *
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
44  * appropriate.
45  *
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.
49  */
50 typedef enum
51 {
57 
59 
60 #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
61 
62 
63 extern bool XLogHaveInvalidPages(void);
64 extern void XLogCheckInvalidPages(void);
65 
66 extern void XLogDropRelation(RelFileLocator rlocator, ForkNumber forknum);
67 extern void XLogDropDatabase(Oid dbid);
68 extern void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum,
69  BlockNumber nblocks);
70 
71 /* Result codes for XLogReadBufferForRedo[Extended] */
72 typedef enum
73 {
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) */
80 
81 /* Private data of the read_local_xlog_page_no_wait callback. */
83 {
84  bool end_of_wal; /* true, when end of WAL is reached */
86 
88  uint8 block_id, Buffer *buf);
89 extern Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id);
91  uint8 block_id,
92  ReadBufferMode mode, bool get_cleanup_lock,
93  Buffer *buf);
94 
97  Buffer recent_buffer);
98 
100 extern void FreeFakeRelcacheEntry(Relation fakerel);
101 
103  XLogRecPtr targetPagePtr, int reqLen,
104  XLogRecPtr targetRecPtr, char *cur_page);
106  XLogRecPtr targetPagePtr, int reqLen,
107  XLogRecPtr targetRecPtr,
108  char *cur_page);
110  XLogSegNo nextSegNo,
111  TimeLineID *tli_p);
113 
115  XLogRecPtr wantPage,
116  uint32 wantLength,
117  TimeLineID currTLI);
118 
119 extern void WALReadRaiseError(WALReadError *errinfo);
120 
121 #endif
uint32 BlockNumber
Definition: block.h:31
int Buffer
Definition: buf.h:23
ReadBufferMode
Definition: bufmgr.h:44
unsigned int uint32
Definition: c.h:506
#define PGDLLIMPORT
Definition: c.h:1316
unsigned char uint8
Definition: c.h:504
static PgChecksumMode mode
Definition: pg_checksums.c:56
static char * buf
Definition: pg_test_fsync.c:73
unsigned int Oid
Definition: postgres_ext.h:31
ForkNumber
Definition: relpath.h:48
Definition: regguts.h:323
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:59
uint64 XLogSegNo
Definition: xlogdefs.h:48
void wal_segment_close(XLogReaderState *state)
Definition: xlogutils.c:842
void FreeFakeRelcacheEntry(Relation fakerel)
Definition: xlogutils.c:629
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
Definition: xlogutils.c:817
PGDLLIMPORT bool InRecovery
Definition: xlogutils.c:50
void XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, uint32 wantLength, TimeLineID currTLI)
Definition: xlogutils.c:718
HotStandbyState
Definition: xlogutils.h:51
@ STANDBY_DISABLED
Definition: xlogutils.h:52
@ STANDBY_SNAPSHOT_READY
Definition: xlogutils.h:55
@ STANDBY_SNAPSHOT_PENDING
Definition: xlogutils.h:54
@ STANDBY_INITIALIZED
Definition: xlogutils.h:53
bool XLogHaveInvalidPages(void)
Definition: xlogutils.c:235
XLogRedoAction XLogReadBufferForRedo(XLogReaderState *record, uint8 block_id, Buffer *buf)
Definition: xlogutils.c:314
Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id)
Definition: xlogutils.c:326
Buffer XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode, Buffer recent_buffer)
Definition: xlogutils.c:471
void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber nblocks)
Definition: xlogutils.c:671
Relation CreateFakeRelcacheEntry(RelFileLocator rlocator)
Definition: xlogutils.c:582
int read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition: xlogutils.c:861
PGDLLIMPORT HotStandbyState standbyState
Definition: xlogutils.c:53
void XLogCheckInvalidPages(void)
Definition: xlogutils.c:245
void WALReadRaiseError(WALReadError *errinfo)
Definition: xlogutils.c:1020
struct ReadLocalXLogPageNoWaitPrivate ReadLocalXLogPageNoWaitPrivate
void XLogDropRelation(RelFileLocator rlocator, ForkNumber forknum)
Definition: xlogutils.c:641
int read_local_xlog_page_no_wait(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition: xlogutils.c:873
XLogRedoAction
Definition: xlogutils.h:73
@ BLK_RESTORED
Definition: xlogutils.h:76
@ BLK_NEEDS_REDO
Definition: xlogutils.h:74
@ BLK_DONE
Definition: xlogutils.h:75
@ BLK_NOTFOUND
Definition: xlogutils.h:77
XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, uint8 block_id, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf)
Definition: xlogutils.c:351
PGDLLIMPORT bool ignore_invalid_pages
Definition: xlogutils.c:34
void XLogDropDatabase(Oid dbid)
Definition: xlogutils.c:652