PostgreSQL Source Code  git master
xlogarchive.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * xlogarchive.c
4  * Functions for archiving WAL files and restoring from the archive.
5  *
6  *
7  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/backend/access/transam/xlogarchive.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres.h"
16 
17 #include <sys/stat.h>
18 #include <sys/wait.h>
19 #include <signal.h>
20 #include <unistd.h>
21 
22 #include "access/xlog.h"
23 #include "access/xlog_internal.h"
24 #include "access/xlogarchive.h"
25 #include "common/archive.h"
26 #include "miscadmin.h"
27 #include "postmaster/startup.h"
28 #include "replication/walsender.h"
29 #include "storage/fd.h"
30 #include "storage/ipc.h"
31 #include "storage/lwlock.h"
32 #include "storage/pmsignal.h"
33 
34 /*
35  * Attempt to retrieve the specified file from off-line archival storage.
36  * If successful, fill "path" with its complete path (note that this will be
37  * a temp file name that doesn't follow the normal naming convention), and
38  * return true.
39  *
40  * If not successful, fill "path" with the name of the normal on-line file
41  * (which may or may not actually exist, but we'll try to use it), and return
42  * false.
43  *
44  * For fixed-size files, the caller may pass the expected size as an
45  * additional crosscheck on successful recovery. If the file size is not
46  * known, set expectedSize = 0.
47  *
48  * When 'cleanupEnabled' is false, refrain from deleting any old WAL segments
49  * in the archive. This is used when fetching the initial checkpoint record,
50  * when we are not yet sure how far back we need the WAL.
51  */
52 bool
53 RestoreArchivedFile(char *path, const char *xlogfname,
54  const char *recovername, off_t expectedSize,
55  bool cleanupEnabled)
56 {
57  char xlogpath[MAXPGPATH];
58  char *xlogRestoreCmd;
59  char lastRestartPointFname[MAXPGPATH];
60  int rc;
61  struct stat stat_buf;
62  XLogSegNo restartSegNo;
63  XLogRecPtr restartRedoPtr;
64  TimeLineID restartTli;
65 
66  /*
67  * Ignore restore_command when not in archive recovery (meaning we are in
68  * crash recovery).
69  */
71  goto not_available;
72 
73  /* In standby mode, restore_command might not be supplied */
74  if (recoveryRestoreCommand == NULL || strcmp(recoveryRestoreCommand, "") == 0)
75  goto not_available;
76 
77  /*
78  * When doing archive recovery, we always prefer an archived log file even
79  * if a file of the same name exists in XLOGDIR. The reason is that the
80  * file in XLOGDIR could be an old, un-filled or partly-filled version
81  * that was copied and restored as part of backing up $PGDATA.
82  *
83  * We could try to optimize this slightly by checking the local copy
84  * lastchange timestamp against the archived copy, but we have no API to
85  * do this, nor can we guarantee that the lastchange timestamp was
86  * preserved correctly when we copied to archive. Our aim is robustness,
87  * so we elect not to do this.
88  *
89  * If we cannot obtain the log file from the archive, however, we will try
90  * to use the XLOGDIR file if it exists. This is so that we can make use
91  * of log segments that weren't yet transferred to the archive.
92  *
93  * Notice that we don't actually overwrite any files when we copy back
94  * from archive because the restore_command may inadvertently restore
95  * inappropriate xlogs, or they may be corrupt, so we may wish to fallback
96  * to the segments remaining in current XLOGDIR later. The
97  * copy-from-archive filename is always the same, ensuring that we don't
98  * run out of disk space on long recoveries.
99  */
100  snprintf(xlogpath, MAXPGPATH, XLOGDIR "/%s", recovername);
101 
102  /*
103  * Make sure there is no existing file named recovername.
104  */
105  if (stat(xlogpath, &stat_buf) != 0)
106  {
107  if (errno != ENOENT)
108  ereport(FATAL,
110  errmsg("could not stat file \"%s\": %m",
111  xlogpath)));
112  }
113  else
114  {
115  if (unlink(xlogpath) != 0)
116  ereport(FATAL,
118  errmsg("could not remove file \"%s\": %m",
119  xlogpath)));
120  }
121 
122  /*
123  * Calculate the archive file cutoff point for use during log shipping
124  * replication. All files earlier than this point can be deleted from the
125  * archive, though there is no requirement to do so.
126  *
127  * If cleanup is not enabled, initialise this with the filename of
128  * InvalidXLogRecPtr, which will prevent the deletion of any WAL files
129  * from the archive because of the alphabetic sorting property of WAL
130  * filenames.
131  *
132  * Once we have successfully located the redo pointer of the checkpoint
133  * from which we start recovery we never request a file prior to the redo
134  * pointer of the last restartpoint. When redo begins we know that we have
135  * successfully located it, so there is no need for additional status
136  * flags to signify the point when we can begin deleting WAL files from
137  * the archive.
138  */
139  if (cleanupEnabled)
140  {
141  GetOldestRestartPoint(&restartRedoPtr, &restartTli);
142  XLByteToSeg(restartRedoPtr, restartSegNo, wal_segment_size);
143  XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
145  /* we shouldn't need anything earlier than last restart point */
146  Assert(strcmp(lastRestartPointFname, xlogfname) <= 0);
147  }
148  else
149  XLogFileName(lastRestartPointFname, 0, 0L, wal_segment_size);
150 
151  /* Build the restore command to execute */
153  xlogpath, xlogfname,
154  lastRestartPointFname);
155  if (xlogRestoreCmd == NULL)
156  elog(ERROR, "could not build restore command \"%s\"",
158 
159  ereport(DEBUG3,
160  (errmsg_internal("executing restore command \"%s\"",
161  xlogRestoreCmd)));
162 
163  /*
164  * Check signals before restore command and reset afterwards.
165  */
167 
168  /*
169  * Copy xlog from archival storage to XLOGDIR
170  */
171  rc = system(xlogRestoreCmd);
172 
174  pfree(xlogRestoreCmd);
175 
176  if (rc == 0)
177  {
178  /*
179  * command apparently succeeded, but let's make sure the file is
180  * really there now and has the correct size.
181  */
182  if (stat(xlogpath, &stat_buf) == 0)
183  {
184  if (expectedSize > 0 && stat_buf.st_size != expectedSize)
185  {
186  int elevel;
187 
188  /*
189  * If we find a partial file in standby mode, we assume it's
190  * because it's just being copied to the archive, and keep
191  * trying.
192  *
193  * Otherwise treat a wrong-sized file as FATAL to ensure the
194  * DBA would notice it, but is that too strong? We could try
195  * to plow ahead with a local copy of the file ... but the
196  * problem is that there probably isn't one, and we'd
197  * incorrectly conclude we've reached the end of WAL and we're
198  * done recovering ...
199  */
200  if (StandbyMode && stat_buf.st_size < expectedSize)
201  elevel = DEBUG1;
202  else
203  elevel = FATAL;
204  ereport(elevel,
205  (errmsg("archive file \"%s\" has wrong size: %lu instead of %lu",
206  xlogfname,
207  (unsigned long) stat_buf.st_size,
208  (unsigned long) expectedSize)));
209  return false;
210  }
211  else
212  {
213  ereport(LOG,
214  (errmsg("restored log file \"%s\" from archive",
215  xlogfname)));
216  strcpy(path, xlogpath);
217  return true;
218  }
219  }
220  else
221  {
222  /* stat failed */
223  if (errno != ENOENT)
224  ereport(FATAL,
226  errmsg("could not stat file \"%s\": %m",
227  xlogpath)));
228  }
229  }
230 
231  /*
232  * Remember, we rollforward UNTIL the restore fails so failure here is
233  * just part of the process... that makes it difficult to determine
234  * whether the restore failed because there isn't an archive to restore,
235  * or because the administrator has specified the restore program
236  * incorrectly. We have to assume the former.
237  *
238  * However, if the failure was due to any sort of signal, it's best to
239  * punt and abort recovery. (If we "return false" here, upper levels will
240  * assume that recovery is complete and start up the database!) It's
241  * essential to abort on child SIGINT and SIGQUIT, because per spec
242  * system() ignores SIGINT and SIGQUIT while waiting; if we see one of
243  * those it's a good bet we should have gotten it too.
244  *
245  * On SIGTERM, assume we have received a fast shutdown request, and exit
246  * cleanly. It's pure chance whether we receive the SIGTERM first, or the
247  * child process. If we receive it first, the signal handler will call
248  * proc_exit, otherwise we do it here. If we or the child process received
249  * SIGTERM for any other reason than a fast shutdown request, postmaster
250  * will perform an immediate shutdown when it sees us exiting
251  * unexpectedly.
252  *
253  * We treat hard shell errors such as "command not found" as fatal, too.
254  */
255  if (wait_result_is_signal(rc, SIGTERM))
256  proc_exit(1);
257 
259  (errmsg("could not restore file \"%s\" from archive: %s",
260  xlogfname, wait_result_to_str(rc))));
261 
262 not_available:
263 
264  /*
265  * if an archived file is not available, there might still be a version of
266  * this file in XLOGDIR, so return that as the filename to open.
267  *
268  * In many recovery scenarios we expect this to fail also, but if so that
269  * just means we've reached the end of WAL.
270  */
271  snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname);
272  return false;
273 }
274 
275 /*
276  * Attempt to execute an external shell command during recovery.
277  *
278  * 'command' is the shell command to be executed, 'commandName' is a
279  * human-readable name describing the command emitted in the logs. If
280  * 'failOnSignal' is true and the command is killed by a signal, a FATAL
281  * error is thrown. Otherwise a WARNING is emitted.
282  *
283  * This is currently used for recovery_end_command and archive_cleanup_command.
284  */
285 void
286 ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal)
287 {
288  char xlogRecoveryCmd[MAXPGPATH];
289  char lastRestartPointFname[MAXPGPATH];
290  char *dp;
291  char *endp;
292  const char *sp;
293  int rc;
294  XLogSegNo restartSegNo;
295  XLogRecPtr restartRedoPtr;
296  TimeLineID restartTli;
297 
298  Assert(command && commandName);
299 
300  /*
301  * Calculate the archive file cutoff point for use during log shipping
302  * replication. All files earlier than this point can be deleted from the
303  * archive, though there is no requirement to do so.
304  */
305  GetOldestRestartPoint(&restartRedoPtr, &restartTli);
306  XLByteToSeg(restartRedoPtr, restartSegNo, wal_segment_size);
307  XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
309 
310  /*
311  * construct the command to be executed
312  */
313  dp = xlogRecoveryCmd;
314  endp = xlogRecoveryCmd + MAXPGPATH - 1;
315  *endp = '\0';
316 
317  for (sp = command; *sp; sp++)
318  {
319  if (*sp == '%')
320  {
321  switch (sp[1])
322  {
323  case 'r':
324  /* %r: filename of last restartpoint */
325  sp++;
326  StrNCpy(dp, lastRestartPointFname, endp - dp);
327  dp += strlen(dp);
328  break;
329  case '%':
330  /* convert %% to a single % */
331  sp++;
332  if (dp < endp)
333  *dp++ = *sp;
334  break;
335  default:
336  /* otherwise treat the % as not special */
337  if (dp < endp)
338  *dp++ = *sp;
339  break;
340  }
341  }
342  else
343  {
344  if (dp < endp)
345  *dp++ = *sp;
346  }
347  }
348  *dp = '\0';
349 
350  ereport(DEBUG3,
351  (errmsg_internal("executing %s \"%s\"", commandName, command)));
352 
353  /*
354  * execute the constructed command
355  */
356  rc = system(xlogRecoveryCmd);
357  if (rc != 0)
358  {
359  /*
360  * If the failure was due to any sort of signal, it's best to punt and
361  * abort recovery. See comments in RestoreArchivedFile().
362  */
363  ereport((failOnSignal && wait_result_is_any_signal(rc, true)) ? FATAL : WARNING,
364  /*------
365  translator: First %s represents a postgresql.conf parameter name like
366  "recovery_end_command", the 2nd is the value of that parameter, the
367  third an already translated error message. */
368  (errmsg("%s \"%s\": %s", commandName,
369  command, wait_result_to_str(rc))));
370  }
371 }
372 
373 
374 /*
375  * A file was restored from the archive under a temporary filename (path),
376  * and now we want to keep it. Rename it under the permanent filename in
377  * pg_wal (xlogfname), replacing any existing file with the same name.
378  */
379 void
380 KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
381 {
382  char xlogfpath[MAXPGPATH];
383  bool reload = false;
384  struct stat statbuf;
385 
386  snprintf(xlogfpath, MAXPGPATH, XLOGDIR "/%s", xlogfname);
387 
388  if (stat(xlogfpath, &statbuf) == 0)
389  {
390  char oldpath[MAXPGPATH];
391 
392 #ifdef WIN32
393  static unsigned int deletedcounter = 1;
394 
395  /*
396  * On Windows, if another process (e.g a walsender process) holds the
397  * file open in FILE_SHARE_DELETE mode, unlink will succeed, but the
398  * file will still show up in directory listing until the last handle
399  * is closed, and we cannot rename the new file in its place until
400  * that. To avoid that problem, rename the old file to a temporary
401  * name first. Use a counter to create a unique filename, because the
402  * same file might be restored from the archive multiple times, and a
403  * walsender could still be holding onto an old deleted version of it.
404  */
405  snprintf(oldpath, MAXPGPATH, "%s.deleted%u",
406  xlogfpath, deletedcounter++);
407  if (rename(xlogfpath, oldpath) != 0)
408  {
409  ereport(ERROR,
411  errmsg("could not rename file \"%s\" to \"%s\": %m",
412  xlogfpath, oldpath)));
413  }
414 #else
415  /* same-size buffers, so this never truncates */
416  strlcpy(oldpath, xlogfpath, MAXPGPATH);
417 #endif
418  if (unlink(oldpath) != 0)
419  ereport(FATAL,
421  errmsg("could not remove file \"%s\": %m",
422  xlogfpath)));
423  reload = true;
424  }
425 
426  durable_rename(path, xlogfpath, ERROR);
427 
428  /*
429  * Create .done file forcibly to prevent the restored segment from being
430  * archived again later.
431  */
433  XLogArchiveForceDone(xlogfname);
434  else
435  XLogArchiveNotify(xlogfname);
436 
437  /*
438  * If the existing file was replaced, since walsenders might have it open,
439  * request them to reload a currently-open segment. This is only required
440  * for WAL segments, walsenders don't hold other files open, but there's
441  * no harm in doing this too often, and we don't know what kind of a file
442  * we're dealing with here.
443  */
444  if (reload)
446 
447  /*
448  * Signal walsender that new WAL has arrived. Again, this isn't necessary
449  * if we restored something other than a WAL segment, but it does no harm
450  * either.
451  */
452  WalSndWakeup();
453 }
454 
455 /*
456  * XLogArchiveNotify
457  *
458  * Create an archive notification file
459  *
460  * The name of the notification file is the message that will be picked up
461  * by the archiver, e.g. we write 0000000100000001000000C6.ready
462  * and the archiver then knows to archive XLOGDIR/0000000100000001000000C6,
463  * then when complete, rename it to 0000000100000001000000C6.done
464  */
465 void
466 XLogArchiveNotify(const char *xlog)
467 {
468  char archiveStatusPath[MAXPGPATH];
469  FILE *fd;
470 
471  /* insert an otherwise empty file called <XLOG>.ready */
472  StatusFilePath(archiveStatusPath, xlog, ".ready");
473  fd = AllocateFile(archiveStatusPath, "w");
474  if (fd == NULL)
475  {
476  ereport(LOG,
478  errmsg("could not create archive status file \"%s\": %m",
479  archiveStatusPath)));
480  return;
481  }
482  if (FreeFile(fd))
483  {
484  ereport(LOG,
486  errmsg("could not write archive status file \"%s\": %m",
487  archiveStatusPath)));
488  return;
489  }
490 
491  /* Notify archiver that it's got something to do */
492  if (IsUnderPostmaster)
494 }
495 
496 /*
497  * Convenience routine to notify using segment number representation of filename
498  */
499 void
501 {
502  char xlog[MAXFNAMELEN];
503 
505  XLogArchiveNotify(xlog);
506 }
507 
508 /*
509  * XLogArchiveForceDone
510  *
511  * Emit notification forcibly that an XLOG segment file has been successfully
512  * archived, by creating <XLOG>.done regardless of whether <XLOG>.ready
513  * exists or not.
514  */
515 void
516 XLogArchiveForceDone(const char *xlog)
517 {
518  char archiveReady[MAXPGPATH];
519  char archiveDone[MAXPGPATH];
520  struct stat stat_buf;
521  FILE *fd;
522 
523  /* Exit if already known done */
524  StatusFilePath(archiveDone, xlog, ".done");
525  if (stat(archiveDone, &stat_buf) == 0)
526  return;
527 
528  /* If .ready exists, rename it to .done */
529  StatusFilePath(archiveReady, xlog, ".ready");
530  if (stat(archiveReady, &stat_buf) == 0)
531  {
532  (void) durable_rename(archiveReady, archiveDone, WARNING);
533  return;
534  }
535 
536  /* insert an otherwise empty file called <XLOG>.done */
537  fd = AllocateFile(archiveDone, "w");
538  if (fd == NULL)
539  {
540  ereport(LOG,
542  errmsg("could not create archive status file \"%s\": %m",
543  archiveDone)));
544  return;
545  }
546  if (FreeFile(fd))
547  {
548  ereport(LOG,
550  errmsg("could not write archive status file \"%s\": %m",
551  archiveDone)));
552  return;
553  }
554 }
555 
556 /*
557  * XLogArchiveCheckDone
558  *
559  * This is called when we are ready to delete or recycle an old XLOG segment
560  * file or backup history file. If it is okay to delete it then return true.
561  * If it is not time to delete it, make sure a .ready file exists, and return
562  * false.
563  *
564  * If <XLOG>.done exists, then return true; else if <XLOG>.ready exists,
565  * then return false; else create <XLOG>.ready and return false.
566  *
567  * The reason we do things this way is so that if the original attempt to
568  * create <XLOG>.ready fails, we'll retry during subsequent checkpoints.
569  */
570 bool
571 XLogArchiveCheckDone(const char *xlog)
572 {
573  char archiveStatusPath[MAXPGPATH];
574  struct stat stat_buf;
575 
576  /* The file is always deletable if archive_mode is "off". */
577  if (!XLogArchivingActive())
578  return true;
579 
580  /*
581  * During archive recovery, the file is deletable if archive_mode is not
582  * "always".
583  */
584  if (!XLogArchivingAlways() &&
586  return true;
587 
588  /*
589  * At this point of the logic, note that we are either a primary with
590  * archive_mode set to "on" or "always", or a standby with archive_mode
591  * set to "always".
592  */
593 
594  /* First check for .done --- this means archiver is done with it */
595  StatusFilePath(archiveStatusPath, xlog, ".done");
596  if (stat(archiveStatusPath, &stat_buf) == 0)
597  return true;
598 
599  /* check for .ready --- this means archiver is still busy with it */
600  StatusFilePath(archiveStatusPath, xlog, ".ready");
601  if (stat(archiveStatusPath, &stat_buf) == 0)
602  return false;
603 
604  /* Race condition --- maybe archiver just finished, so recheck */
605  StatusFilePath(archiveStatusPath, xlog, ".done");
606  if (stat(archiveStatusPath, &stat_buf) == 0)
607  return true;
608 
609  /* Retry creation of the .ready file */
610  XLogArchiveNotify(xlog);
611  return false;
612 }
613 
614 /*
615  * XLogArchiveIsBusy
616  *
617  * Check to see if an XLOG segment file is still unarchived.
618  * This is almost but not quite the inverse of XLogArchiveCheckDone: in
619  * the first place we aren't chartered to recreate the .ready file, and
620  * in the second place we should consider that if the file is already gone
621  * then it's not busy. (This check is needed to handle the race condition
622  * that a checkpoint already deleted the no-longer-needed file.)
623  */
624 bool
625 XLogArchiveIsBusy(const char *xlog)
626 {
627  char archiveStatusPath[MAXPGPATH];
628  struct stat stat_buf;
629 
630  /* First check for .done --- this means archiver is done with it */
631  StatusFilePath(archiveStatusPath, xlog, ".done");
632  if (stat(archiveStatusPath, &stat_buf) == 0)
633  return false;
634 
635  /* check for .ready --- this means archiver is still busy with it */
636  StatusFilePath(archiveStatusPath, xlog, ".ready");
637  if (stat(archiveStatusPath, &stat_buf) == 0)
638  return true;
639 
640  /* Race condition --- maybe archiver just finished, so recheck */
641  StatusFilePath(archiveStatusPath, xlog, ".done");
642  if (stat(archiveStatusPath, &stat_buf) == 0)
643  return false;
644 
645  /*
646  * Check to see if the WAL file has been removed by checkpoint, which
647  * implies it has already been archived, and explains why we can't see a
648  * status file for it.
649  */
650  snprintf(archiveStatusPath, MAXPGPATH, XLOGDIR "/%s", xlog);
651  if (stat(archiveStatusPath, &stat_buf) != 0 &&
652  errno == ENOENT)
653  return false;
654 
655  return true;
656 }
657 
658 /*
659  * XLogArchiveIsReadyOrDone
660  *
661  * Check to see if an XLOG segment file has a .ready or .done file.
662  * This is similar to XLogArchiveIsBusy(), but returns true if the file
663  * is already archived or is about to be archived.
664  *
665  * This is currently only used at recovery. During normal operation this
666  * would be racy: the file might get removed or marked with .ready as we're
667  * checking it, or immediately after we return.
668  */
669 bool
670 XLogArchiveIsReadyOrDone(const char *xlog)
671 {
672  char archiveStatusPath[MAXPGPATH];
673  struct stat stat_buf;
674 
675  /* First check for .done --- this means archiver is done with it */
676  StatusFilePath(archiveStatusPath, xlog, ".done");
677  if (stat(archiveStatusPath, &stat_buf) == 0)
678  return true;
679 
680  /* check for .ready --- this means archiver is still busy with it */
681  StatusFilePath(archiveStatusPath, xlog, ".ready");
682  if (stat(archiveStatusPath, &stat_buf) == 0)
683  return true;
684 
685  /* Race condition --- maybe archiver just finished, so recheck */
686  StatusFilePath(archiveStatusPath, xlog, ".done");
687  if (stat(archiveStatusPath, &stat_buf) == 0)
688  return true;
689 
690  return false;
691 }
692 
693 /*
694  * XLogArchiveIsReady
695  *
696  * Check to see if an XLOG segment file has an archive notification (.ready)
697  * file.
698  */
699 bool
700 XLogArchiveIsReady(const char *xlog)
701 {
702  char archiveStatusPath[MAXPGPATH];
703  struct stat stat_buf;
704 
705  StatusFilePath(archiveStatusPath, xlog, ".ready");
706  if (stat(archiveStatusPath, &stat_buf) == 0)
707  return true;
708 
709  return false;
710 }
711 
712 /*
713  * XLogArchiveCleanup
714  *
715  * Cleanup archive notification file(s) for a particular xlog segment
716  */
717 void
718 XLogArchiveCleanup(const char *xlog)
719 {
720  char archiveStatusPath[MAXPGPATH];
721 
722  /* Remove the .done file */
723  StatusFilePath(archiveStatusPath, xlog, ".done");
724  unlink(archiveStatusPath);
725  /* should we complain about failure? */
726 
727  /* Remove the .ready file if present --- normally it shouldn't be */
728  StatusFilePath(archiveStatusPath, xlog, ".ready");
729  unlink(archiveStatusPath);
730  /* should we complain about failure? */
731 }
bool ArchiveRecoveryRequested
Definition: xlog.c:265
#define StatusFilePath(path, xlog, suffix)
void ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal)
Definition: xlogarchive.c:286
bool XLogArchiveIsReadyOrDone(const char *xlog)
Definition: xlogarchive.c:670
bool StandbyMode
Definition: xlog.c:300
#define DEBUG1
Definition: elog.h:25
uint32 TimeLineID
Definition: xlogdefs.h:52
int wal_segment_size
Definition: xlog.c:116
#define DEBUG3
Definition: elog.h:23
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
Definition: xlog.c:11512
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
Definition: xlogarchive.c:53
void proc_exit(int code)
Definition: ipc.c:104
void KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
Definition: xlogarchive.c:380
#define LOG
Definition: elog.h:26
char * wait_result_to_str(int exitstatus)
Definition: wait_error.c:32
static int fd(const char *x, int i)
Definition: preproc-init.c:105
void XLogArchiveCleanup(const char *xlog)
Definition: xlogarchive.c:718
void XLogArchiveNotify(const char *xlog)
Definition: xlogarchive.c:466
void WalSndRqstFileReload(void)
Definition: walsender.c:2992
void pfree(void *pointer)
Definition: mcxt.c:1056
#define XLogArchivingAlways()
Definition: xlog.h:183
bool wait_result_is_signal(int exit_status, int signum)
Definition: wait_error.c:92
void PostRestoreCommand(void)
Definition: startup.c:228
#define ERROR
Definition: elog.h:43
bool XLogArchiveCheckDone(const char *xlog)
Definition: xlogarchive.c:571
#define FATAL
Definition: elog.h:52
#define MAXPGPATH
char * recoveryRestoreCommand
Definition: xlog.c:279
char * BuildRestoreCommand(const char *restoreCommand, const char *xlogpath, const char *xlogfname, const char *lastRestartPointFname)
Definition: archive.c:39
#define DEBUG2
Definition: elog.h:24
bool IsUnderPostmaster
Definition: globals.c:109
uint64 XLogSegNo
Definition: xlogdefs.h:41
int XLogArchiveMode
Definition: xlog.c:94
int errcode_for_file_access(void)
Definition: elog.c:633
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2320
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:656
bool XLogArchiveIsReady(const char *xlog)
Definition: xlogarchive.c:700
#define WARNING
Definition: elog.h:40
#define stat(a, b)
Definition: win32_port.h:255
#define MAXFNAMELEN
static int elevel
Definition: vacuumlazy.c:323
void XLogArchiveForceDone(const char *xlog)
Definition: xlogarchive.c:516
#define XLOGDIR
static char xlogfpath[MAXPGPATH]
Definition: parsexlog.c:41
TimeLineID ThisTimeLineID
Definition: xlog.c:191
#define ereport(elevel,...)
Definition: elog.h:144
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
bool XLogArchiveIsBusy(const char *xlog)
Definition: xlogarchive.c:625
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:738
#define StrNCpy(dst, src, len)
Definition: c.h:944
#define XLogArchivingActive()
Definition: xlog.h:180
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
RecoveryState GetRecoveryState(void)
Definition: xlog.c:8122
int FreeFile(FILE *file)
Definition: fd.c:2519
void PreRestoreCommand(void)
Definition: startup.c:214
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
void XLogArchiveNotifySeg(XLogSegNo segno)
Definition: xlogarchive.c:500
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:146
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
Definition: wait_error.c:111
#define snprintf
Definition: port.h:193
void WalSndWakeup(void)
Definition: walsender.c:3112
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)