52 const char *recovername, off_t expectedSize,
106 if (
stat(xlogpath, &stat_buf) != 0)
111 errmsg(
"could not stat file \"%s\": %m",
116 if (unlink(xlogpath) != 0)
119 errmsg(
"could not remove file \"%s\": %m",
144 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
147 Assert(strcmp(lastRestartPointFname, xlogfname) <= 0);
168 StrNCpy(dp, xlogpath, endp - dp);
175 StrNCpy(dp, xlogfname, endp - dp);
181 StrNCpy(dp, lastRestartPointFname, endp - dp);
217 rc = system(xlogRestoreCmd);
227 if (
stat(xlogpath, &stat_buf) == 0)
229 if (expectedSize > 0 && stat_buf.st_size != expectedSize)
245 if (
StandbyMode && stat_buf.st_size < expectedSize)
250 (
errmsg(
"archive file \"%s\" has wrong size: %lu instead of %lu",
252 (
unsigned long) stat_buf.st_size,
253 (
unsigned long) expectedSize)));
259 (
errmsg(
"restored log file \"%s\" from archive",
261 strcpy(path, xlogpath);
271 errmsg(
"could not stat file \"%s\": %m",
304 (
errmsg(
"could not restore file \"%s\" from archive: %s",
343 Assert(command && commandName);
352 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
358 dp = xlogRecoveryCmd;
362 for (sp = command; *sp; sp++)
371 StrNCpy(dp, lastRestartPointFname, endp - dp);
401 rc = system(xlogRecoveryCmd);
413 (
errmsg(
"%s \"%s\": %s", commandName,
433 if (
stat(xlogfpath, &statbuf) == 0)
438 static unsigned int deletedcounter = 1;
451 xlogfpath, deletedcounter++);
452 if (rename(xlogfpath, oldpath) != 0)
456 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
457 xlogfpath, oldpath)));
463 if (unlink(oldpath) != 0)
466 errmsg(
"could not remove file \"%s\": %m",
523 errmsg(
"could not create archive status file \"%s\": %m",
524 archiveStatusPath)));
531 errmsg(
"could not write archive status file \"%s\": %m",
532 archiveStatusPath)));
565 struct stat stat_buf;
570 if (
stat(archiveDone, &stat_buf) == 0)
575 if (
stat(archiveReady, &stat_buf) == 0)
587 errmsg(
"could not create archive status file \"%s\": %m",
595 errmsg(
"could not write archive status file \"%s\": %m",
619 struct stat stat_buf;
634 if (
stat(archiveStatusPath, &stat_buf) == 0)
639 if (
stat(archiveStatusPath, &stat_buf) == 0)
644 if (
stat(archiveStatusPath, &stat_buf) == 0)
666 struct stat stat_buf;
670 if (
stat(archiveStatusPath, &stat_buf) == 0)
675 if (
stat(archiveStatusPath, &stat_buf) == 0)
680 if (
stat(archiveStatusPath, &stat_buf) == 0)
689 if (
stat(archiveStatusPath, &stat_buf) != 0 &&
711 struct stat stat_buf;
715 if (
stat(archiveStatusPath, &stat_buf) == 0)
720 if (
stat(archiveStatusPath, &stat_buf) == 0)
725 if (
stat(archiveStatusPath, &stat_buf) == 0)
741 struct stat stat_buf;
744 if (
stat(archiveStatusPath, &stat_buf) == 0)
762 unlink(archiveStatusPath);
767 unlink(archiveStatusPath);
bool ArchiveRecoveryRequested
#define StatusFilePath(path, xlog, suffix)
void ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal)
bool XLogArchiveIsReadyOrDone(const char *xlog)
void make_native_path(char *path)
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
void KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
bool RecoveryInProgress(void)
char * wait_result_to_str(int exitstatus)
static int fd(const char *x, int i)
void XLogArchiveCleanup(const char *xlog)
void XLogArchiveNotify(const char *xlog)
void WalSndRqstFileReload(void)
#define XLogArchivingAlways()
bool wait_result_is_signal(int exit_status, int signum)
void PostRestoreCommand(void)
bool XLogArchiveCheckDone(const char *xlog)
char * recoveryRestoreCommand
int errcode_for_file_access(void)
FILE * AllocateFile(const char *name, const char *mode)
#define ereport(elevel, rest)
int durable_rename(const char *oldfile, const char *newfile, int elevel)
bool XLogArchiveIsReady(const char *xlog)
void XLogArchiveForceDone(const char *xlog)
static char xlogfpath[MAXPGPATH]
TimeLineID ThisTimeLineID
size_t strlcpy(char *dst, const char *src, size_t siz)
int errmsg_internal(const char *fmt,...)
bool XLogArchiveIsBusy(const char *xlog)
#define Assert(condition)
#define StrNCpy(dst, src, len)
#define XLogArchivingActive()
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
void PreRestoreCommand(void)
int errmsg(const char *fmt,...)
void XLogArchiveNotifySeg(XLogSegNo segno)
void SendPostmasterSignal(PMSignalReason reason)
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)