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-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 
14 #include "access/xlogreader.h"
15 #include "storage/bufmgr.h"
16 
17 /*
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.
23  */
24 extern PGDLLIMPORT bool InRecovery;
25 
26 /*
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).
30  *
31  * In DISABLED state, we're performing crash recovery or hot standby was
32  * disabled in postgresql.conf.
33  *
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.
37  *
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
41  * appropriate.
42  *
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.
46  */
47 typedef enum
48 {
54 
56 
57 #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
58 
59 
60 extern bool XLogHaveInvalidPages(void);
61 extern void XLogCheckInvalidPages(void);
62 
63 extern void XLogDropRelation(RelFileLocator rlocator, ForkNumber forknum);
64 extern void XLogDropDatabase(Oid dbid);
65 extern void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum,
66  BlockNumber nblocks);
67 
68 /* Result codes for XLogReadBufferForRedo[Extended] */
69 typedef enum
70 {
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) */
77 
78 /* Private data of the read_local_xlog_page_no_wait callback. */
80 {
81  bool end_of_wal; /* true, when end of WAL is reached */
83 
85  uint8 buffer_id, Buffer *buf);
86 extern Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id);
88  uint8 buffer_id,
89  ReadBufferMode mode, bool get_cleanup_lock,
90  Buffer *buf);
91 
94  Buffer recent_buffer);
95 
97 extern void FreeFakeRelcacheEntry(Relation fakerel);
98 
100  XLogRecPtr targetPagePtr, int reqLen,
101  XLogRecPtr targetRecPtr, char *cur_page);
103  XLogRecPtr targetPagePtr, int reqLen,
104  XLogRecPtr targetRecPtr,
105  char *cur_page);
107  XLogSegNo nextSegNo,
108  TimeLineID *tli_p);
110 
112  XLogRecPtr wantPage,
113  uint32 wantLength,
114  TimeLineID currTLI);
115 
116 extern void WALReadRaiseError(WALReadError *errinfo);
117 
118 #endif
uint32 BlockNumber
Definition: block.h:31
int Buffer
Definition: buf.h:23
ReadBufferMode
Definition: bufmgr.h:38
unsigned int uint32
Definition: c.h:452
#define PGDLLIMPORT
Definition: c.h:1342
unsigned char uint8
Definition: c.h:450
static PgChecksumMode mode
Definition: pg_checksums.c:65
static char * buf
Definition: pg_test_fsync.c:67
unsigned int Oid
Definition: postgres_ext.h:31
ForkNumber
Definition: relpath.h:41
Definition: regguts.h:318
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:857
void FreeFakeRelcacheEntry(Relation fakerel)
Definition: xlogutils.c:641
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
Definition: xlogutils.c:832
XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, uint8 buffer_id, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf)
Definition: xlogutils.c:354
PGDLLIMPORT bool InRecovery
Definition: xlogutils.c:53
void XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, uint32 wantLength, TimeLineID currTLI)
Definition: xlogutils.c:733
HotStandbyState
Definition: xlogutils.h:48
@ STANDBY_DISABLED
Definition: xlogutils.h:49
@ STANDBY_SNAPSHOT_READY
Definition: xlogutils.h:52
@ STANDBY_SNAPSHOT_PENDING
Definition: xlogutils.h:51
@ STANDBY_INITIALIZED
Definition: xlogutils.h:50
bool XLogHaveInvalidPages(void)
Definition: xlogutils.c:238
Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id)
Definition: xlogutils.c:329
Buffer XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode, Buffer recent_buffer)
Definition: xlogutils.c:472
void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber nblocks)
Definition: xlogutils.c:686
Relation CreateFakeRelcacheEntry(RelFileLocator rlocator)
Definition: xlogutils.c:598
XLogRedoAction XLogReadBufferForRedo(XLogReaderState *record, uint8 buffer_id, Buffer *buf)
Definition: xlogutils.c:317
int read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition: xlogutils.c:876
PGDLLIMPORT HotStandbyState standbyState
Definition: xlogutils.c:56
void XLogCheckInvalidPages(void)
Definition: xlogutils.c:248
void WALReadRaiseError(WALReadError *errinfo)
Definition: xlogutils.c:1040
struct ReadLocalXLogPageNoWaitPrivate ReadLocalXLogPageNoWaitPrivate
void XLogDropRelation(RelFileLocator rlocator, ForkNumber forknum)
Definition: xlogutils.c:656
int read_local_xlog_page_no_wait(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition: xlogutils.c:888
XLogRedoAction
Definition: xlogutils.h:70
@ BLK_RESTORED
Definition: xlogutils.h:73
@ BLK_NEEDS_REDO
Definition: xlogutils.h:71
@ BLK_DONE
Definition: xlogutils.h:72
@ BLK_NOTFOUND
Definition: xlogutils.h:74
void XLogDropDatabase(Oid dbid)
Definition: xlogutils.c:667