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   0xD102 /* 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 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)
 
bool RestoreArchivedFile (char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
 
void ExecuteRecoveryCommand (const char *command, const char *commandName, bool failOnSignal)
 
void KeepFileRestoredFromArchive (const char *path, const char *xlogfname)
 
void XLogArchiveNotify (const char *xlog)
 
void XLogArchiveNotifySeg (XLogSegNo segno)
 
void XLogArchiveForceDone (const char *xlog)
 
bool XLogArchiveCheckDone (const char *xlog)
 
bool XLogArchiveIsBusy (const char *xlog)
 
bool XLogArchiveIsReady (const char *xlog)
 
bool XLogArchiveIsReadyOrDone (const char *xlog)
 
void XLogArchiveCleanup (const char *xlog)
 

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)
unsigned int uint32
Definition: c.h:359
#define MAXFNAMELEN
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define snprintf
Definition: port.h:192

Definition at line 208 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)
#define MAXPGPATH
unsigned int uint32
Definition: c.h:359
#define XLOGDIR
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define snprintf
Definition: port.h:192

Definition at line 219 of file xlog_internal.h.

Referenced by do_pg_stop_backup().

◆ DEFAULT_MAX_WAL_SEGS

#define DEFAULT_MAX_WAL_SEGS   64

Definition at line 93 of file xlog_internal.h.

Referenced by setup_config().

◆ DEFAULT_MIN_WAL_SEGS

#define DEFAULT_MIN_WAL_SEGS   5

Definition at line 92 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 214 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 176 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 96 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 197 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:89
#define IsPowerOf2(x)
Definition: xlog_internal.h:96
#define WalSegMaxSize
Definition: xlog_internal.h:90

Definition at line 97 of file xlog_internal.h.

Referenced by AuxiliaryProcessMain(), digestControlFile(), main(), 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 90 of file xlog_internal.h.

◆ WalSegMinSize

#define WalSegMinSize   1024 * 1024

Definition at line 89 of file xlog_internal.h.

◆ XLByteInPrevSeg

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

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

Referenced by KillExistingArchiveStatus(), and main().

◆ XLOG_PAGE_MAGIC

#define XLOG_PAGE_MAGIC   0xD102 /* 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 164 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)
#define MAXPGPATH
unsigned int uint32
Definition: c.h:359
#define XLOGDIR
#define snprintf
Definition: port.h:192

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

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

◆ XLogPageHeaderSize

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

Definition at line 85 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 101 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 83 of file xlog_internal.h.

Referenced by XLogReaderValidatePageHeader().

◆ XLP_BKP_REMOVABLE

#define XLP_BKP_REMOVABLE   0x0004

Definition at line 81 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 137 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 74 of file xlog_internal.h.

◆ XLogLongPageHeaderData

◆ XLogPageHeader

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

Function Documentation

◆ ExecuteRecoveryCommand()

void ExecuteRecoveryCommand ( const char *  command,
const char *  commandName,
bool  failOnSignal 
)

Definition at line 331 of file xlogarchive.c.

References Assert, DEBUG3, ereport, errmsg(), errmsg_internal(), FATAL, GetOldestRestartPoint(), MAXPGPATH, StrNCpy, wait_result_is_any_signal(), wait_result_to_str(), wal_segment_size, WARNING, XLByteToSeg, and XLogFileName.

Referenced by CreateRestartPoint(), and StartupXLOG().

332 {
333  char xlogRecoveryCmd[MAXPGPATH];
334  char lastRestartPointFname[MAXPGPATH];
335  char *dp;
336  char *endp;
337  const char *sp;
338  int rc;
339  XLogSegNo restartSegNo;
340  XLogRecPtr restartRedoPtr;
341  TimeLineID restartTli;
342 
343  Assert(command && commandName);
344 
345  /*
346  * Calculate the archive file cutoff point for use during log shipping
347  * replication. All files earlier than this point can be deleted from the
348  * archive, though there is no requirement to do so.
349  */
350  GetOldestRestartPoint(&restartRedoPtr, &restartTli);
351  XLByteToSeg(restartRedoPtr, restartSegNo, wal_segment_size);
352  XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
354 
355  /*
356  * construct the command to be executed
357  */
358  dp = xlogRecoveryCmd;
359  endp = xlogRecoveryCmd + MAXPGPATH - 1;
360  *endp = '\0';
361 
362  for (sp = command; *sp; sp++)
363  {
364  if (*sp == '%')
365  {
366  switch (sp[1])
367  {
368  case 'r':
369  /* %r: filename of last restartpoint */
370  sp++;
371  StrNCpy(dp, lastRestartPointFname, endp - dp);
372  dp += strlen(dp);
373  break;
374  case '%':
375  /* convert %% to a single % */
376  sp++;
377  if (dp < endp)
378  *dp++ = *sp;
379  break;
380  default:
381  /* otherwise treat the % as not special */
382  if (dp < endp)
383  *dp++ = *sp;
384  break;
385  }
386  }
387  else
388  {
389  if (dp < endp)
390  *dp++ = *sp;
391  }
392  }
393  *dp = '\0';
394 
395  ereport(DEBUG3,
396  (errmsg_internal("executing %s \"%s\"", commandName, command)));
397 
398  /*
399  * execute the constructed command
400  */
401  rc = system(xlogRecoveryCmd);
402  if (rc != 0)
403  {
404  /*
405  * If the failure was due to any sort of signal, it's best to punt and
406  * abort recovery. See comments in RestoreArchivedFile().
407  */
408  ereport((failOnSignal && wait_result_is_any_signal(rc, true)) ? FATAL : WARNING,
409  /*------
410  translator: First %s represents a postgresql.conf parameter name like
411  "recovery_end_command", the 2nd is the value of that parameter, the
412  third an already translated error message. */
413  (errmsg("%s \"%s\": %s", commandName,
414  command, wait_result_to_str(rc))));
415  }
416 }
uint32 TimeLineID
Definition: xlogdefs.h:52
int wal_segment_size
Definition: xlog.c:112
#define DEBUG3
Definition: elog.h:23
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
Definition: xlog.c:11221
char * wait_result_to_str(int exitstatus)
Definition: wait_error.c:32
#define FATAL
Definition: elog.h:52
#define MAXPGPATH
uint64 XLogSegNo
Definition: xlogdefs.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
#define WARNING
Definition: elog.h:40
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:739
#define StrNCpy(dst, src, len)
Definition: c.h:935
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
int errmsg(const char *fmt,...)
Definition: elog.c:822
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
Definition: wait_error.c:111
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)

