codekingpro/portable-devtools
116k
1/*2 * xlogutils.h3 *4 * Utilities for replaying WAL records.5 *6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group7 * Portions Copyright (c) 1994, Regents of the University of California8 *9 * src/include/access/xlogutils.h10 */11#ifndef XLOG_UTILS_H12#define XLOG_UTILS_H13 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 startup19 * process. This local variable continues to be used in many parts of the20 * code to indicate actions taken by RecoveryManagers. Other processes that21 * potentially perform work during recovery should check RecoveryInProgress().22 * See XLogCtl notes in xlog.c.23 */24extern 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 (so29 * InHotStandby will read as false).30 *31 * In DISABLED state, we're performing crash recovery or hot standby was32 * disabled in postgresql.conf.33 *34 * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but35 * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record36 * to initialize our primary-transaction tracking system.37 *38 * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING39 * state. The tracked information might still be incomplete, so we can't allow40 * connections yet, but redo functions must update the in-memory state when41 * appropriate.42 *43 * In SNAPSHOT_READY mode, we have full knowledge of transactions that are44 * (or were) running on the primary at the current WAL location. Snapshots45 * can be taken, and read-only queries can be run.46 */47typedef enum48{49 STANDBY_DISABLED,50 STANDBY_INITIALIZED,51 STANDBY_SNAPSHOT_PENDING,52 STANDBY_SNAPSHOT_READY53} HotStandbyState;54 55extern PGDLLIMPORT HotStandbyState standbyState;56 57#define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)58 59 60extern bool XLogHaveInvalidPages(void);61extern void XLogCheckInvalidPages(void);62 63extern void XLogDropRelation(RelFileLocator rlocator, ForkNumber forknum);64extern void XLogDropDatabase(Oid dbid);65extern void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum,66 BlockNumber nblocks);67 68/* Result codes for XLogReadBufferForRedo[Extended] */69typedef enum70{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 not75 * need to be replayed) */76} XLogRedoAction;77 78/* Private data of the read_local_xlog_page_no_wait callback. */79typedef struct ReadLocalXLogPageNoWaitPrivate80{81 bool end_of_wal; /* true, when end of WAL is reached */82} ReadLocalXLogPageNoWaitPrivate;83 84extern XLogRedoAction XLogReadBufferForRedo(XLogReaderState *record,85 uint8 block_id, Buffer *buf);86extern Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id);87extern XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record,88 uint8 block_id,89 ReadBufferMode mode, bool get_cleanup_lock,90 Buffer *buf);91 92extern Buffer XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum,93 BlockNumber blkno, ReadBufferMode mode,94 Buffer recent_buffer);95 96extern Relation CreateFakeRelcacheEntry(RelFileLocator rlocator);97extern void FreeFakeRelcacheEntry(Relation fakerel);98 99extern int read_local_xlog_page(XLogReaderState *state,100 XLogRecPtr targetPagePtr, int reqLen,101 XLogRecPtr targetRecPtr, char *cur_page);102extern int read_local_xlog_page_no_wait(XLogReaderState *state,103 XLogRecPtr targetPagePtr, int reqLen,104 XLogRecPtr targetRecPtr,105 char *cur_page);106extern void wal_segment_open(XLogReaderState *state,107 XLogSegNo nextSegNo,108 TimeLineID *tli_p);109extern void wal_segment_close(XLogReaderState *state);110 111extern void XLogReadDetermineTimeline(XLogReaderState *state,112 XLogRecPtr wantPage,113 uint32 wantLength,114 TimeLineID currTLI);115 116extern void WALReadRaiseError(WALReadError *errinfo);117 118#endif119 