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_overwrite_contrecord
 
struct  xl_end_of_recovery
 
struct  XLogRecData
 
struct  RmgrData
 

Macros

#define XLOG_PAGE_MAGIC   0xD110 /* 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_FIRST_IS_OVERWRITE_CONTRECORD   0x0008
 
#define XLP_ALL_FLAGS   0x000F
 
#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_overwrite_contrecord xl_overwrite_contrecord
 
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

void RmgrStartup (void)
 
void RmgrCleanup (void)
 
void RmgrNotFound (RmgrId rmid)
 
void RegisterCustomRmgr (RmgrId rmid, RmgrData *rmgr)
 
static bool RmgrIdExists (RmgrId rmid)
 
static RmgrData GetRmgr (RmgrId rmid)
 
pg_time_t GetLastSegSwitchData (XLogRecPtr *lastSwitchLSN)
 
XLogRecPtr RequestXLogSwitch (bool mark_unimportant)
 
void GetOldestRestartPoint (XLogRecPtr *oldrecptr, TimeLineID *oldtli)
 
void XLogRecGetBlockRefInfo (XLogReaderState *record, bool pretty, bool detailed_format, StringInfo buf, uint32 *fpi_len)
 

Variables

PGDLLIMPORT RmgrData RmgrTable []
 
PGDLLIMPORT bool ArchiveRecoveryRequested
 
PGDLLIMPORT bool InArchiveRecovery
 
PGDLLIMPORT bool StandbyMode
 
PGDLLIMPORT 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)))
unsigned int uint32
Definition: c.h:452
#define snprintf
Definition: port.h:225
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define MAXFNAMELEN
#define XLogSegmentsPerXLogId(wal_segsz_bytes)

Definition at line 214 of file xlog_internal.h.

◆ 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 MAXPGPATH
#define XLOGDIR

Definition at line 225 of file xlog_internal.h.

◆ DEFAULT_MAX_WAL_SEGS

#define DEFAULT_MAX_WAL_SEGS   64

Definition at line 92 of file xlog_internal.h.

◆ DEFAULT_MIN_WAL_SEGS

#define DEFAULT_MIN_WAL_SEGS   5

Definition at line 91 of file xlog_internal.h.

◆ 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 220 of file xlog_internal.h.

◆ 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)

Definition at line 182 of file xlog_internal.h.

◆ IsPowerOf2

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

Definition at line 95 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 203 of file xlog_internal.h.

◆ IsValidWalSegSize

#define IsValidWalSegSize (   size)
Value:
(IsPowerOf2(size) && \
((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
#define IsPowerOf2(x)
Definition: xlog_internal.h:95
#define WalSegMinSize
Definition: xlog_internal.h:88
#define WalSegMaxSize
Definition: xlog_internal.h:89

Definition at line 96 of file xlog_internal.h.

◆ IsXLogFileName

#define IsXLogFileName (   fname)
Value:
(strlen(fname) == XLOG_FNAME_LEN && \
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN)

Definition at line 173 of file xlog_internal.h.

◆ MAXFNAMELEN

#define MAXFNAMELEN   64

Definition at line 156 of file xlog_internal.h.

◆ SizeOfXLogLongPHD

#define SizeOfXLogLongPHD   MAXALIGN(sizeof(XLogLongPageHeaderData))

Definition at line 69 of file xlog_internal.h.

◆ SizeOfXLogShortPHD

#define SizeOfXLogShortPHD   MAXALIGN(sizeof(XLogPageHeaderData))

Definition at line 52 of file xlog_internal.h.

◆ StatusFilePath

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

Definition at line 211 of file xlog_internal.h.

◆ TLHistoryFileName

#define TLHistoryFileName (   fname,
  tli 
)     snprintf(fname, MAXFNAMELEN, "%08X.history", tli)

Definition at line 200 of file xlog_internal.h.

◆ TLHistoryFilePath

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

Definition at line 208 of file xlog_internal.h.

◆ WalSegMaxSize

#define WalSegMaxSize   1024 * 1024 * 1024

Definition at line 89 of file xlog_internal.h.

◆ WalSegMinSize

#define WalSegMinSize   1024 * 1024

Definition at line 88 of file xlog_internal.h.

◆ XLByteInPrevSeg

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

Definition at line 139 of file xlog_internal.h.

◆ XLByteInSeg

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

Definition at line 136 of file xlog_internal.h.

◆ XLByteToPrevSeg

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

Definition at line 120 of file xlog_internal.h.

◆ XLByteToSeg

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

Definition at line 117 of file xlog_internal.h.

◆ XLOG_CONTROL_FILE

#define XLOG_CONTROL_FILE   "global/pg_control"

Definition at line 150 of file xlog_internal.h.

◆ XLOG_FNAME_LEN

#define XLOG_FNAME_LEN   24

Definition at line 159 of file xlog_internal.h.

◆ XLOG_PAGE_MAGIC

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

Definition at line 34 of file xlog_internal.h.

◆ XLOGDIR

#define XLOGDIR   "pg_wal"

Definition at line 149 of file xlog_internal.h.

◆ XLogFileName

#define XLogFileName (   fname,
  tli,
  logSegNo,
  wal_segsz_bytes 
)
Value:
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))