◆ GetLastSegSwitchData()

pg_time_t GetLastSegSwitchData ( XLogRecPtr lastSwitchLSN)

Definition at line 8314 of file xlog.c.

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

Referenced by CheckArchiveTimeout().

8315 {
8316  pg_time_t result;
8317 
8318  /* Need WALWriteLock, but shared lock is sufficient */
8319  LWLockAcquire(WALWriteLock, LW_SHARED);
8320  result = XLogCtl->lastSegSwitchTime;
8321  *lastSwitchLSN = XLogCtl->lastSegSwitchLSN;
8322  LWLockRelease(WALWriteLock);
8323 
8324  return result;
8325 }
int64 pg_time_t
Definition: pgtime.h:23
XLogRecPtr lastSegSwitchLSN
Definition: xlog.c:607
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
pg_time_t lastSegSwitchTime
Definition: xlog.c:606
static XLogCtlData * XLogCtl
Definition: xlog.c:713
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122

◆ GetOldestRestartPoint()

void GetOldestRestartPoint ( XLogRecPtr oldrecptr,
TimeLineID oldtli 
)

Definition at line 11221 of file xlog.c.

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

Referenced by ExecuteRecoveryCommand(), and RestoreArchivedFile().

11222 {
11223  LWLockAcquire(ControlFileLock, LW_SHARED);
11224  *oldrecptr = ControlFile->checkPointCopy.redo;
11226  LWLockRelease(ControlFileLock);
11227 }
CheckPoint checkPointCopy
Definition: pg_control.h:131
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
static ControlFileData * ControlFile
Definition: xlog.c:721
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
XLogRecPtr redo
Definition: pg_control.h:37

◆ KeepFileRestoredFromArchive()

void KeepFileRestoredFromArchive ( const char *  path,
const char *  xlogfname 
)

Definition at line 425 of file xlogarchive.c.

References ARCHIVE_MODE_ALWAYS, durable_rename(), ereport, errcode_for_file_access(), errmsg(), ERROR, FATAL, MAXPGPATH, snprintf, stat, strlcpy(), WalSndRqstFileReload(), WalSndWakeup(), XLogArchiveForceDone(), XLogArchiveMode, XLogArchiveNotify(), XLOGDIR, and xlogfpath.

Referenced by readTimeLineHistory(), restoreTimeLineHistoryFiles(), and XLogFileRead().

