PostgreSQL Source Code  git master
xlog_internal.h File Reference
#include "access/xlogdefs.h"
#include "access/xlogreader.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "pgtime.h"
#include "storage/block.h"
#include "storage/relfilenode.h"
Include dependency graph for xlog_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  XLogPageHeaderData
 
struct  XLogLongPageHeaderData
 
struct  xl_parameter_change
 
struct  xl_restore_point
 
struct  xl_end_of_recovery
 
struct  XLogRecData
 
struct  RmgrData
 

Macros

#define XLOG_PAGE_MAGIC   0xD108 /* can be used as WAL version indicator */
 
#define SizeOfXLogShortPHD   MAXALIGN(sizeof(XLogPageHeaderData))
 
#define SizeOfXLogLongPHD   MAXALIGN(sizeof(XLogLongPageHeaderData))
 
#define XLP_FIRST_IS_CONTRECORD   0x0001
 
#define XLP_LONG_HEADER   0x0002
 
#define XLP_BKP_REMOVABLE   0x0004
 
#define XLP_ALL_FLAGS   0x0007
 
#define XLogPageHeaderSize(hdr)   (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
 
#define WalSegMinSize   1024 * 1024
 
#define WalSegMaxSize   1024 * 1024 * 1024
 
#define DEFAULT_MIN_WAL_SEGS   5
 
#define DEFAULT_MAX_WAL_SEGS   64
 
#define IsPowerOf2(x)   (x > 0 && ((x) & ((x)-1)) == 0)
 
#define IsValidWalSegSize(size)
 
#define XLogSegmentsPerXLogId(wal_segsz_bytes)   (UINT64CONST(0x100000000) / (wal_segsz_bytes))
 
#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest)   (dest) = (segno) * (wal_segsz_bytes) + (offset)
 
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)   ((xlogptr) & ((wal_segsz_bytes) - 1))
 
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)   logSegNo = (xlrp) / (wal_segsz_bytes)
 
#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes)   logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
 
#define XLogMBVarToSegs(mbvar, wal_segsz_bytes)   ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
 
#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes)   (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
 
#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes)   ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
 
#define XRecOffIsValid(xlrp)   ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
 
#define XLOGDIR   "pg_wal"
 
#define XLOG_CONTROL_FILE   "global/pg_control"
 
#define MAXFNAMELEN   64
 
#define XLOG_FNAME_LEN   24
 
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
 
#define XLogFileNameById(fname, tli, log, seg)   snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
 
#define IsXLogFileName(fname)
 
#define IsPartialXLogFileName(fname)
 
#define XLogFromFileName(fname, tli, logSegNo, wal_segsz_bytes)
 
#define XLogFilePath(path, tli, logSegNo, wal_segsz_bytes)
 
#define TLHistoryFileName(fname, tli)   snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
 
#define IsTLHistoryFileName(fname)
 
#define TLHistoryFilePath(path, tli)   snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
 
#define StatusFilePath(path, xlog, suffix)   snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
 
#define BackupHistoryFileName(fname, tli, logSegNo, startpoint, wal_segsz_bytes)
 
#define IsBackupHistoryFileName(fname)
 
#define BackupHistoryFilePath(path, tli, logSegNo, startpoint, wal_segsz_bytes)
 

Typedefs

typedef struct XLogPageHeaderData XLogPageHeaderData
 
typedef XLogPageHeaderDataXLogPageHeader
 
typedef struct XLogLongPageHeaderData XLogLongPageHeaderData
 
typedef XLogLongPageHeaderDataXLogLongPageHeader
 
typedef struct xl_parameter_change xl_parameter_change
 
typedef struct xl_restore_point xl_restore_point
 
typedef struct xl_end_of_recovery xl_end_of_recovery
 
typedef struct XLogRecData XLogRecData
 
typedef struct RmgrData RmgrData
 

Enumerations

enum  RecoveryTargetAction { RECOVERY_TARGET_ACTION_PAUSE, RECOVERY_TARGET_ACTION_PROMOTE, RECOVERY_TARGET_ACTION_SHUTDOWN }
 

Functions

pg_time_t GetLastSegSwitchData (XLogRecPtr *lastSwitchLSN)
 
XLogRecPtr RequestXLogSwitch (bool mark_unimportant)
 
void GetOldestRestartPoint (XLogRecPtr *oldrecptr, TimeLineID *oldtli)
 

