4 * PostgreSQL write-ahead log manager
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/access/xlog.h
36/* these variables are GUC parameters related to XLOG */
79/* Compression algorithms for WAL */
98/* Is WAL archiving enabled (always or only while server is running normally)? */
99 #define XLogArchivingActive() \
100 (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode > ARCHIVE_MODE_OFF)
101/* Is WAL archiving enabled always (even during recovery)? */
102 #define XLogArchivingAlways() \
103 (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode == ARCHIVE_MODE_ALWAYS)
106 * Is WAL-logging necessary for archival or log-shipping, or can we skip
107 * WAL-logging if we fsync() the data before committing instead?
109 #define XLogIsNeeded() (wal_level >= WAL_LEVEL_REPLICA)
112 * Is a full-page image needed for hint bit updates?
114 * Normally, we don't WAL-log hint bit updates, but if checksums are enabled,
115 * we have to protect them against torn page writes. When you only set
116 * individual bits on a page, it's still consistent no matter what combination
117 * of the bits make it to disk, but the checksum wouldn't match. Also WAL-log
118 * them if forced by wal_log_hints=on.
120 #define XLogHintBitIsNeeded() (DataChecksumsEnabled() || wal_log_hints)
122/* Do we need to WAL-log information required only for Hot Standby and logical replication? */
123 #define XLogStandbyInfoActive() (wal_level >= WAL_LEVEL_REPLICA)
125/* Do we need to WAL-log information required only for logical replication? */
126 #define XLogLogicalInfoActive() (wal_level >= WAL_LEVEL_LOGICAL)
133 * OR-able request flag bits for checkpoints. The "cause" bits are used only
134 * for logging purposes. Note: the flags must be defined so that it's
135 * sensible to OR together request flags arising from different requestors.
138/* These directly affect the behavior of CreateCheckPoint and subsidiaries */
139 #define CHECKPOINT_IS_SHUTDOWN 0x0001 /* Checkpoint is for shutdown */
140 #define CHECKPOINT_END_OF_RECOVERY 0x0002 /* Like shutdown checkpoint, but
141 * issued at end of WAL recovery */
142 #define CHECKPOINT_FAST 0x0004 /* Do it without delays */
143 #define CHECKPOINT_FORCE 0x0008 /* Force even if no activity */
144#define CHECKPOINT_FLUSH_UNLOGGED 0x0010 /* Flush unlogged tables */
145 /* These are important to RequestCheckpoint */
146 #define CHECKPOINT_WAIT 0x0020 /* Wait for completion */
147#define CHECKPOINT_REQUESTED 0x0040 /* Checkpoint request has been made */
148 /* These indicate the cause of a checkpoint request */
149 #define CHECKPOINT_CAUSE_XLOG 0x0080 /* XLOG consumption */
150#define CHECKPOINT_CAUSE_TIME 0x0100 /* Elapsed time */
153 * Flag bits for the record being inserted, set using XLogSetRecordFlags().
155 #define XLOG_INCLUDE_ORIGIN 0x01 /* include the replication origin */
156#define XLOG_MARK_UNIMPORTANT 0x02 /* record not important for durability */
159 /* Checkpoint statistics */
178 * times, which is not necessarily the
179 * same as the total elapsed time for the
180 * entire sync phase. */
186 * GetWALAvailability return codes
205 bool topxid_included);
263 * Routines used by xlogrecovery.c to call back into xlog.c during recovery.
274 * Routines to start, stop, and get status of a base backup.
278 * Session-level status of base backups
280 * This is used in parallel with the shared memory status to control parallel
281 * execution of base backup functions for a given session, be it a backend
282 * dedicated to replication or a normal backend connected to a database. The
283 * update of the session-level status happens at the same time as the shared
284 * memory counters to keep a consistent global and local state of the backups
301 /* File path names (all relative to $PGDATA) */
302 #define RECOVERY_SIGNAL_FILE "recovery.signal"
303 #define STANDBY_SIGNAL_FILE "standby.signal"
304 #define BACKUP_LABEL_FILE "backup_label"
305#define BACKUP_LABEL_OLD "backup_label.old"
307 #define TABLESPACE_MAP "tablespace_map"
308#define TABLESPACE_MAP_OLD "tablespace_map.old"
310 /* files to signal promotion to primary */
311#define PROMOTE_SIGNAL_FILE "promote"
static int fd(const char *x, int i)
uint64 ckpt_agg_sync_time
TimestampTz ckpt_sync_end_t
DecodedXLogRecord * record
int XLogFileInit(XLogSegNo logsegno, TimeLineID logtli)
uint64 GetSystemIdentifier(void)
void UpdateFullPageWrites(void)
bool RecoveryInProgress(void)
void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p)
TimeLineID GetWALInsertionTimeLine(void)
PGDLLIMPORT bool log_checkpoints
void do_pg_abort_backup(int code, Datum arg)
XLogSegNo XLogGetLastRemovedSegno(void)
void xlog_desc(StringInfo buf, struct XLogReaderState *record)
Size WALReadFromBuffers(char *dstbuf, XLogRecPtr startptr, Size count, TimeLineID tli)
XLogRecPtr GetRedoRecPtr(void)
void SetInstallXLogFileSegmentActive(void)
XLogRecPtr XLogInsertRecord(struct XLogRecData *rdata, XLogRecPtr fpw_lsn, uint8 flags, int num_fpi, bool topxid_included)
bool IsInstallXLogFileSegmentActive(void)
PGDLLIMPORT XLogRecPtr XactLastRecEnd
void BootStrapXLOG(uint32 data_checksum_version)
bool CreateRestartPoint(int flags)
PGDLLIMPORT int wal_sync_method
PGDLLIMPORT bool EnableHotStandby
XLogRecPtr GetInsertRecPtr(void)
SessionBackupState get_backup_status(void)
void CheckXLogRemoved(XLogSegNo segno, TimeLineID tli)
PGDLLIMPORT CheckpointStatsData CheckpointStats
WALAvailability GetWALAvailability(XLogRecPtr targetLSN)
PGDLLIMPORT int wal_retrieve_retry_interval
void ShutdownXLOG(int code, Datum arg)
bool DataChecksumsEnabled(void)
RecoveryState GetRecoveryState(void)
const char * xlog_identify(uint8 info)
PGDLLIMPORT int wal_compression
void XLogSetReplicationSlotMinimumLSN(XLogRecPtr lsn)
PGDLLIMPORT int CommitSiblings
void SwitchIntoArchiveRecovery(XLogRecPtr EndRecPtr, TimeLineID replayTLI)
bool GetDefaultCharSignedness(void)
PGDLLIMPORT int wal_decode_buffer_size
XLogRecPtr GetXLogInsertRecPtr(void)
void SetWalWriterSleeping(bool sleeping)
struct CheckpointStatsData CheckpointStatsData
int XLogFileOpen(XLogSegNo segno, TimeLineID tli)
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
WalLevel GetActiveWalLevelOnStandby(void)
PGDLLIMPORT int CheckPointSegments
void xlog_redo(struct XLogReaderState *record)
void InitializeWalConsistencyChecking(void)
PGDLLIMPORT bool fullPageWrites
void RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
XLogRecPtr GetLastImportantRecPtr(void)
PGDLLIMPORT XLogRecPtr ProcLastRecPtr
PGDLLIMPORT char * wal_consistency_checking_string
bool XLogNeedsFlush(XLogRecPtr record)
PGDLLIMPORT int wal_segment_size
void register_persistent_abort_backup_handler(void)
void ReachedEndOfBackup(XLogRecPtr EndRecPtr, TimeLineID tli)
void LocalProcessControlFile(bool reset)
XLogSegNo XLogGetOldestSegno(TimeLineID tli)
PGDLLIMPORT int XLogArchiveMode
XLogRecPtr GetXLogWriteRecPtr(void)
PGDLLIMPORT char * XLogArchiveCommand
PGDLLIMPORT int wal_keep_size_mb
bool XLogBackgroundFlush(void)
char * GetMockAuthenticationNonce(void)
PGDLLIMPORT bool * wal_consistency_checking
PGDLLIMPORT int max_slot_wal_keep_size_mb
bool XLogInsertAllowed(void)
void do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, BackupState *state, StringInfo tblspcmapfile)
PGDLLIMPORT bool wal_init_zero
PGDLLIMPORT int min_wal_size_mb
PGDLLIMPORT int CommitDelay
XLogRecPtr XLogRestorePoint(const char *rpName)
PGDLLIMPORT int XLOGbuffers
TimeLineID GetWALInsertionTimeLineIfSet(void)
void do_pg_backup_stop(BackupState *state, bool waitforarchive)
PGDLLIMPORT bool wal_recycle
bool CreateCheckPoint(int flags)
XLogRecPtr GetFakeLSNForUnloggedRel(void)
PGDLLIMPORT int XLogArchiveTimeout
void XLogPutNextOid(Oid nextOid)
void XLogFlush(XLogRecPtr record)
PGDLLIMPORT XLogRecPtr XactLastCommitEnd
PGDLLIMPORT int wal_level
PGDLLIMPORT bool wal_log_hints
void XLogShutdownWalRcv(void)
void issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
PGDLLIMPORT int max_wal_size_mb
void XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
PGDLLIMPORT bool track_wal_io_timing
bool XLogCheckpointNeeded(XLogSegNo new_segno)
@ WAL_SYNC_METHOD_FDATASYNC
@ WAL_SYNC_METHOD_FSYNC_WRITETHROUGH
@ WAL_SYNC_METHOD_OPEN_DSYNC