426 {
427  char xlogfpath[MAXPGPATH];
428  bool reload = false;
429  struct stat statbuf;
430 
431  snprintf(xlogfpath, MAXPGPATH, XLOGDIR "/%s", xlogfname);
432 
433  if (stat(xlogfpath, &statbuf) == 0)
434  {
435  char oldpath[MAXPGPATH];
436 
437 #ifdef WIN32
438  static unsigned int deletedcounter = 1;
439 
440  /*
441  * On Windows, if another process (e.g a walsender process) holds the
442  * file open in FILE_SHARE_DELETE mode, unlink will succeed, but the
443  * file will still show up in directory listing until the last handle
444  * is closed, and we cannot rename the new file in its place until
445  * that. To avoid that problem, rename the old file to a temporary
446  * name first. Use a counter to create a unique filename, because the
447  * same file might be restored from the archive multiple times, and a
448  * walsender could still be holding onto an old deleted version of it.
449  */
450  snprintf(oldpath, MAXPGPATH, "%s.deleted%u",
451  xlogfpath, deletedcounter++);
452  if (rename(xlogfpath, oldpath) != 0)
453  {
454  ereport(ERROR,
456  errmsg("could not rename file \"%s\" to \"%s\": %m",
457  xlogfpath, oldpath)));
458  }
459 #else
460  /* same-size buffers, so this never truncates */
461  strlcpy(oldpath, xlogfpath, MAXPGPATH);
462 #endif
463  if (unlink(oldpath) != 0)
464  ereport(FATAL,
466  errmsg("could not remove file \"%s\": %m",
467  xlogfpath)));
468  reload = true;
469  }
470 
471  durable_rename(path, xlogfpath, ERROR);
472 
473  /*
474  * Create .done file forcibly to prevent the restored segment from being
475  * archived again later.
476  */
478  XLogArchiveForceDone(xlogfname);
479  else
480  XLogArchiveNotify(xlogfname);
481 
482  /*
483  * If the existing file was replaced, since walsenders might have it open,
484  * request them to reload a currently-open segment. This is only required
485  * for WAL segments, walsenders don't hold other files open, but there's
486  * no harm in doing this too often, and we don't know what kind of a file
487  * we're dealing with here.
488  */
489  if (reload)
491 
492  /*
493  * Signal walsender that new WAL has arrived. Again, this isn't necessary
494  * if we restored something other than a WAL segment, but it does no harm
495  * either.
496  */
497  WalSndWakeup();
498 }
void XLogArchiveNotify(const char *xlog)
Definition: xlogarchive.c:511
void WalSndRqstFileReload(void)
Definition: walsender.c:2912
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
#define MAXPGPATH
int XLogArchiveMode
Definition: xlog.c:91
int errcode_for_file_access(void)
Definition: elog.c:631
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:643
#define stat(a, b)
Definition: win32_port.h:255
void XLogArchiveForceDone(const char *xlog)
Definition: xlogarchive.c:561
#define XLOGDIR
static char xlogfpath[MAXPGPATH]
Definition: parsexlog.c:40
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define snprintf
Definition: port.h:192
void WalSndWakeup(void)
Definition: walsender.c:3033

◆ RequestXLogSwitch()

XLogRecPtr RequestXLogSwitch ( bool  mark_unimportant)

Definition at line 9414 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().

9415 {
9416  XLogRecPtr RecPtr;
9417 
9418  /* XLOG SWITCH has no data */
9419  XLogBeginInsert();
9420 
9421  if (mark_unimportant)
9423  RecPtr = XLogInsert(RM_XLOG_ID, XLOG_SWITCH);
9424 
9425  return RecPtr;
9426 }
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:397
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:229
#define XLOG_SWITCH
Definition: pg_control.h:71
void XLogBeginInsert(void)
Definition: xloginsert.c:120

◆ RestoreArchivedFile()

bool RestoreArchivedFile ( char *  path,
const char *  xlogfname,
const char *  recovername,
off_t  expectedSize,
bool  cleanupEnabled 
)

Definition at line 51 of file xlogarchive.c.

References ArchiveRecoveryRequested, Assert, DEBUG1, DEBUG2, DEBUG3, elevel, ereport, errcode_for_file_access(), errmsg(), errmsg_internal(), FATAL, GetOldestRestartPoint(), LOG, make_native_path(), MAXPGPATH, PostRestoreCommand(), PreRestoreCommand(), proc_exit(), recoveryRestoreCommand, snprintf, StandbyMode, stat, StrNCpy, wait_result_is_any_signal(), wait_result_is_signal(), wait_result_to_str(), wal_segment_size, XLByteToSeg, XLOGDIR, and XLogFileName.