Variables

const RmgrData RmgrTable []
 
bool ArchiveRecoveryRequested
 
bool InArchiveRecovery
 
bool StandbyMode
 
char * recoveryRestoreCommand
 

Macro Definition Documentation

◆ BackupHistoryFileName

#define BackupHistoryFileName (   fname,
  tli,
  logSegNo,
  startpoint,
  wal_segsz_bytes 
)
Value:
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
(uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)))
#define XLogSegmentsPerXLogId(wal_segsz_bytes)
Definition: xlog_internal.h:98
unsigned int uint32
Definition: c.h:374
#define MAXFNAMELEN
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define snprintf
Definition: port.h:193

Definition at line 212 of file xlog_internal.h.

Referenced by do_pg_stop_backup().

◆ BackupHistoryFilePath

#define BackupHistoryFilePath (   path,
  tli,
  logSegNo,
  startpoint,
  wal_segsz_bytes 
)
Value:
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
(uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)))
#define XLogSegmentsPerXLogId(wal_segsz_bytes)
Definition: xlog_internal.h:98
#define MAXPGPATH
unsigned int uint32
Definition: c.h:374
#define XLOGDIR
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define snprintf
Definition: port.h:193

Definition at line 223 of file xlog_internal.h.

Referenced by do_pg_stop_backup().

◆ DEFAULT_MAX_WAL_SEGS

#define DEFAULT_MAX_WAL_SEGS   64

Definition at line 90 of file xlog_internal.h.

Referenced by setup_config().

◆ DEFAULT_MIN_WAL_SEGS

#define DEFAULT_MIN_WAL_SEGS   5

Definition at line 89 of file xlog_internal.h.

Referenced by setup_config().

◆ IsBackupHistoryFileName

#define IsBackupHistoryFileName (   fname)
Value:
(strlen(fname) > XLOG_FNAME_LEN && \
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
#define XLOG_FNAME_LEN

Definition at line 218 of file xlog_internal.h.

Referenced by CleanupBackupHistory(), and SetWALFileNameForCleanup().

◆ IsPartialXLogFileName

#define IsPartialXLogFileName (   fname)
Value:
(strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
#define XLOG_FNAME_LEN

Definition at line 180 of file xlog_internal.h.

Referenced by CleanupPriorWALFiles(), FindEndOfXLOG(), FindStreamingStart(), KillExistingXLOG(), RemoveOldXlogFiles(), and SetWALFileNameForCleanup().

◆ IsPowerOf2

#define IsPowerOf2 (   x)    (x > 0 && ((x) & ((x)-1)) == 0)

Definition at line 93 of file xlog_internal.h.

◆ IsTLHistoryFileName

#define IsTLHistoryFileName (   fname)
Value:
(strlen(fname) == 8 + strlen(".history") && \
strspn(fname, "0123456789ABCDEF") == 8 && \
strcmp((fname) + 8, ".history") == 0)

Definition at line 201 of file xlog_internal.h.

Referenced by main(), perform_base_backup(), and pgarch_readyXlog().

◆ IsValidWalSegSize

#define IsValidWalSegSize (   size)
Value:
(IsPowerOf2(size) && \
((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
#define WalSegMinSize
Definition: xlog_internal.h:86
#define IsPowerOf2(x)
Definition: xlog_internal.h:93
#define WalSegMaxSize
Definition: xlog_internal.h:87

Definition at line 94 of file xlog_internal.h.

Referenced by AuxiliaryProcessMain(), digestControlFile(), main(), read_controlfile(), ReadControlFile(), RetrieveWalSegSize(), search_directory(), and SetWALSegSize().

◆ IsXLogFileName

◆ MAXFNAMELEN

◆ SizeOfXLogLongPHD

◆ SizeOfXLogShortPHD

◆ StatusFilePath

#define StatusFilePath (   path,
  xlog,
  suffix 
)    snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)

◆ TLHistoryFileName

◆ TLHistoryFilePath

#define TLHistoryFilePath (   path,
  tli 
)    snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)

◆ WalSegMaxSize

#define WalSegMaxSize   1024 * 1024 * 1024

Definition at line 87 of file xlog_internal.h.

◆ WalSegMinSize

#define WalSegMinSize   1024 * 1024

Definition at line 86 of file xlog_internal.h.

◆ XLByteInPrevSeg

#define XLByteInPrevSeg (   xlrp,
  logSegNo,
  wal_segsz_bytes 
)    ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))

