Fix possible crash in pg_dump with identity sequences.
[pgsql.git] / src / include / access / xlogutils.h
blob20950ce0336ca76706f7ce68e2ec842d771758aa
1 /*
2 * xlogutils.h
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
11 #ifndef XLOG_UTILS_H
12 #define XLOG_UTILS_H
14 #include "access/xlogreader.h"
15 #include "storage/bufmgr.h"
17 /* GUC variable */
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
44 * appropriate.
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.
50 typedef enum
52 STANDBY_DISABLED,
53 STANDBY_INITIALIZED,
54 STANDBY_SNAPSHOT_PENDING,
55 STANDBY_SNAPSHOT_READY,
56 } HotStandbyState;
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,
69 BlockNumber nblocks);
71 /* Result codes for XLogReadBufferForRedo[Extended] */
72 typedef enum
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) */
79 } XLogRedoAction;
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,
91 uint8 block_id,
92 ReadBufferMode mode, bool get_cleanup_lock,
93 Buffer *buf);
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,
108 char *cur_page);
109 extern void wal_segment_open(XLogReaderState *state,
110 XLogSegNo nextSegNo,
111 TimeLineID *tli_p);
112 extern void wal_segment_close(XLogReaderState *state);
114 extern void XLogReadDetermineTimeline(XLogReaderState *state,
115 XLogRecPtr wantPage,
116 uint32 wantLength,
117 TimeLineID currTLI);
119 extern void WALReadRaiseError(WALReadError *errinfo);
121 #endif