Referenced by existsTimeLineHistory(), readTimeLineHistory(), restoreTimeLineHistoryFiles(), writeTimeLineHistory(), and XLogFileRead().

54 {
55  char xlogpath[MAXPGPATH];
56  char xlogRestoreCmd[MAXPGPATH];
57  char lastRestartPointFname[MAXPGPATH];
58  char *dp;
59  char *endp;
60  const char *sp;
61  int rc;
62  struct stat stat_buf;
63  XLogSegNo restartSegNo;
64  XLogRecPtr restartRedoPtr;
65  TimeLineID restartTli;
66 
67  /*
68  * Ignore restore_command when not in archive recovery (meaning
69  * we are in crash recovery).
70  */
72  goto not_available;
73 
74  /* In standby mode, restore_command might not be supplied */
75  if (recoveryRestoreCommand == NULL || strcmp(recoveryRestoreCommand, "") == 0)
76  goto not_available;
77 
78  /*
79  * When doing archive recovery, we always prefer an archived log file even
80  * if a file of the same name exists in XLOGDIR. The reason is that the
81  * file in XLOGDIR could be an old, un-filled or partly-filled version
82  * that was copied and restored as part of backing up $PGDATA.
83  *
84  * We could try to optimize this slightly by checking the local copy
85  * lastchange timestamp against the archived copy, but we have no API to
86  * do this, nor can we guarantee that the lastchange timestamp was
87  * preserved correctly when we copied to archive. Our aim is robustness,
88  * so we elect not to do this.
89  *
90  * If we cannot obtain the log file from the archive, however, we will try
91  * to use the XLOGDIR file if it exists. This is so that we can make use
92  * of log segments that weren't yet transferred to the archive.
93  *
94  * Notice that we don't actually overwrite any files when we copy back
95  * from archive because the restore_command may inadvertently restore
96  * inappropriate xlogs, or they may be corrupt, so we may wish to fallback
97  * to the segments remaining in current XLOGDIR later. The
98  * copy-from-archive filename is always the same, ensuring that we don't
99  * run out of disk space on long recoveries.
100  */
101  snprintf(xlogpath, MAXPGPATH, XLOGDIR "/%s", recovername);
102 
103  /*
104  * Make sure there is no existing file named recovername.
105  */
106  if (stat(xlogpath, &stat_buf) != 0)
107  {
108  if (errno != ENOENT)
109  ereport(FATAL,
111  errmsg("could not stat file \"%s\": %m",
112  xlogpath)));
113  }
114  else
115  {
116  if (unlink(xlogpath) != 0)
117  ereport(FATAL,
119  errmsg("could not remove file \"%s\": %m",
120  xlogpath)));
121  }
122 
123  /*
124  * Calculate the archive file cutoff point for use during log shipping
125  * replication. All files earlier than this point can be deleted from the
126  * archive, though there is no requirement to do so.
127  *
128  * If cleanup is not enabled, initialise this with the filename of
129  * InvalidXLogRecPtr, which will prevent the deletion of any WAL files
130  * from the archive because of the alphabetic sorting property of WAL
131  * filenames.
132  *
133  * Once we have successfully located the redo pointer of the checkpoint
134  * from which we start recovery we never request a file prior to the redo
135  * pointer of the last restartpoint. When redo begins we know that we have
136  * successfully located it, so there is no need for additional status
137  * flags to signify the point when we can begin deleting WAL files from
138  * the archive.
139  */
140  if (cleanupEnabled)
141  {
142  GetOldestRestartPoint(&restartRedoPtr, &restartTli);
143  XLByteToSeg(restartRedoPtr, restartSegNo, wal_segment_size);
144  XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
146  /* we shouldn't need anything earlier than last restart point */
147  Assert(strcmp(lastRestartPointFname, xlogfname) <= 0);
148  }
149  else
150  XLogFileName(lastRestartPointFname, 0, 0L, wal_segment_size);
151 
152  /*
153  * construct the command to be executed
154  */
155  dp = xlogRestoreCmd;
156  endp = xlogRestoreCmd + MAXPGPATH - 1;
157  *endp = '\0';
158 
159  for (sp = recoveryRestoreCommand; *sp; sp++)
160  {
161  if (*sp == '%')
162  {
163  switch (sp[1])
164  {
165  case 'p':
166  /* %p: relative path of target file */
167  sp++;
168  StrNCpy(dp, xlogpath, endp - dp);
169  make_native_path(dp);
170  dp += strlen(dp);
171  break;
172  case 'f':
173  /* %f: filename of desired file */
174  sp++;
175  StrNCpy(dp, xlogfname, endp - dp);
176  dp += strlen(dp);
177  break;
178  case 'r':
179  /* %r: filename of last restartpoint */
180  sp++;
181  StrNCpy(dp, lastRestartPointFname, endp - dp);
182  dp += strlen(dp);
183  break;
184  case '%':
185  /* convert %% to a single % */
186  sp++;
187  if (dp < endp)
188  *dp++ = *sp;
189  break;
190  default:
191  /* otherwise treat the % as not special */
192  if (dp < endp)
193  *dp++ = *sp;
194  break;
195  }
196  }
197  else
198  {
199  if (dp < endp)
200  *dp++ = *sp;
201  }
202  }
203  *dp = '\0';
204 
205  ereport(DEBUG3,
206  (errmsg_internal("executing restore command \"%s\"",
207  xlogRestoreCmd)));
208 
209  /*
210  * Check signals before restore command and reset afterwards.
211  */
213 
214  /*
215  * Copy xlog from archival storage to XLOGDIR
216  */
217  rc = system(xlogRestoreCmd);
218 
220 
221  if (rc == 0)
222  {
223  /*
224  * command apparently succeeded, but let's make sure the file is
225  * really there now and has the correct size.
226  */
227  if (stat(xlogpath, &stat_buf) == 0)
228  {
229  if (expectedSize > 0 && stat_buf.st_size != expectedSize)
230  {
231  int elevel;
232 
233  /*
234  * If we find a partial file in standby mode, we assume it's
235  * because it's just being copied to the archive, and keep
236  * trying.
237  *
238  * Otherwise treat a wrong-sized file as FATAL to ensure the
239  * DBA would notice it, but is that too strong? We could try
240  * to plow ahead with a local copy of the file ... but the
241  * problem is that there probably isn't one, and we'd
242  * incorrectly conclude we've reached the end of WAL and we're
243  * done recovering ...
244  */
245  if (StandbyMode && stat_buf.st_size < expectedSize)
246  elevel = DEBUG1;
247  else
248  elevel = FATAL;
249  ereport(elevel,
250  (errmsg("archive file \"%s\" has wrong size: %lu instead of %lu",
251  xlogfname,
252  (unsigned long) stat_buf.st_size,
253  (unsigned long) expectedSize)));
254  return false;
255  }
256  else
257  {
258  ereport(LOG,
259  (errmsg("restored log file \"%s\" from archive",
260  xlogfname)));
261  strcpy(path, xlogpath);
262  return true;
263  }
264  }
265  else
266  {
267  /* stat failed */
268  if (errno != ENOENT)
269  ereport(FATAL,
271  errmsg("could not stat file \"%s\": %m",
272  xlogpath)));
273  }
274  }
275 
276  /*
277  * Remember, we rollforward UNTIL the restore fails so failure here is
278  * just part of the process... that makes it difficult to determine
279  * whether the restore failed because there isn't an archive to restore,
280  * or because the administrator has specified the restore program
281  * incorrectly. We have to assume the former.
282  *
283  * However, if the failure was due to any sort of signal, it's best to
284  * punt and abort recovery. (If we "return false" here, upper levels will
285  * assume that recovery is complete and start up the database!) It's
286  * essential to abort on child SIGINT and SIGQUIT, because per spec
287  * system() ignores SIGINT and SIGQUIT while waiting; if we see one of
288  * those it's a good bet we should have gotten it too.
289  *
290  * On SIGTERM, assume we have received a fast shutdown request, and exit
291  * cleanly. It's pure chance whether we receive the SIGTERM first, or the
292  * child process. If we receive it first, the signal handler will call
293  * proc_exit, otherwise we do it here. If we or the child process received
294  * SIGTERM for any other reason than a fast shutdown request, postmaster
295  * will perform an immediate shutdown when it sees us exiting
296  * unexpectedly.
297  *
298  * We treat hard shell errors such as "command not found" as fatal, too.
299  */
300  if (wait_result_is_signal(rc, SIGTERM))
301  proc_exit(1);
302 
304  (errmsg("could not restore file \"%s\" from archive: %s",
305  xlogfname, wait_result_to_str(rc))));
306 
307 not_available:
308 
309  /*
310  * if an archived file is not available, there might still be a version of
311  * this file in XLOGDIR, so return that as the filename to open.
312  *
313  * In many recovery scenarios we expect this to fail also, but if so that
314  * just means we've reached the end of WAL.
315  */
316  snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname);
317  return false;
318 }
bool ArchiveRecoveryRequested
Definition: xlog.c:254
bool StandbyMode
Definition: xlog.c:289
#define DEBUG1
Definition: elog.h:25
uint32 TimeLineID
Definition: xlogdefs.h:52
int wal_segment_size
Definition: xlog.c:112
#define DEBUG3
Definition: elog.h:23
void make_native_path(char *path)
Definition: path.c:166
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
Definition: xlog.c:11221
void proc_exit(int code)
Definition: ipc.c:104
#define LOG
Definition: elog.h:26
char * wait_result_to_str(int exitstatus)
Definition: wait_error.c:32
bool wait_result_is_signal(int exit_status, int signum)
Definition: wait_error.c:92
void PostRestoreCommand(void)
Definition: startup.c:220
struct stat stat_buf
Definition: pg_standby.c:100
#define FATAL
Definition: elog.h:52
#define MAXPGPATH
char * recoveryRestoreCommand
Definition: xlog.c:268
#define DEBUG2
Definition: elog.h:24
uint64 XLogSegNo
Definition: xlogdefs.h:41
int errcode_for_file_access(void)
Definition: elog.c:631
#define ereport(elevel, rest)
Definition: elog.h:141
#define stat(a, b)
Definition: win32_port.h:255
static int elevel
Definition: vacuumlazy.c:143
#define XLOGDIR
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:739
#define StrNCpy(dst, src, len)
Definition: c.h:935
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
void PreRestoreCommand(void)
Definition: startup.c:206
int errmsg(const char *fmt,...)
Definition: elog.c:822
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
Definition: wait_error.c:111
#define snprintf
Definition: port.h:192
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)

