PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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/relfilelocator.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   0xD118 /* 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
 

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

static void XLogFileName (char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
 
static void XLogFileNameById (char *fname, TimeLineID tli, uint32 log, uint32 seg)
 
static bool IsXLogFileName (const char *fname)
 
static bool IsPartialXLogFileName (const char *fname)
 
static void XLogFromFileName (const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
 
static void XLogFilePath (char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
 
static void TLHistoryFileName (char *fname, TimeLineID tli)
 
static bool IsTLHistoryFileName (const char *fname)
 
static void TLHistoryFilePath (char *path, TimeLineID tli)
 
static void StatusFilePath (char *path, const char *xlog, const char *suffix)
 
static void BackupHistoryFileName (char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
 
static bool IsBackupHistoryFileName (const char *fname)
 
static void BackupHistoryFilePath (char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
 
void RmgrStartup (void)
 
void RmgrCleanup (void)
 
void RmgrNotFound (RmgrId rmid)
 
void RegisterCustomRmgr (RmgrId rmid, const 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

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

◆ IsPowerOf2

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

Definition at line 95 of file xlog_internal.h.

◆ IsValidWalSegSize

#define IsValidWalSegSize (   size)
Value:
static pg_noinline void Size size
Definition: slab.c:607
#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.

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

◆ 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   0xD118 /* 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.

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

323{
RecoveryTargetAction
@ RECOVERY_TARGET_ACTION_PAUSE
@ RECOVERY_TARGET_ACTION_PROMOTE
@ RECOVERY_TARGET_ACTION_SHUTDOWN

Function Documentation

◆ BackupHistoryFileName()

static void BackupHistoryFileName ( char *  fname,
TimeLineID  tli,
XLogSegNo  logSegNo,
XLogRecPtr  startpoint,
int  wal_segsz_bytes 
)
inlinestatic

Definition at line 244 of file xlog_internal.h.

245{
246 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
247 (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
248 (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
249 (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
250}
uint32_t uint32
Definition: c.h:485
#define snprintf
Definition: port.h:238
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define MAXFNAMELEN
#define XLogSegmentsPerXLogId(wal_segsz_bytes)

References MAXFNAMELEN, snprintf, XLogSegmentOffset, and XLogSegmentsPerXLogId.

Referenced by do_pg_backup_stop().

◆ BackupHistoryFilePath()

static void BackupHistoryFilePath ( char *  path,
TimeLineID  tli,
XLogSegNo  logSegNo,
XLogRecPtr  startpoint,
int  wal_segsz_bytes 
)
inlinestatic

Definition at line 261 of file xlog_internal.h.

262{
263 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
264 (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
265 (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
266 (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
267}
#define MAXPGPATH
#define XLOGDIR

References MAXPGPATH, snprintf, XLOGDIR, XLogSegmentOffset, and XLogSegmentsPerXLogId.

Referenced by do_pg_backup_stop().

◆ GetLastSegSwitchData()

pg_time_t GetLastSegSwitchData ( XLogRecPtr lastSwitchLSN)

Definition at line 6585 of file xlog.c.

6586{
6587 pg_time_t result;
6588
6589 /* Need WALWriteLock, but shared lock is sufficient */
6590 LWLockAcquire(WALWriteLock, LW_SHARED);
6591 result = XLogCtl->lastSegSwitchTime;
6592 *lastSwitchLSN = XLogCtl->lastSegSwitchLSN;
6593 LWLockRelease(WALWriteLock);
6594
6595 return result;
6596}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_SHARED
Definition: lwlock.h:115
int64 pg_time_t
Definition: pgtime.h:23
pg_time_t lastSegSwitchTime
Definition: xlog.c:467
XLogRecPtr lastSegSwitchLSN
Definition: xlog.c:468
static XLogCtlData * XLogCtl
Definition: xlog.c:566

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

Referenced by CheckArchiveTimeout().

◆ GetOldestRestartPoint()

void GetOldestRestartPoint ( XLogRecPtr oldrecptr,
TimeLineID oldtli 
)

Definition at line 9463 of file xlog.c.

