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-2021, 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 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(RelFileNode rnode, ForkNumber forknum);
64 extern void XLogDropDatabase(Oid dbid);
65 extern void XLogTruncateRelation(RelFileNode rnode, 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 
79  uint8 buffer_id, Buffer *buf);
80 extern Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id);
82  uint8 buffer_id,
83  ReadBufferMode mode, bool get_cleanup_lock,
84  Buffer *buf);
85 
88 
90 extern void FreeFakeRelcacheEntry(Relation fakerel);
91 
93  XLogRecPtr targetPagePtr, int reqLen,
94  XLogRecPtr targetRecPtr, char *cur_page);
96  XLogSegNo nextSegNo,
97  TimeLineID *tli_p);
99 
101  XLogRecPtr wantPage, uint32 wantLength);
102 
103 extern void WALReadRaiseError(WALReadError *errinfo);
104 
105 #endif
static PgChecksumMode mode
Definition: pg_checksums.c:65
uint32 TimeLineID
Definition: xlogdefs.h:59
XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, uint8 buffer_id, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf)
Definition: xlogutils.c:349
unsigned char uint8
Definition: c.h:439
void XLogDropRelation(RelFileNode rnode, ForkNumber forknum)
Definition: xlogutils.c:632
Buffer XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode)
Definition: xlogutils.c:459
uint32 BlockNumber
Definition: block.h:31
unsigned int Oid
Definition: postgres_ext.h:31
void wal_segment_close(XLogReaderState *state)
Definition: xlogutils.c:829
void XLogCheckInvalidPages(void)
Definition: xlogutils.c:243
Relation CreateFakeRelcacheEntry(RelFileNode rnode)
Definition: xlogutils.c:574
bool XLogHaveInvalidPages(void)
Definition: xlogutils.c:233
bool InRecovery
Definition: xlogutils.c:52
static char * buf
Definition: pg_test_fsync.c:68
uint64 XLogSegNo
Definition: xlogdefs.h:48
unsigned int uint32
Definition: c.h:441
HotStandbyState standbyState
Definition: xlogutils.c:55
void FreeFakeRelcacheEntry(Relation fakerel)
Definition: xlogutils.c:617
ForkNumber
Definition: relpath.h:40
ReadBufferMode
Definition: bufmgr.h:37
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
Definition: xlogutils.c:804
XLogRedoAction XLogReadBufferForRedo(XLogReaderState *record, uint8 buffer_id, Buffer *buf)
Definition: xlogutils.c:312
int read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition: xlogutils.c:848
uint64 XLogRecPtr
Definition: xlogdefs.h:21
Definition: regguts.h:317
void XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, uint32 wantLength)
Definition: xlogutils.c:707
XLogRedoAction
Definition: xlogutils.h:69
void WALReadRaiseError(WALReadError *errinfo)
Definition: xlogutils.c:975
Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id)
Definition: xlogutils.c:324
HotStandbyState
Definition: xlogutils.h:47
void XLogDropDatabase(Oid dbid)
Definition: xlogutils.c:643
int Buffer
Definition: buf.h:23
void XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum, BlockNumber nblocks)
Definition: xlogutils.c:662