◆ XLogArchiveCheckDone()

bool XLogArchiveCheckDone ( const char *  xlog)

Definition at line 616 of file xlogarchive.c.

References MAXPGPATH, RecoveryInProgress(), stat, StatusFilePath, XLogArchiveNotify(), XLogArchivingActive, and XLogArchivingAlways.

Referenced by CleanupBackupHistory(), and RemoveOldXlogFiles().

617 {
618  char archiveStatusPath[MAXPGPATH];
619  struct stat stat_buf;
620  bool inRecovery = RecoveryInProgress();
621 
622  /*
623  * The file is always deletable if archive_mode is "off". On standbys
624  * archiving is disabled if archive_mode is "on", and enabled with
625  * "always". On a primary, archiving is enabled if archive_mode is "on"
626  * or "always".
627  */
628  if (!((XLogArchivingActive() && !inRecovery) ||
629  (XLogArchivingAlways() && inRecovery)))
630  return true;
631 
632  /* First check for .done --- this means archiver is done with it */
633  StatusFilePath(archiveStatusPath, xlog, ".done");
634  if (stat(archiveStatusPath, &stat_buf) == 0)
635  return true;
636 
637  /* check for .ready --- this means archiver is still busy with it */
638  StatusFilePath(archiveStatusPath, xlog, ".ready");
639  if (stat(archiveStatusPath, &stat_buf) == 0)
640  return false;
641 
642  /* Race condition --- maybe archiver just finished, so recheck */
643  StatusFilePath(archiveStatusPath, xlog, ".done");
644  if (stat(archiveStatusPath, &stat_buf) == 0)
645  return true;
646 
647  /* Retry creation of the .ready file */
648  XLogArchiveNotify(xlog);
649  return false;
650 }
#define StatusFilePath(path, xlog, suffix)
bool RecoveryInProgress(void)
Definition: xlog.c:7935
void XLogArchiveNotify(const char *xlog)
Definition: xlogarchive.c:511
#define XLogArchivingAlways()
Definition: xlog.h:173
struct stat stat_buf
Definition: pg_standby.c:100
#define MAXPGPATH
#define stat(a, b)
Definition: win32_port.h:255
#define XLogArchivingActive()
Definition: xlog.h:170