Definition at line 137 of file xlog_internal.h.

Referenced by XLogBackgroundFlush(), and XLogWrite().

◆ XLByteInSeg

#define XLByteInSeg (   xlrp,
  logSegNo,
  wal_segsz_bytes 
)    (((xlrp) / (wal_segsz_bytes)) == (logSegNo))

◆ XLByteToPrevSeg

#define XLByteToPrevSeg (   xlrp,
  logSegNo,
  wal_segsz_bytes 
)    logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)

◆ XLByteToSeg

◆ XLOG_CONTROL_FILE

#define XLOG_CONTROL_FILE   "global/pg_control"

◆ XLOG_FNAME_LEN

#define XLOG_FNAME_LEN   24

Definition at line 157 of file xlog_internal.h.

Referenced by KillExistingArchiveStatus(), and main().

◆ XLOG_PAGE_MAGIC

#define XLOG_PAGE_MAGIC   0xD108 /* can be used as WAL version indicator */

◆ XLOGDIR

◆ XLogFileName

◆ XLogFileNameById

#define XLogFileNameById (   fname,
  tli,
  log,
  seg 
)    snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)

Definition at line 168 of file xlog_internal.h.

Referenced by SetWALFileNameForCleanup().

◆ XLogFilePath

#define XLogFilePath (   path,
  tli,
  logSegNo,
  wal_segsz_bytes 
)
Value:
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
#define XLogSegmentsPerXLogId(wal_segsz_bytes)
Definition: xlog_internal.h:98
#define MAXPGPATH
unsigned int uint32
Definition: c.h:374
#define XLOGDIR
#define snprintf
Definition: port.h:193

Definition at line 193 of file xlog_internal.h.

Referenced by InstallXLogFileSegment(), StartupXLOG(), wal_segment_open(), WalSndSegmentOpen(), WriteEmptyXLOG(), XLogFileCopy(), XLogFileInit(), XLogFileOpen(), XLogFileRead(), and XLogFileReadAnyTLI().

◆ XLogFromFileName

#define XLogFromFileName (   fname,
  tli,
  logSegNo,
  wal_segsz_bytes 
)
Value:
do { \
uint32 log; \
uint32 seg; \
sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
*logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg; \
} while (0)
#define XLogSegmentsPerXLogId(wal_segsz_bytes)
Definition: xlog_internal.h:98

Definition at line 185 of file xlog_internal.h.

Referenced by FindStreamingStart(), main(), perform_base_backup(), and UpdateLastRemovedPtr().

◆ XLogMBVarToSegs

#define XLogMBVarToSegs (   mbvar,
  wal_segsz_bytes 
)    ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))

Definition at line 125 of file xlog_internal.h.

Referenced by pg_get_replication_slots().

◆ XLogPageHeaderSize

#define XLogPageHeaderSize (   hdr)    (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)

Definition at line 82 of file xlog_internal.h.

Referenced by ReadPageInternal(), XLogReaderValidatePageHeader(), and XLogReadRecord().

◆ XLogSegmentOffset

◆ XLogSegmentsPerXLogId

#define XLogSegmentsPerXLogId (   wal_segsz_bytes)    (UINT64CONST(0x100000000) / (wal_segsz_bytes))

Definition at line 98 of file xlog_internal.h.

◆ XLogSegNoOffsetToRecPtr

#define XLogSegNoOffsetToRecPtr (   segno,
  offset,
  wal_segsz_bytes,
  dest 
)    (dest) = (segno) * (wal_segsz_bytes) + (offset)

◆ XLP_ALL_FLAGS

#define XLP_ALL_FLAGS   0x0007

Definition at line 80 of file xlog_internal.h.

Referenced by XLogReaderValidatePageHeader().

◆ XLP_BKP_REMOVABLE

#define XLP_BKP_REMOVABLE   0x0004

Definition at line 78 of file xlog_internal.h.

Referenced by AdvanceXLInsertBuffer().

◆ XLP_FIRST_IS_CONTRECORD

#define XLP_FIRST_IS_CONTRECORD   0x0001

◆ XLP_LONG_HEADER

#define XLP_LONG_HEADER   0x0002

◆ XRecOffIsValid

#define XRecOffIsValid (   xlrp)    ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)

Definition at line 141 of file xlog_internal.h.