Definition at line 165 of file xlog_internal.h.

◆ XLogFileNameById

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

Definition at line 170 of file xlog_internal.h.

◆ 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)))

Definition at line 195 of file xlog_internal.h.

◆ 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)

Definition at line 187 of file xlog_internal.h.

◆ XLogMBVarToSegs

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

Definition at line 127 of file xlog_internal.h.

◆ XLogPageHeaderSize

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

Definition at line 84 of file xlog_internal.h.

◆ XLogSegmentOffset

#define XLogSegmentOffset (   xlogptr,
  wal_segsz_bytes 
)     ((xlogptr) & ((wal_segsz_bytes) - 1))

Definition at line 106 of file xlog_internal.h.

◆ XLogSegmentsPerXLogId

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

Definition at line 100 of file xlog_internal.h.

◆ XLogSegNoOffsetToRecPtr

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

Definition at line 103 of file xlog_internal.h.

◆ XLP_ALL_FLAGS

#define XLP_ALL_FLAGS   0x000F

Definition at line 82 of file xlog_internal.h.

◆ XLP_BKP_REMOVABLE

#define XLP_BKP_REMOVABLE   0x0004

Definition at line 78 of file xlog_internal.h.

◆ XLP_FIRST_IS_CONTRECORD

#define XLP_FIRST_IS_CONTRECORD   0x0001

Definition at line 74 of file xlog_internal.h.

◆ XLP_FIRST_IS_OVERWRITE_CONTRECORD

#define XLP_FIRST_IS_OVERWRITE_CONTRECORD   0x0008

Definition at line 80 of file xlog_internal.h.

◆ XLP_LONG_HEADER

#define XLP_LONG_HEADER   0x0002

Definition at line 76 of file xlog_internal.h.

◆ XRecOffIsValid

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

Definition at line 143 of file xlog_internal.h.

Typedef Documentation

◆ RmgrData

typedef struct RmgrData RmgrData

◆ xl_end_of_recovery

◆ xl_overwrite_contrecord

◆ 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 283 of file xlog_internal.h.