◆ XLogArchiveCleanup()

void XLogArchiveCleanup ( const char *  xlog)

Definition at line 756 of file xlogarchive.c.

References MAXPGPATH, and StatusFilePath.

Referenced by CleanupBackupHistory(), exitArchiveRecovery(), RemoveXlogFile(), and StartupXLOG().

757 {
758  char archiveStatusPath[MAXPGPATH];
759 
760  /* Remove the .done file */
761  StatusFilePath(archiveStatusPath, xlog, ".done");
762  unlink(archiveStatusPath);
763  /* should we complain about failure? */
764 
765  /* Remove the .ready file if present --- normally it shouldn't be */
766  StatusFilePath(archiveStatusPath, xlog, ".ready");
767  unlink(archiveStatusPath);
768  /* should we complain about failure? */
769 }
#define StatusFilePath(path, xlog, suffix)
#define MAXPGPATH

◆ XLogArchiveForceDone()

void XLogArchiveForceDone ( const char *  xlog)

Definition at line 561 of file xlogarchive.c.

References AllocateFile(), durable_rename(), ereport, errcode_for_file_access(), errmsg(), fd(), FreeFile(), LOG, MAXPGPATH, stat, StatusFilePath, and WARNING.

Referenced by KeepFileRestoredFromArchive(), WalReceiverMain(), and XLogWalRcvWrite().

