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   0xD101 /* 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:358
#define MAXFNAMELEN
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define snprintf
Definition: port.h:192

Definition at line 204 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:358
#define XLOGDIR
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define snprintf
Definition: port.h:192

Definition at line 215 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 210 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 172 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 193 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   0xD101 /* 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 160 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:358
#define XLOGDIR
#define snprintf
Definition: port.h:192

Definition at line 185 of file xlog_internal.h.

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

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

◆ xl_end_of_recovery

◆ xl_parameter_change

◆ xl_restore_point

◆ XLogLongPageHeader

◆ XLogLongPageHeaderData

◆ XLogPageHeader

◆ XLogPageHeaderData

◆ XLogRecData

Enumeration Type Documentation

◆ RecoveryTargetAction

Enumerator
RECOVERY_TARGET_ACTION_PAUSE 
RECOVERY_TARGET_ACTION_PROMOTE 
RECOVERY_TARGET_ACTION_SHUTDOWN 

Definition at line 266 of file xlog_internal.h.

Function Documentation

◆ ExecuteRecoveryCommand()

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

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

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

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

Referenced by CheckArchiveTimeout().

8278 {
8279  pg_time_t result;
8280 
8281  /* Need WALWriteLock, but shared lock is sufficient */
8282  LWLockAcquire(WALWriteLock, LW_SHARED);
8283  result = XLogCtl->lastSegSwitchTime;
8284  *lastSwitchLSN = XLogCtl->lastSegSwitchLSN;
8285  LWLockRelease(WALWriteLock);
8286 
8287  return result;
8288 }
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 11179 of file xlog.c.

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

Referenced by ExecuteRecoveryCommand(), and RestoreArchivedFile().

11180 {
11181  LWLockAcquire(ControlFileLock, LW_SHARED);
11182  *oldrecptr = ControlFile->checkPointCopy.redo;
11184  LWLockRelease(ControlFileLock);
11185 }
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 418 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().

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

◆ RequestXLogSwitch()

XLogRecPtr RequestXLogSwitch ( bool  mark_unimportant)

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

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

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

Referenced by CleanupBackupHistory(), and RemoveOldXlogFiles().

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

◆ XLogArchiveCleanup()

void XLogArchiveCleanup ( const char *  xlog)

Definition at line 749 of file xlogarchive.c.

References MAXPGPATH, and StatusFilePath.

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

750 {
751  char archiveStatusPath[MAXPGPATH];
752 
753  /* Remove the .done file */
754  StatusFilePath(archiveStatusPath, xlog, ".done");
755  unlink(archiveStatusPath);
756  /* should we complain about failure? */
757 
758  /* Remove the .ready file if present --- normally it shouldn't be */
759  StatusFilePath(archiveStatusPath, xlog, ".ready");
760  unlink(archiveStatusPath);
761  /* should we complain about failure? */
762 }
#define StatusFilePath(path, xlog, suffix)
#define MAXPGPATH

◆ XLogArchiveForceDone()

void XLogArchiveForceDone ( const char *  xlog)

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

555 {
556  char archiveReady[MAXPGPATH];
557  char archiveDone[MAXPGPATH];
558  struct stat stat_buf;
559  FILE *fd;
560 
561  /* Exit if already known done */
562  StatusFilePath(archiveDone, xlog, ".done");
563  if (stat(archiveDone, &stat_buf) == 0)
564  return;
565 
566  /* If .ready exists, rename it to .done */
567  StatusFilePath(archiveReady, xlog, ".ready");
568  if (stat(archiveReady, &stat_buf) == 0)
569  {
570  (void) durable_rename(archiveReady, archiveDone, WARNING);
571  return;
572  }
573 
574  /* insert an otherwise empty file called <XLOG>.done */
575  fd = AllocateFile(archiveDone, "w");
576  if (fd == NULL)
577  {
578  ereport(LOG,
580  errmsg("could not create archive status file \"%s\": %m",
581  archiveDone)));
582  return;
583  }
584  if (FreeFile(fd))
585  {
586  ereport(LOG,
588  errmsg("could not write archive status file \"%s\": %m",
589  archiveDone)));
590  return;
591  }
592 }
#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:101
#define MAXPGPATH
int errcode_for_file_access(void)
Definition: elog.c:593
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2207
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:608
#define WARNING
Definition: elog.h:40
#define stat(a, b)
Definition: win32_port.h:264
int FreeFile(FILE *file)
Definition: fd.c:2406
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ XLogArchiveIsBusy()

bool XLogArchiveIsBusy ( const char *  xlog)

Definition at line 656 of file xlogarchive.c.

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

Referenced by do_pg_stop_backup().

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

◆ XLogArchiveIsReady()

bool XLogArchiveIsReady ( const char *  xlog)

Definition at line 731 of file xlogarchive.c.

References MAXPGPATH, stat, and StatusFilePath.

Referenced by RemoveNonParentXlogFiles().

732 {
733  char archiveStatusPath[MAXPGPATH];
734  struct stat stat_buf;
735 
736  StatusFilePath(archiveStatusPath, xlog, ".ready");
737  if (stat(archiveStatusPath, &stat_buf) == 0)
738  return true;
739 
740  return false;
741 }
#define StatusFilePath(path, xlog, suffix)
struct stat stat_buf
Definition: pg_standby.c:101
#define MAXPGPATH
#define stat(a, b)
Definition: win32_port.h:264

◆ XLogArchiveIsReadyOrDone()

bool XLogArchiveIsReadyOrDone ( const char *  xlog)

Definition at line 701 of file xlogarchive.c.

References MAXPGPATH, stat, and StatusFilePath.

Referenced by StartupXLOG().

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

◆ XLogArchiveNotify()

void XLogArchiveNotify ( const char *  xlog)

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

505 {
506  char archiveStatusPath[MAXPGPATH];
507  FILE *fd;
508 
509  /* insert an otherwise empty file called <XLOG>.ready */
510  StatusFilePath(archiveStatusPath, xlog, ".ready");
511  fd = AllocateFile(archiveStatusPath, "w");
512  if (fd == NULL)
513  {
514  ereport(LOG,
516  errmsg("could not create archive status file \"%s\": %m",
517  archiveStatusPath)));
518  return;
519  }
520  if (FreeFile(fd))
521  {
522  ereport(LOG,
524  errmsg("could not write archive status file \"%s\": %m",
525  archiveStatusPath)));
526  return;
527  }
528 
529  /* Notify archiver that it's got something to do */
530  if (IsUnderPostmaster)
532 }
#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:593
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2207
#define ereport(elevel, rest)
Definition: elog.h:141
int FreeFile(FILE *file)
Definition: fd.c:2406
int errmsg(const char *fmt,...)
Definition: elog.c:784
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:146

◆ XLogArchiveNotifySeg()

void XLogArchiveNotifySeg ( XLogSegNo  segno)

Definition at line 538 of file xlogarchive.c.

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

Referenced by XLogWrite().

539 {
540  char xlog[MAXFNAMELEN];
541 
543  XLogArchiveNotify(xlog);
544 }
int wal_segment_size
Definition: xlog.c:112
void XLogArchiveNotify(const char *xlog)
Definition: xlogarchive.c:504
#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