284 {
RecoveryTargetAction
@ RECOVERY_TARGET_ACTION_PAUSE
@ RECOVERY_TARGET_ACTION_PROMOTE
@ RECOVERY_TARGET_ACTION_SHUTDOWN

Function Documentation

◆ GetLastSegSwitchData()

pg_time_t GetLastSegSwitchData ( XLogRecPtr lastSwitchLSN)

Definition at line 5996 of file xlog.c.

5997 {
5998  pg_time_t result;
5999 
6000  /* Need WALWriteLock, but shared lock is sufficient */
6001  LWLockAcquire(WALWriteLock, LW_SHARED);
6002  result = XLogCtl->lastSegSwitchTime;
6003  *lastSwitchLSN = XLogCtl->lastSegSwitchLSN;
6004  LWLockRelease(WALWriteLock);
6005 
6006  return result;
6007 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_SHARED
Definition: lwlock.h:105
int64 pg_time_t
Definition: pgtime.h:23
pg_time_t lastSegSwitchTime
Definition: xlog.c:473
XLogRecPtr lastSegSwitchLSN
Definition: xlog.c:474
static XLogCtlData * XLogCtl
Definition: xlog.c:558

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

Referenced by CheckArchiveTimeout().

◆ GetOldestRestartPoint()

void GetOldestRestartPoint ( XLogRecPtr oldrecptr,
TimeLineID oldtli 
)

Definition at line 8842 of file xlog.c.

8843 {
8844  LWLockAcquire(ControlFileLock, LW_SHARED);
8845  *oldrecptr = ControlFile->checkPointCopy.redo;
8847  LWLockRelease(ControlFileLock);
8848 }
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
XLogRecPtr redo
Definition: pg_control.h:37
CheckPoint checkPointCopy
Definition: pg_control.h:133
static ControlFileData * ControlFile
Definition: xlog.c:566

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

Referenced by ExecuteRecoveryCommand(), and RestoreArchivedFile().

◆ GetRmgr()

static RmgrData GetRmgr ( RmgrId  rmid)
inlinestatic

Definition at line 337 of file xlog_internal.h.

338 {
339  if (unlikely(!RmgrIdExists(rmid)))
340  RmgrNotFound(rmid);
341  return RmgrTable[rmid];
342 }
#define unlikely(x)
Definition: c.h:284
void RmgrNotFound(RmgrId rmid)
Definition: rmgr.c:82
PGDLLIMPORT RmgrData RmgrTable[]
Definition: rmgr.c:41
static bool RmgrIdExists(RmgrId rmid)

References RmgrIdExists(), RmgrNotFound(), RmgrTable, and unlikely.

Referenced by ApplyWalRecord(), check_wal_consistency_checking(), GetWALRecordInfo(), GetXLogSummaryStats(), LogicalDecodingProcessRecord(), verifyBackupPageConsistency(), and xlog_outdesc().

◆ RegisterCustomRmgr()

void RegisterCustomRmgr ( RmgrId  rmid,
RmgrData rmgr 
)

Definition at line 98 of file rmgr.c.

99 {
100  if (rmgr->rm_name == NULL || strlen(rmgr->rm_name) == 0)
101  ereport(ERROR, (errmsg("custom resource manager name is invalid"),
102  errhint("Provide a non-empty name for the custom resource manager.")));
103 
104  if (!RmgrIdIsCustom(rmid))
105  ereport(ERROR, (errmsg("custom resource manager ID %d is out of range", rmid),
106  errhint("Provide a custom resource manager ID between %d and %d.",
108 
110  ereport(ERROR,
111  (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
112  errdetail("Custom resource manager must be registered while initializing modules in shared_preload_libraries.")));
113 
114  if (RmgrTable[rmid].rm_name != NULL)
115  ereport(ERROR,
116  (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
117  errdetail("Custom resource manager \"%s\" already registered with the same ID.",
118  RmgrTable[rmid].rm_name)));
119 
120  /* check for existing rmgr with the same name */
121  for (int existing_rmid = 0; existing_rmid <= RM_MAX_ID; existing_rmid++)
122  {
123  if (!RmgrIdExists(existing_rmid))
124  continue;
125 
126  if (!pg_strcasecmp(RmgrTable[existing_rmid].rm_name, rmgr->rm_name))
127  ereport(ERROR,
128  (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
129  errdetail("Existing resource manager with ID %d has the same name.", existing_rmid)));
130  }
131 
132  /* register it */
133  RmgrTable[rmid] = *rmgr;
134  ereport(LOG,
135  (errmsg("registered custom resource manager \"%s\" with ID %d",
136  rmgr->rm_name, rmid)));
137 }
int errdetail(const char *fmt,...)
Definition: elog.c:1037
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define LOG
Definition: elog.h:25
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1617
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:41
static bool RmgrIdIsCustom(int rmid)
Definition: rmgr.h:48
#define RM_MAX_CUSTOM_ID
Definition: rmgr.h:36
#define RM_MAX_ID
Definition: rmgr.h:33
#define RM_MIN_CUSTOM_ID
Definition: rmgr.h:35
const char * rm_name

References ereport, errdetail(), errhint(), errmsg(), ERROR, LOG, pg_strcasecmp(), process_shared_preload_libraries_in_progress, RM_MAX_CUSTOM_ID, RM_MAX_ID, RM_MIN_CUSTOM_ID, RmgrData::rm_name, RmgrIdExists(), RmgrIdIsCustom(), and RmgrTable.

◆ RequestXLogSwitch()

XLogRecPtr RequestXLogSwitch ( bool  mark_unimportant)

Definition at line 7366 of file xlog.c.

7367 {
7368  XLogRecPtr RecPtr;
7369 
7370  /* XLOG SWITCH has no data */
7371  XLogBeginInsert();
7372 
7373  if (mark_unimportant)
7375  RecPtr = XLogInsert(RM_XLOG_ID, XLOG_SWITCH);
7376 
7377  return RecPtr;
7378 }
#define XLOG_SWITCH
Definition: pg_control.h:71
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:150
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:443
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:425
void XLogBeginInsert(void)
Definition: xloginsert.c:150

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

Referenced by CheckArchiveTimeout(), do_pg_backup_start(), do_pg_backup_stop(), pg_switch_wal(), and ShutdownXLOG().

◆ RmgrCleanup()

void RmgrCleanup ( void  )

Definition at line 65 of file rmgr.c.

66 {
67  for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
68  {
69  if (!RmgrIdExists(rmid))
70  continue;
71 
72  if (RmgrTable[rmid].rm_cleanup != NULL)
73  RmgrTable[rmid].rm_cleanup();
74  }
75 }
void(* rm_cleanup)(void)

References RmgrData::rm_cleanup, RM_MAX_ID, RmgrIdExists(), and RmgrTable.

Referenced by PerformWalRecovery().

◆ RmgrIdExists()

static bool RmgrIdExists ( RmgrId  rmid)
inlinestatic

Definition at line 331 of file xlog_internal.h.

332 {
333  return RmgrTable[rmid].rm_name != NULL;
334 }

References RmgrData::rm_name, and RmgrTable.

Referenced by check_wal_consistency_checking(), GetRmgr(), GetXLogSummaryStats(), RegisterCustomRmgr(), RmgrCleanup(), and RmgrStartup().

◆ RmgrNotFound()

void RmgrNotFound ( RmgrId  rmid)

Definition at line 82 of file rmgr.c.

83 {
84  ereport(ERROR, (errmsg("resource manager with ID %d not registered", rmid),
85  errhint("Include the extension module that implements this resource manager in shared_preload_libraries.")));
86 }

References ereport, errhint(), errmsg(), and ERROR.

Referenced by GetRmgr().

◆ RmgrStartup()

void RmgrStartup ( void  )

Definition at line 49 of file rmgr.c.

50 {
51  for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
52  {
53  if (!RmgrIdExists(rmid))
54  continue;
55 
56  if (RmgrTable[rmid].rm_startup != NULL)
57  RmgrTable[rmid].rm_startup();
58  }
59 }
void(* rm_startup)(void)

References RM_MAX_ID, RmgrData::rm_startup, RmgrIdExists(), and RmgrTable.

Referenced by PerformWalRecovery().

◆ XLogRecGetBlockRefInfo()

void XLogRecGetBlockRefInfo ( XLogReaderState record,
bool  pretty,
bool  detailed_format,
StringInfo  buf,
uint32 fpi_len 
)

Definition at line 209 of file xlogdesc.c.

212 {
213  int block_id;
214 
215  Assert(record != NULL);
216 
217  if (detailed_format && pretty)
218  appendStringInfoChar(buf, '\n');
219 
220  for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
221  {
222  RelFileNode rnode;
223  ForkNumber forknum;
224  BlockNumber blk;
225 
226  if (!XLogRecGetBlockTagExtended(record, block_id,
227  &rnode, &forknum, &blk, NULL))
228  continue;
229 
230  if (detailed_format)
231  {
232  /* Get block references in detailed format. */
233 
234  if (pretty)
235  appendStringInfoChar(buf, '\t');
236  else if (block_id > 0)
238 
240  "blkref #%d: rel %u/%u/%u fork %s blk %u",
241  block_id,
242  rnode.spcNode, rnode.dbNode, rnode.relNode,
243  forkNames[forknum],
244  blk);
245 
246  if (XLogRecHasBlockImage(record, block_id))
247  {
248  uint8 bimg_info = XLogRecGetBlock(record, block_id)->bimg_info;
249 
250  /* Calculate the amount of FPI data in the record. */
251  if (fpi_len)
252  *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
253 
254  if (BKPIMAGE_COMPRESSED(bimg_info))
255  {
256  const char *method;
257 
258  if ((bimg_info & BKPIMAGE_COMPRESS_PGLZ) != 0)
259  method = "pglz";
260  else if ((bimg_info & BKPIMAGE_COMPRESS_LZ4) != 0)
261  method = "lz4";
262  else if ((bimg_info & BKPIMAGE_COMPRESS_ZSTD) != 0)
263  method = "zstd";
264  else
265  method = "unknown";
266 
268  " (FPW%s); hole: offset: %u, length: %u, "
269  "compression saved: %u, method: %s",
270  XLogRecBlockImageApply(record, block_id) ?
271  "" : " for WAL verification",
272  XLogRecGetBlock(record, block_id)->hole_offset,
273  XLogRecGetBlock(record, block_id)->hole_length,
274  BLCKSZ -
275  XLogRecGetBlock(record, block_id)->hole_length -
276  XLogRecGetBlock(record, block_id)->bimg_len,
277  method);
278  }
279  else
280  {
282  " (FPW%s); hole: offset: %u, length: %u",
283  XLogRecBlockImageApply(record, block_id) ?
284  "" : " for WAL verification",
285  XLogRecGetBlock(record, block_id)->hole_offset,
286  XLogRecGetBlock(record, block_id)->hole_length);
287  }
288  }
289 
290  if (pretty)
291  appendStringInfoChar(buf, '\n');
292  }
293  else
294  {
295  /* Get block references in short format. */
296 
297  if (forknum != MAIN_FORKNUM)
298  {
300  ", blkref #%d: rel %u/%u/%u fork %s blk %u",
301  block_id,
302  rnode.spcNode, rnode.dbNode, rnode.relNode,
303  forkNames[forknum],
304  blk);
305  }
306  else
307  {
309  ", blkref #%d: rel %u/%u/%u blk %u",
310  block_id,
311  rnode.spcNode, rnode.dbNode, rnode.relNode,
312  blk);
313  }
314 
315  if (XLogRecHasBlockImage(record, block_id))
316  {
317  /* Calculate the amount of FPI data in the record. */
318  if (fpi_len)
319  *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
320 
321  if (XLogRecBlockImageApply(record, block_id))
322  appendStringInfo(buf, " FPW");
323  else
324  appendStringInfo(buf, " FPW for WAL verification");
325  }
326  }
327  }
328 
329  if (!detailed_format && pretty)
330  appendStringInfoChar(buf, '\n');
331 }
uint32 BlockNumber
Definition: block.h:31
unsigned char uint8
Definition: c.h:450
Assert(fmt[strlen(fmt) - 1] !='\n')
static char * buf
Definition: pg_test_fsync.c:67
const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:41
@ MAIN_FORKNUM
Definition: relpath.h:43
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
Definition: xlogreader.c:1953
#define XLogRecBlockImageApply(decoder, block_id)
Definition: xlogreader.h:423
#define XLogRecGetBlock(decoder, i)
Definition: xlogreader.h:417
#define XLogRecMaxBlockId(decoder)
Definition: xlogreader.h:416
#define XLogRecHasBlockImage(decoder, block_id)
Definition: xlogreader.h:421
#define BKPIMAGE_COMPRESS_ZSTD
Definition: xlogrecord.h:151
#define BKPIMAGE_COMPRESS_LZ4
Definition: xlogrecord.h:150
#define BKPIMAGE_COMPRESSED(info)
Definition: xlogrecord.h:153
#define BKPIMAGE_COMPRESS_PGLZ
Definition: xlogrecord.h:149