562 {
563  char archiveReady[MAXPGPATH];
564  char archiveDone[MAXPGPATH];
565  struct stat stat_buf;
566  FILE *fd;
567 
568  /* Exit if already known done */
569  StatusFilePath(archiveDone, xlog, ".done");
570  if (stat(archiveDone, &stat_buf) == 0)
571  return;
572 
573  /* If .ready exists, rename it to .done */
574  StatusFilePath(archiveReady, xlog, ".ready");
575  if (stat(archiveReady, &stat_buf) == 0)
576  {
577  (void) durable_rename(archiveReady, archiveDone, WARNING);
578  return;
579  }
580 
581  /* insert an otherwise empty file called <XLOG>.done */
582  fd = AllocateFile(archiveDone, "w");
583  if (fd == NULL)
584  {
585  ereport(LOG,
587  errmsg("could not create archive status file \"%s\": %m",
588  archiveDone)));
589  return;
590  }
591  if (FreeFile(fd))
592  {
593  ereport(LOG,
595  errmsg("could not write archive status file \"%s\": %m",
596  archiveDone)));
597  return;
598  }
599 }
#define StatusFilePath(path, xlog, suffix)
#define LOG
Definition: elog.h:26
static int fd(const char *x, int i)
Definition: preproc-init.c:105
struct stat stat_buf
Definition: pg_standby.c:100
#define MAXPGPATH
int errcode_for_file_access(void)
Definition: elog.c:631
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2242
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:643
#define WARNING
Definition: elog.h:40
#define stat(a, b)
Definition: win32_port.h:255
int FreeFile(FILE *file)
Definition: fd.c:2441
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ XLogArchiveIsBusy()

bool XLogArchiveIsBusy ( const char *  xlog)

Definition at line 663 of file xlogarchive.c.

References MAXPGPATH, snprintf, stat, StatusFilePath, and XLOGDIR.

Referenced by do_pg_stop_backup().

664 {
665  char archiveStatusPath[MAXPGPATH];
666  struct stat stat_buf;
667 
668  /* First check for .done --- this means archiver is done with it */
669  StatusFilePath(archiveStatusPath, xlog, ".done");
670  if (stat(archiveStatusPath, &stat_buf) == 0)
671  return false;
672 
673  /* check for .ready --- this means archiver is still busy with it */
674  StatusFilePath(archiveStatusPath, xlog, ".ready");
675  if (stat(archiveStatusPath, &stat_buf) == 0)
676  return true;
677 
678  /* Race condition --- maybe archiver just finished, so recheck */
679  StatusFilePath(archiveStatusPath, xlog, ".done");
680  if (stat(archiveStatusPath, &stat_buf) == 0)
681  return false;
682 
683  /*
684  * Check to see if the WAL file has been removed by checkpoint, which
685  * implies it has already been archived, and explains why we can't see a
686  * status file for it.
687  */
688  snprintf(archiveStatusPath, MAXPGPATH, XLOGDIR "/%s", xlog);
689  if (stat(archiveStatusPath, &stat_buf) != 0 &&
690  errno == ENOENT)
691  return false;
692 
693  return true;
694 }
#define StatusFilePath(path, xlog, suffix)
struct stat stat_buf
Definition: pg_standby.c:100
#define MAXPGPATH
#define stat(a, b)
Definition: win32_port.h:255
#define XLOGDIR
#define snprintf
Definition: port.h:192

◆ XLogArchiveIsReady()

bool XLogArchiveIsReady ( const char *  xlog)

Definition at line 738 of file xlogarchive.c.

References MAXPGPATH, stat, and StatusFilePath.

Referenced by RemoveNonParentXlogFiles().