9464{
9465 LWLockAcquire(ControlFileLock, LW_SHARED);
9466 *oldrecptr = ControlFile->checkPointCopy.redo;
9468 LWLockRelease(ControlFileLock);
9469}
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
XLogRecPtr redo
Definition: pg_control.h:37
CheckPoint checkPointCopy
Definition: pg_control.h:135
static ControlFileData * ControlFile
Definition: xlog.c:574

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

377{
378 if (unlikely(!RmgrIdExists(rmid)))
379 RmgrNotFound(rmid);
380 return RmgrTable[rmid];
381}
#define unlikely(x)
Definition: c.h:330
void RmgrNotFound(RmgrId rmid)
Definition: rmgr.c:91
PGDLLIMPORT RmgrData RmgrTable[]
Definition: rmgr.c:50
static bool RmgrIdExists(RmgrId rmid)

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

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

◆ IsBackupHistoryFileName()

static bool IsBackupHistoryFileName ( const char *  fname)
inlinestatic

Definition at line 253 of file xlog_internal.h.

254{
255 return (strlen(fname) > XLOG_FNAME_LEN &&
256 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
257 strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
258}
#define XLOG_FNAME_LEN

References XLOG_FNAME_LEN.

Referenced by CleanupBackupHistory(), CleanupPriorWALFiles(), and SetWALFileNameForCleanup().

◆ IsPartialXLogFileName()

static bool IsPartialXLogFileName ( const char *  fname)
inlinestatic

Definition at line 192 of file xlog_internal.h.

193{
194 return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
195 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
196 strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
197}

References XLOG_FNAME_LEN.

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

◆ IsTLHistoryFileName()

static bool IsTLHistoryFileName ( const char *  fname)
inlinestatic

Definition at line 224 of file xlog_internal.h.

225{
226 return (strlen(fname) == 8 + strlen(".history") &&
227 strspn(fname, "0123456789ABCDEF") == 8 &&
228 strcmp(fname + 8, ".history") == 0);
229}

Referenced by perform_base_backup(), ready_file_comparator(), and XLogArchiveNotify().

◆ IsXLogFileName()

static bool IsXLogFileName ( const char *  fname)
inlinestatic

◆ RegisterCustomRmgr()

void RegisterCustomRmgr ( RmgrId  rmid,
const RmgrData rmgr 
)

Definition at line 107 of file rmgr.c.

108{
109 if (rmgr->rm_name == NULL || strlen(rmgr->rm_name) == 0)
110 ereport(ERROR, (errmsg("custom resource manager name is invalid"),
111 errhint("Provide a non-empty name for the custom resource manager.")));
112
113 if (!RmgrIdIsCustom(rmid))
114 ereport(ERROR, (errmsg("custom resource manager ID %d is out of range", rmid),
115 errhint("Provide a custom resource manager ID between %d and %d.",
117
120 (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
121 errdetail("Custom resource manager must be registered while initializing modules in \"shared_preload_libraries\".")));
122
123 if (RmgrTable[rmid].rm_name != NULL)
125 (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
126 errdetail("Custom resource manager \"%s\" already registered with the same ID.",
127 RmgrTable[rmid].rm_name)));
128
129 /* check for existing rmgr with the same name */
130 for (int existing_rmid = 0; existing_rmid <= RM_MAX_ID; existing_rmid++)
131 {
132 if (!RmgrIdExists(existing_rmid))
133 continue;
134
135 if (!pg_strcasecmp(RmgrTable[existing_rmid].rm_name, rmgr->rm_name))
137 (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
138 errdetail("Existing resource manager with ID %d has the same name.", existing_rmid)));
139 }
140
141 /* register it */
142 RmgrTable[rmid] = *rmgr;
143 ereport(LOG,
144 (errmsg("registered custom resource manager \"%s\" with ID %d",
145 rmgr->rm_name, rmid)));
146}
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define LOG
Definition: elog.h:31
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1834
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:50
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.

Referenced by _PG_init().

◆ RequestXLogSwitch()

XLogRecPtr RequestXLogSwitch ( bool  mark_unimportant)

Definition at line 8060 of file xlog.c.

8061{
8062 XLogRecPtr RecPtr;
8063
8064 /* XLOG SWITCH has no data */
8066
8067 if (mark_unimportant)
8069 RecPtr = XLogInsert(RM_XLOG_ID, XLOG_SWITCH);
8070
8071 return RecPtr;
8072}
#define XLOG_SWITCH
Definition: pg_control.h:72
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:155
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:456
void XLogBeginInsert(void)
Definition: xloginsert.c:149

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 74 of file rmgr.c.

75{
76 for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
77 {
78 if (!RmgrIdExists(rmid))
79 continue;
80
81 if (RmgrTable[rmid].rm_cleanup != NULL)
82 RmgrTable[rmid].rm_cleanup();
83 }
84}
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 370 of file xlog_internal.h.

371{
372 return RmgrTable[rmid].rm_name != NULL;
373}

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 91 of file rmgr.c.

92{
93 ereport(ERROR, (errmsg("resource manager with ID %d not registered", rmid),
94 errhint("Include the extension module that implements this resource manager in \"shared_preload_libraries\".")));
95}

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

Referenced by GetRmgr().

◆ RmgrStartup()

void RmgrStartup ( void  )

Definition at line 58 of file rmgr.c.

59{
60 for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
61 {
62 if (!RmgrIdExists(rmid))
63 continue;
64
65 if (RmgrTable[rmid].rm_startup != NULL)
66 RmgrTable[rmid].rm_startup();
67 }
68}
void(* rm_startup)(void)

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

Referenced by PerformWalRecovery().

◆ StatusFilePath()

static void StatusFilePath ( char *  path,
const char *  xlog,
const char *  suffix 
)
inlinestatic

◆ TLHistoryFileName()

static void TLHistoryFileName ( char *  fname,
TimeLineID  tli 
)
inlinestatic

◆ TLHistoryFilePath()

static void TLHistoryFilePath ( char *  path,
TimeLineID  tli 
)
inlinestatic

◆ XLogFileName()

◆ XLogFileNameById()

static void XLogFileNameById ( char *  fname,
TimeLineID  tli,
uint32  log,
uint32  seg 
)
inlinestatic

Definition at line 174 of file xlog_internal.h.

175{
176 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
177}

References MAXFNAMELEN, and snprintf.

Referenced by SetWALFileNameForCleanup().

◆ XLogFilePath()

static void XLogFilePath ( char *  path,
TimeLineID  tli,
XLogSegNo  logSegNo,
int  wal_segsz_bytes 
)
inlinestatic

◆ XLogFromFileName()

static void XLogFromFileName ( const char *  fname,
TimeLineID tli,
XLogSegNo logSegNo,
int  wal_segsz_bytes 
)
inlinestatic

Definition at line 200 of file xlog_internal.h.

201{
202 uint32 log;
203 uint32 seg;
204
205 sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
206 *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
207}
uint64_t uint64
Definition: c.h:486

References XLogSegmentsPerXLogId.

Referenced by FindEndOfXLOG(), FindStreamingStart(), main(), perform_base_backup(), pg_split_walfile_name(), UpdateLastRemovedPtr(), and XLogGetOldestSegno().

◆ XLogRecGetBlockRefInfo()

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

Definition at line 231 of file xlogdesc.c.

234{
235 int block_id;
236
237 Assert(record != NULL);
238
239 if (detailed_format && pretty)
241
242 for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
243 {
244 RelFileLocator rlocator;
245 ForkNumber forknum;
246 BlockNumber blk;
247
248 if (!XLogRecGetBlockTagExtended(record, block_id,
249 &rlocator, &forknum, &blk, NULL))
250 continue;
251
252 if (detailed_format)
253 {
254 /* Get block references in detailed format. */
255
256 if (pretty)
258 else if (block_id > 0)
260
262 "blkref #%d: rel %u/%u/%u fork %s blk %u",
263 block_id,
264 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
265 forkNames[forknum],
266 blk);
267
268 if (XLogRecHasBlockImage(record, block_id))
269 {
270 uint8 bimg_info = XLogRecGetBlock(record, block_id)->bimg_info;
271
272 /* Calculate the amount of FPI data in the record. */
273 if (fpi_len)
274 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
275
276 if (BKPIMAGE_COMPRESSED(bimg_info))
277 {
278 const char *method;
279
280 if ((bimg_info & BKPIMAGE_COMPRESS_PGLZ) != 0)
281 method = "pglz";
282 else if ((bimg_info & BKPIMAGE_COMPRESS_LZ4) != 0)
283 method = "lz4";
284 else if ((bimg_info & BKPIMAGE_COMPRESS_ZSTD) != 0)
285 method = "zstd";
286 else
287 method = "unknown";
288
290 " (FPW%s); hole: offset: %u, length: %u, "
291 "compression saved: %u, method: %s",
292 XLogRecBlockImageApply(record, block_id) ?
293 "" : " for WAL verification",
294 XLogRecGetBlock(record, block_id)->hole_offset,
295 XLogRecGetBlock(record, block_id)->hole_length,
296 BLCKSZ -
297 XLogRecGetBlock(record, block_id)->hole_length -
298 XLogRecGetBlock(record, block_id)->bimg_len,
299 method);
300 }
301 else
302 {
304 " (FPW%s); hole: offset: %u, length: %u",
305 XLogRecBlockImageApply(record, block_id) ?
306 "" : " for WAL verification",
307 XLogRecGetBlock(record, block_id)->hole_offset,
308 XLogRecGetBlock(record, block_id)->hole_length);
309 }
310 }
311
312 if (pretty)
314 }
315 else
316 {
317 /* Get block references in short format. */
318
319 if (forknum != MAIN_FORKNUM)
320 {
322 ", blkref #%d: rel %u/%u/%u fork %s blk %u",
323 block_id,
324 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
325 forkNames[forknum],
326 blk);
327 }
328 else
329 {
331 ", blkref #%d: rel %u/%u/%u blk %u",
332 block_id,
333 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
334 blk);
335 }
336
337 if (XLogRecHasBlockImage(record, block_id))
338 {
339 /* Calculate the amount of FPI data in the record. */
340 if (fpi_len)
341 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
342
343 if (XLogRecBlockImageApply(record, block_id))
345 else
346 appendStringInfoString(buf, " FPW for WAL verification");
347 }
348 }
349 }
350
351 if (!detailed_format && pretty)
353}
uint32 BlockNumber
Definition: block.h:31
uint8_t uint8
Definition: c.h:483
#define Assert(condition)
Definition: c.h:812
static char * buf
Definition: pg_test_fsync.c:72
const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:56
@ MAIN_FORKNUM
Definition: relpath.h:58
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:94
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:191
RelFileNumber relNumber
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
Definition: xlogreader.c:1997
#define XLogRecBlockImageApply(decoder, block_id)
Definition: xlogreader.h:425
#define XLogRecGetBlock(decoder, i)
Definition: xlogreader.h:419
#define XLogRecMaxBlockId(decoder)
Definition: xlogreader.h:418
#define XLogRecHasBlockImage(decoder, block_id)
Definition: xlogreader.h:423
#define BKPIMAGE_COMPRESS_ZSTD
Definition: xlogrecord.h:162
#define BKPIMAGE_COMPRESS_LZ4
Definition: xlogrecord.h:161
#define BKPIMAGE_COMPRESSED(info)
Definition: xlogrecord.h:164
#define BKPIMAGE_COMPRESS_PGLZ
Definition: xlogrecord.h:160

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, BKPIMAGE_COMPRESS_LZ4, BKPIMAGE_COMPRESS_PGLZ, BKPIMAGE_COMPRESS_ZSTD, BKPIMAGE_COMPRESSED, buf, RelFileLocator::dbOid, forkNames, MAIN_FORKNUM, RelFileLocator::relNumber, RelFileLocator::spcOid, XLogRecBlockImageApply, XLogRecGetBlock, XLogRecGetBlockTagExtended(), XLogRecHasBlockImage, and XLogRecMaxBlockId.

Referenced by GetWALRecordInfo(), and XLogDumpDisplayRecord().

Variable Documentation

◆ ArchiveRecoveryRequested

◆ InArchiveRecovery

◆ recoveryRestoreCommand

PGDLLIMPORT char* recoveryRestoreCommand
extern

Definition at line 82 of file xlogrecovery.c.

◆ RmgrTable

PGDLLIMPORT RmgrData RmgrTable[]
extern

Definition at line 50 of file rmgr.c.

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

◆ StandbyMode

PGDLLIMPORT bool StandbyMode
extern

Definition at line 147 of file xlogrecovery.c.