Referenced by ReadCheckpointRecord(), StartupXLOG(), and XLogReadRecord().

Typedef Documentation

◆ RmgrData

typedef struct RmgrData RmgrData

◆ xl_end_of_recovery

◆ xl_parameter_change

◆ xl_restore_point

◆ XLogLongPageHeader

Definition at line 71 of file xlog_internal.h.

◆ XLogLongPageHeaderData

◆ XLogPageHeader

Definition at line 54 of file xlog_internal.h.

◆ XLogPageHeaderData

◆ XLogRecData

typedef struct XLogRecData XLogRecData

Enumeration Type Documentation

◆ RecoveryTargetAction

Enumerator
RECOVERY_TARGET_ACTION_PAUSE 
RECOVERY_TARGET_ACTION_PROMOTE 
RECOVERY_TARGET_ACTION_SHUTDOWN 

Definition at line 274 of file xlog_internal.h.

Function Documentation

◆ GetLastSegSwitchData()

pg_time_t GetLastSegSwitchData ( XLogRecPtr lastSwitchLSN)

Definition at line 8473 of file xlog.c.

References XLogCtlData::lastSegSwitchLSN, XLogCtlData::lastSegSwitchTime, LW_SHARED, LWLockAcquire(), and LWLockRelease().

Referenced by CheckArchiveTimeout().

8474 {
8475  pg_time_t result;
8476 
8477  /* Need WALWriteLock, but shared lock is sufficient */
8478  LWLockAcquire(WALWriteLock, LW_SHARED);
8479  result = XLogCtl->lastSegSwitchTime;
8480  *lastSwitchLSN = XLogCtl->lastSegSwitchLSN;
8481  LWLockRelease(WALWriteLock);
8482 
8483  return result;
8484 }
int64 pg_time_t
Definition: pgtime.h:23
XLogRecPtr lastSegSwitchLSN
Definition: xlog.c:617
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1812
pg_time_t lastSegSwitchTime
Definition: xlog.c:616
static XLogCtlData * XLogCtl
Definition: xlog.c:729
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1208

◆ GetOldestRestartPoint()

void GetOldestRestartPoint ( XLogRecPtr oldrecptr,
TimeLineID oldtli 
)

Definition at line 11529 of file xlog.c.

References ControlFileData::checkPointCopy, LW_SHARED, LWLockAcquire(), LWLockRelease(), CheckPoint::redo, and CheckPoint::ThisTimeLineID.

Referenced by ExecuteRecoveryCommand(), and RestoreArchivedFile().

11530 {
11531  LWLockAcquire(ControlFileLock, LW_SHARED);
11532  *oldrecptr = ControlFile->checkPointCopy.redo;
11534  LWLockRelease(ControlFileLock);
11535 }
CheckPoint checkPointCopy
Definition: pg_control.h:131
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1812
static ControlFileData * ControlFile
Definition: xlog.c:737
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1208
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
XLogRecPtr redo
Definition: pg_control.h:37

◆ RequestXLogSwitch()

XLogRecPtr RequestXLogSwitch ( bool  mark_unimportant)

Definition at line 9683 of file xlog.c.

References XLOG_MARK_UNIMPORTANT, XLOG_SWITCH, XLogBeginInsert(), XLogInsert(), and XLogSetRecordFlags().

Referenced by CheckArchiveTimeout(), do_pg_start_backup(), do_pg_stop_backup(), pg_switch_wal(), and ShutdownXLOG().

9684 {
9685  XLogRecPtr RecPtr;
9686 
9687  /* XLOG SWITCH has no data */
9688  XLogBeginInsert();
9689 
9690  if (mark_unimportant)
9692  RecPtr = XLogInsert(RM_XLOG_ID, XLOG_SWITCH);
9693 
9694  return RecPtr;
9695 }
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:404
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:422
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:239
#define XLOG_SWITCH
Definition: pg_control.h:71
void XLogBeginInsert(void)
Definition: xloginsert.c:123

Variable Documentation

◆ ArchiveRecoveryRequested

◆ InArchiveRecovery

◆ recoveryRestoreCommand

char* recoveryRestoreCommand

Definition at line 280 of file xlog.c.

Referenced by RestoreArchivedFile(), and validateRecoveryParameters().

◆ RmgrTable

const RmgrData RmgrTable[]

◆ StandbyMode

bool StandbyMode