739 {
740  char archiveStatusPath[MAXPGPATH];
741  struct stat stat_buf;
742 
743  StatusFilePath(archiveStatusPath, xlog, ".ready");
744  if (stat(archiveStatusPath, &stat_buf) == 0)
745  return true;
746 
747  return false;
748 }
#define StatusFilePath(path, xlog, suffix)
struct stat stat_buf
Definition: pg_standby.c:100
#define MAXPGPATH
#define stat(a, b)
Definition: win32_port.h:255

◆ XLogArchiveIsReadyOrDone()

bool XLogArchiveIsReadyOrDone ( const char *  xlog)

Definition at line 708 of file xlogarchive.c.

References MAXPGPATH, stat, and StatusFilePath.

Referenced by StartupXLOG().

709 {
710  char archiveStatusPath[MAXPGPATH];
711  struct stat stat_buf;
712 
713  /* First check for .done --- this means archiver is done with it */
714  StatusFilePath(archiveStatusPath, xlog, ".done");
715  if (stat(archiveStatusPath, &stat_buf) == 0)
716  return true;
717 
718  /* check for .ready --- this means archiver is still busy with it */
719  StatusFilePath(archiveStatusPath, xlog, ".ready");
720  if (stat(archiveStatusPath, &stat_buf) == 0)
721  return true;
722 
723  /* Race condition --- maybe archiver just finished, so recheck */
724  StatusFilePath(archiveStatusPath, xlog, ".done");
725  if (stat(archiveStatusPath, &stat_buf) == 0)
726  return true;
727 
728  return false;
729 }
#define StatusFilePath(path, xlog, suffix)
struct stat stat_buf
Definition: pg_standby.c:100
#define MAXPGPATH
#define stat(a, b)
Definition: win32_port.h:255

◆ XLogArchiveNotify()

void XLogArchiveNotify ( const char *  xlog)

Definition at line 511 of file xlogarchive.c.

References AllocateFile(), ereport, errcode_for_file_access(), errmsg(), fd(), FreeFile(), IsUnderPostmaster, LOG, MAXPGPATH, PMSIGNAL_WAKEN_ARCHIVER, SendPostmasterSignal(), and StatusFilePath.

Referenced by KeepFileRestoredFromArchive(), StartupXLOG(), WalReceiverMain(), writeTimeLineHistory(), XLogArchiveCheckDone(), XLogArchiveNotifySeg(), and XLogWalRcvWrite().

512 {
513  char archiveStatusPath[MAXPGPATH];
514  FILE *fd;
515 
516  /* insert an otherwise empty file called <XLOG>.ready */
517  StatusFilePath(archiveStatusPath, xlog, ".ready");
518  fd = AllocateFile(archiveStatusPath, "w");
519  if (fd == NULL)
520  {
521  ereport(LOG,
523  errmsg("could not create archive status file \"%s\": %m",
524  archiveStatusPath)));
525  return;
526  }
527  if (FreeFile(fd))
528  {
529  ereport(LOG,
531  errmsg("could not write archive status file \"%s\": %m",
532  archiveStatusPath)));
533  return;
534  }
535 
536  /* Notify archiver that it's got something to do */
537  if (IsUnderPostmaster)
539 }
#define StatusFilePath(path, xlog, suffix)
#define LOG
Definition: elog.h:26
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define MAXPGPATH
bool IsUnderPostmaster
Definition: globals.c:109
int errcode_for_file_access(void)
Definition: elog.c:631
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2242
#define ereport(elevel, rest)
Definition: elog.h:141
int FreeFile(FILE *file)
Definition: fd.c:2441
int errmsg(const char *fmt,...)
Definition: elog.c:822
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:146

◆ XLogArchiveNotifySeg()

void XLogArchiveNotifySeg ( XLogSegNo  segno)

Definition at line 545 of file xlogarchive.c.

References MAXFNAMELEN, ThisTimeLineID, wal_segment_size, XLogArchiveNotify(), and XLogFileName.

Referenced by XLogWrite().

546 {
547  char xlog[MAXFNAMELEN];
548 
550  XLogArchiveNotify(xlog);
551 }
int wal_segment_size
Definition: xlog.c:112
void XLogArchiveNotify(const char *xlog)
Definition: xlogarchive.c:511
#define MAXFNAMELEN
TimeLineID ThisTimeLineID
Definition: xlog.c:187
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)

Variable Documentation

◆ ArchiveRecoveryRequested

◆ InArchiveRecovery

◆ recoveryRestoreCommand

char* recoveryRestoreCommand

Definition at line 268 of file xlog.c.

Referenced by RestoreArchivedFile(), and validateRecoveryParameters().

◆ RmgrTable

const RmgrData RmgrTable[]

◆ StandbyMode

bool StandbyMode