References appendStringInfo(), appendStringInfoChar(), Assert(), BKPIMAGE_COMPRESS_LZ4, BKPIMAGE_COMPRESS_PGLZ, BKPIMAGE_COMPRESS_ZSTD, BKPIMAGE_COMPRESSED, buf, RelFileNode::dbNode, forkNames, MAIN_FORKNUM, RelFileNode::relNode, RelFileNode::spcNode, XLogRecBlockImageApply, XLogRecGetBlock, XLogRecGetBlockTagExtended(), XLogRecHasBlockImage, and XLogRecMaxBlockId.

Referenced by GetWALRecordInfo(), and XLogDumpDisplayRecord().

Variable Documentation

◆ ArchiveRecoveryRequested

◆ InArchiveRecovery

◆ recoveryRestoreCommand

PGDLLIMPORT char* recoveryRestoreCommand
extern

Definition at line 78 of file xlogrecovery.c.

◆ RmgrTable

PGDLLIMPORT RmgrData RmgrTable[]
extern

Definition at line 41 of file rmgr.c.

Referenced by GetRmgr(), RegisterCustomRmgr(), RmgrCleanup(), RmgrIdExists(), and RmgrStartup().

◆ StandbyMode

PGDLLIMPORT bool StandbyMode
extern

Definition at line 144 of file xlogrecovery.c.