PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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/checksum.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_checksum_state
 
struct  xl_overwrite_contrecord
 
struct  xl_end_of_recovery
 
struct  xl_checkpoint_redo
 
struct  XLogRecData
 
struct  RmgrData
 

Macros

#define XLOG_PAGE_MAGIC   0xD11F /* 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_FIRST_IS_OVERWRITE_CONTRECORD   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
 

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_checksum_state xl_checksum_state
 
typedef struct xl_overwrite_contrecord xl_overwrite_contrecord
 
typedef struct xl_end_of_recovery xl_end_of_recovery
 
typedef struct xl_checkpoint_redo xl_checkpoint_redo
 
typedef struct XLogRecData XLogRecData
 
typedef struct RmgrData RmgrData
 

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 charrecoveryRestoreCommand
 

Macro Definition Documentation

◆ DEFAULT_MAX_WAL_SEGS

#define DEFAULT_MAX_WAL_SEGS   64

Definition at line 91 of file xlog_internal.h.

◆ DEFAULT_MIN_WAL_SEGS

#define DEFAULT_MIN_WAL_SEGS   5

Definition at line 90 of file xlog_internal.h.

◆ IsPowerOf2

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

Definition at line 94 of file xlog_internal.h.

◆ IsValidWalSegSize

#define IsValidWalSegSize (   size)
Value:
(IsPowerOf2(size) && \
((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
#define IsPowerOf2(x)
#define WalSegMinSize
#define WalSegMaxSize

Definition at line 95 of file xlog_internal.h.

165{
166 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
169}
170
171static inline void
172XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
173{
174 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
175}
176
177static inline bool
178IsXLogFileName(const char *fname)
179{
180 return (strlen(fname) == XLOG_FNAME_LEN && \
181 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
182}
183
184/*
185 * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
186 * archive recovery, when we want to archive a WAL segment but it might not
187 * be complete yet.
188 */
189static inline bool
190IsPartialXLogFileName(const char *fname)
191{
192 return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
193 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
194 strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
195}
196
197static inline void
198XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
199{
200 uint32 log;
201 uint32 seg;
202
203 sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
205}
206
207static inline void
209{
210 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
213}
214
215static inline void
216TLHistoryFileName(char *fname, TimeLineID tli)
217{
218 snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
219}
220
221static inline bool
222IsTLHistoryFileName(const char *fname)
223{
224 return (strlen(fname) == 8 + strlen(".history") &&
225 strspn(fname, "0123456789ABCDEF") == 8 &&
226 strcmp(fname + 8, ".history") == 0);
227}
228
229static inline void
230TLHistoryFilePath(char *path, TimeLineID tli)
231{
232 snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
233}
234
235static inline void
236StatusFilePath(char *path, const char *xlog, const char *suffix)
237{
238 snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
239}
240
241static inline void
243{
244 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
247 (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
248}
249
250static inline bool
251IsBackupHistoryFileName(const char *fname)
252{
253 return (strlen(fname) > XLOG_FNAME_LEN &&
254 strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
255 strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
256}
257
258static inline void
260{
261 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
264 (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
265}
266
267/*
268 * Information logged when we detect a change in one of the parameters
269 * important for Hot Standby.
270 */
271typedef struct xl_parameter_change
272{
273 int MaxConnections;
275 int max_wal_senders;
278 int wal_level;
279 bool wal_log_hints;
282
283/* logs restore point */
284typedef struct xl_restore_point
285{
287 char rp_name[MAXFNAMELEN];
289
290/* Information logged when data checksum level is changed */
291typedef struct xl_checksum_state
292{
295
296/* Overwrite of prior contrecord */
297typedef struct xl_overwrite_contrecord
298{
302
303/* End of recovery mark, when we don't do an END_OF_RECOVERY checkpoint */
304typedef struct xl_end_of_recovery
305{
307 TimeLineID ThisTimeLineID; /* new TLI */
308 TimeLineID PrevTimeLineID; /* previous TLI we forked off from */
309 int wal_level;
311
312/* checkpoint redo */
313typedef struct xl_checkpoint_redo
314{
315 int wal_level;
318
319/*
320 * The functions in xloginsert.c construct a chain of XLogRecData structs
321 * to represent the final WAL record.
322 */
323typedef struct XLogRecData
324{
325 struct XLogRecData *next; /* next struct in chain, or NULL */
326 const void *data; /* start of rmgr data to include */
327 uint32 len; /* length of rmgr data to include */
329
331struct XLogRecordBuffer;
332
333/*
334 * Method table for resource managers.
335 *
336 * This struct must be kept in sync with the PG_RMGR definition in
337 * rmgr.c.
338 *
339 * rm_identify must return a name for the record based on xl_info (without
340 * reference to the rmid). For example, XLOG_BTREE_VACUUM would be named
341 * "VACUUM". rm_desc can then be called to obtain additional detail for the
342 * record, if available (e.g. the last block).
343 *
344 * rm_mask takes as input a page modified by the resource manager and masks
345 * out bits that shouldn't be flagged by wal_consistency_checking.
346 *
347 * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). If rm_name is
348 * NULL, the corresponding RmgrTable entry is considered invalid.
349 */
350typedef struct RmgrData
351{
352 const char *rm_name;
353 void (*rm_redo) (XLogReaderState *record);
355 const char *(*rm_identify) (uint8 info);
356 void (*rm_startup) (void);
357 void (*rm_cleanup) (void);
358 void (*rm_mask) (char *pagedata, BlockNumber blkno);
359 void (*rm_decode) (struct LogicalDecodingContext *ctx,
360 struct XLogRecordBuffer *buf);
361} RmgrData;
362
364extern void RmgrStartup(void);
365extern void RmgrCleanup(void);
366extern void RmgrNotFound(RmgrId rmid);
367extern void RegisterCustomRmgr(RmgrId rmid, const RmgrData *rmgr);
368
369#ifndef FRONTEND
370static inline bool
372{
373 return RmgrTable[rmid].rm_name != NULL;
374}
375
376static inline RmgrData
377GetRmgr(RmgrId rmid)
378{
379 if (unlikely(!RmgrIdExists(rmid)))
380 RmgrNotFound(rmid);
381 return RmgrTable[rmid];
382}
383#endif
384
385/*
386 * Exported to support xlog switching from checkpointer
387 */
390
392
395 uint32 *fpi_len);
396
397/*
398 * Exported for the functions in timeline.c and xlogarchive.c. Only valid
399 * in the startup process.
400 */
403extern PGDLLIMPORT bool StandbyMode;
405
406#endif /* XLOG_INTERNAL_H */
uint32 BlockNumber
Definition block.h:31
#define PGDLLIMPORT
Definition c.h:1421
uint8_t uint8
Definition c.h:622
uint64_t uint64
Definition c.h:625
#define unlikely(x)
Definition c.h:438
uint32_t uint32
Definition c.h:624
ChecksumStateType
Definition checksum.h:27
int64 TimestampTz
Definition timestamp.h:39
#define MAXPGPATH
static char buf[DEFAULT_XLOG_SEG_SIZE]
int64 pg_time_t
Definition pgtime.h:23
#define snprintf
Definition port.h:260
static int fb(int x)
uint8 RmgrId
Definition rmgr.h:11
void(* rm_mask)(char *pagedata, BlockNumber blkno)
void(* rm_redo)(XLogReaderState *record)
void(* rm_cleanup)(void)
void(* rm_decode)(struct LogicalDecodingContext *ctx, struct XLogRecordBuffer *buf)
const char * rm_name
void(* rm_startup)(void)
void(* rm_desc)(StringInfo buf, XLogReaderState *record)
const void * data
struct XLogRecData * next
XLogReaderState * record
Definition decode.h:21
ChecksumStateType new_checksum_state
TimeLineID PrevTimeLineID
TimeLineID ThisTimeLineID
char rp_name[MAXFNAMELEN]
TimestampTz rp_time
static RmgrData GetRmgr(RmgrId rmid)
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition xlog.c:8607
PGDLLIMPORT bool ArchiveRecoveryRequested
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
static bool IsXLogFileName(const char *fname)
void RmgrStartup(void)
Definition rmgr.c:58
static void XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
void XLogRecGetBlockRefInfo(XLogReaderState *record, bool pretty, bool detailed_format, StringInfo buf, uint32 *fpi_len)
Definition xlogdesc.c:303
static bool IsTLHistoryFileName(const char *fname)
#define MAXFNAMELEN
pg_time_t GetLastSegSwitchData(XLogRecPtr *lastSwitchLSN)
Definition xlog.c:7081
#define XLOGDIR
void RmgrCleanup(void)
Definition rmgr.c:74
#define XLOG_FNAME_LEN
static bool IsBackupHistoryFileName(const char *fname)
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)
void RmgrNotFound(RmgrId rmid)
Definition rmgr.c:91
static void XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
PGDLLIMPORT bool StandbyMode
PGDLLIMPORT bool InArchiveRecovery
static void XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
Definition xlog.c:10152
static void TLHistoryFilePath(char *path, TimeLineID tli)
static void BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
PGDLLIMPORT RmgrData RmgrTable[]
Definition rmgr.c:50
static bool RmgrIdExists(RmgrId rmid)
static void TLHistoryFileName(char *fname, TimeLineID tli)
#define XLogSegmentsPerXLogId(wal_segsz_bytes)
void RegisterCustomRmgr(RmgrId rmid, const RmgrData *rmgr)
Definition rmgr.c:107
PGDLLIMPORT char * recoveryRestoreCommand
static bool IsPartialXLogFileName(const char *fname)
uint64 XLogRecPtr
Definition xlogdefs.h:21
uint32 TimeLineID
Definition xlogdefs.h:63
uint64 XLogSegNo
Definition xlogdefs.h:52

◆ MAXFNAMELEN

#define MAXFNAMELEN   64

Definition at line 155 of file xlog_internal.h.

◆ SizeOfXLogLongPHD

#define SizeOfXLogLongPHD   MAXALIGN(sizeof(XLogLongPageHeaderData))

Definition at line 70 of file xlog_internal.h.

◆ SizeOfXLogShortPHD

#define SizeOfXLogShortPHD   MAXALIGN(sizeof(XLogPageHeaderData))

Definition at line 53 of file xlog_internal.h.

◆ WalSegMaxSize

#define WalSegMaxSize   1024 * 1024 * 1024

Definition at line 88 of file xlog_internal.h.

◆ WalSegMinSize

#define WalSegMinSize   1024 * 1024

Definition at line 87 of file xlog_internal.h.

◆ XLByteInPrevSeg

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

Definition at line 138 of file xlog_internal.h.

◆ XLByteInSeg

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

Definition at line 135 of file xlog_internal.h.

◆ XLByteToPrevSeg

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

Definition at line 119 of file xlog_internal.h.

◆ XLByteToSeg

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

Definition at line 116 of file xlog_internal.h.

◆ XLOG_CONTROL_FILE

#define XLOG_CONTROL_FILE   "global/pg_control"

Definition at line 149 of file xlog_internal.h.

◆ XLOG_FNAME_LEN

#define XLOG_FNAME_LEN   24

Definition at line 158 of file xlog_internal.h.

◆ XLOG_PAGE_MAGIC

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

Definition at line 35 of file xlog_internal.h.

◆ XLOGDIR

#define XLOGDIR   "pg_wal"

Definition at line 148 of file xlog_internal.h.

◆ XLogMBVarToSegs

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

Definition at line 126 of file xlog_internal.h.

◆ XLogPageHeaderSize

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

Definition at line 83 of file xlog_internal.h.

#define SizeOfXLogShortPHD

◆ XLogSegmentOffset

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

Definition at line 105 of file xlog_internal.h.

◆ XLogSegmentsPerXLogId

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

Definition at line 99 of file xlog_internal.h.

◆ XLogSegNoOffsetToRecPtr

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

Definition at line 102 of file xlog_internal.h.

◆ XLP_ALL_FLAGS

#define XLP_ALL_FLAGS   0x0007

Definition at line 81 of file xlog_internal.h.

◆ XLP_FIRST_IS_CONTRECORD

#define XLP_FIRST_IS_CONTRECORD   0x0001

Definition at line 75 of file xlog_internal.h.

◆ XLP_FIRST_IS_OVERWRITE_CONTRECORD

#define XLP_FIRST_IS_OVERWRITE_CONTRECORD   0x0004

Definition at line 79 of file xlog_internal.h.

◆ XLP_LONG_HEADER

#define XLP_LONG_HEADER   0x0002

Definition at line 77 of file xlog_internal.h.

◆ XRecOffIsValid

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

Definition at line 142 of file xlog_internal.h.

Typedef Documentation

◆ RmgrData

◆ xl_checkpoint_redo

◆ xl_checksum_state

◆ xl_end_of_recovery

◆ xl_overwrite_contrecord

◆ xl_parameter_change

◆ xl_restore_point

◆ XLogLongPageHeader

◆ XLogLongPageHeaderData

◆ XLogPageHeader

◆ XLogPageHeaderData

◆ XLogRecData

Function Documentation

◆ BackupHistoryFileName()

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

Definition at line 243 of file xlog_internal.h.

244{
245 snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
248 (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
249}

References fb(), 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 260 of file xlog_internal.h.

261{
262 snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
265 (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
266}

References fb(), MAXPGPATH, snprintf, XLOGDIR, XLogSegmentOffset, and XLogSegmentsPerXLogId.

Referenced by do_pg_backup_stop().

◆ GetLastSegSwitchData()

pg_time_t GetLastSegSwitchData ( XLogRecPtr lastSwitchLSN)
extern

Definition at line 7081 of file xlog.c.

7082{
7084
7085 /* Need WALWriteLock, but shared lock is sufficient */
7090
7091 return result;
7092}
uint32 result
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_SHARED
Definition lwlock.h:105
pg_time_t lastSegSwitchTime
Definition xlog.c:473
XLogRecPtr lastSegSwitchLSN
Definition xlog.c:474
static XLogCtlData * XLogCtl
Definition xlog.c:575

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

Referenced by CheckArchiveTimeout().

◆ GetOldestRestartPoint()

void GetOldestRestartPoint ( XLogRecPtr oldrecptr,
TimeLineID oldtli 
)
extern

◆ GetRmgr()

◆ IsBackupHistoryFileName()

static bool IsBackupHistoryFileName ( const char fname)
inlinestatic

Definition at line 252 of file xlog_internal.h.

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

References fb(), and XLOG_FNAME_LEN.

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

◆ IsPartialXLogFileName()

static bool IsPartialXLogFileName ( const char fname)
inlinestatic

Definition at line 191 of file xlog_internal.h.

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

References fb(), and XLOG_FNAME_LEN.

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

◆ IsTLHistoryFileName()

static bool IsTLHistoryFileName ( const char fname)
inlinestatic

Definition at line 223 of file xlog_internal.h.

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

References fb().

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

◆ IsXLogFileName()

◆ RegisterCustomRmgr()

void RegisterCustomRmgr ( RmgrId  rmid,
const RmgrData rmgr 
)
extern

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 */
131 {
133 continue;
134
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}
#define LOG
Definition elog.h:32
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
bool process_shared_preload_libraries_in_progress
Definition miscinit.c:1788
static char * errmsg
int pg_strcasecmp(const char *s1, const char *s2)
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

References ereport, errdetail(), errhint(), errmsg, ERROR, fb(), 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)
extern

Definition at line 8607 of file xlog.c.

8608{
8610
8611 /* XLOG SWITCH has no data */
8613
8614 if (mark_unimportant)
8617
8618 return RecPtr;
8619}
#define XLOG_SWITCH
Definition pg_control.h:76
#define XLOG_MARK_UNIMPORTANT
Definition xlog.h:167
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:482
void XLogSetRecordFlags(uint8 flags)
Definition xloginsert.c:464
void XLogBeginInsert(void)
Definition xloginsert.c:153

References fb(), 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  )
extern

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}

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

Referenced by PerformWalRecovery().

◆ RmgrIdExists()

static bool RmgrIdExists ( RmgrId  rmid)
inlinestatic

◆ RmgrNotFound()

void RmgrNotFound ( RmgrId  rmid)
extern

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

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}

References fb(), 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 173 of file xlog_internal.h.

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

References fb(), MAXFNAMELEN, and snprintf.

Referenced by SetWALFileNameForCleanup().

◆ XLogFilePath()

◆ XLogFromFileName()

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

◆ XLogRecGetBlockRefInfo()

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

Definition at line 303 of file xlogdesc.c.

306{
307 int block_id;
308
309 Assert(record != NULL);
310
311 if (detailed_format && pretty)
313
314 for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
315 {
316 RelFileLocator rlocator;
317 ForkNumber forknum;
319
321 &rlocator, &forknum, &blk, NULL))
322 continue;
323
324 if (detailed_format)
325 {
326 /* Get block references in detailed format. */
327
328 if (pretty)
330 else if (block_id > 0)
332
334 "blkref #%d: rel %u/%u/%u fork %s blk %u",
335 block_id,
336 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
337 forkNames[forknum],
338 blk);
339
340 if (XLogRecHasBlockImage(record, block_id))
341 {
342 uint8 bimg_info = XLogRecGetBlock(record, block_id)->bimg_info;
343
344 /* Calculate the amount of FPI data in the record. */
345 if (fpi_len)
346 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
347
348 if (BKPIMAGE_COMPRESSED(bimg_info))
349 {
350 const char *method;
351
352 if ((bimg_info & BKPIMAGE_COMPRESS_PGLZ) != 0)
353 method = "pglz";
354 else if ((bimg_info & BKPIMAGE_COMPRESS_LZ4) != 0)
355 method = "lz4";
356 else if ((bimg_info & BKPIMAGE_COMPRESS_ZSTD) != 0)
357 method = "zstd";
358 else
359 method = "unknown";
360
362 " (FPW%s); hole: offset: %u, length: %u, "
363 "compression saved: %u, method: %s",
365 "" : " for WAL verification",
366 XLogRecGetBlock(record, block_id)->hole_offset,
367 XLogRecGetBlock(record, block_id)->hole_length,
368 BLCKSZ -
369 XLogRecGetBlock(record, block_id)->hole_length -
370 XLogRecGetBlock(record, block_id)->bimg_len,
371 method);
372 }
373 else
374 {
376 " (FPW%s); hole: offset: %u, length: %u",
378 "" : " for WAL verification",
379 XLogRecGetBlock(record, block_id)->hole_offset,
380 XLogRecGetBlock(record, block_id)->hole_length);
381 }
382 }
383
384 if (pretty)
386 }
387 else
388 {
389 /* Get block references in short format. */
390
391 if (forknum != MAIN_FORKNUM)
392 {
394 ", blkref #%d: rel %u/%u/%u fork %s blk %u",
395 block_id,
396 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
397 forkNames[forknum],
398 blk);
399 }
400 else
401 {
403 ", blkref #%d: rel %u/%u/%u blk %u",
404 block_id,
405 rlocator.spcOid, rlocator.dbOid, rlocator.relNumber,
406 blk);
407 }
408
409 if (XLogRecHasBlockImage(record, block_id))
410 {
411 /* Calculate the amount of FPI data in the record. */
412 if (fpi_len)
413 *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
414
415 if (XLogRecBlockImageApply(record, block_id))
417 else
418 appendStringInfoString(buf, " FPW for WAL verification");
419 }
420 }
421 }
422
423 if (!detailed_format && pretty)
425}
#define Assert(condition)
Definition c.h:943
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:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
RelFileNumber relNumber
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
#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, fb(), 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 86 of file xlogrecovery.c.

◆ RmgrTable

PGDLLIMPORT RmgrData RmgrTable[]
extern

Definition at line 50 of file rmgr.c.

50 {
51#include "access/rmgrlist.h"
52};

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

◆ StandbyMode

PGDLLIMPORT bool StandbyMode
extern

Definition at line 151 of file xlogrecovery.c.