54 const char *recovername, off_t expectedSize,
105 if (
stat(xlogpath, &stat_buf) != 0)
110 errmsg(
"could not stat file \"%s\": %m",
115 if (unlink(xlogpath) != 0)
118 errmsg(
"could not remove file \"%s\": %m",
143 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
146 Assert(strcmp(lastRestartPointFname, xlogfname) <= 0);
154 lastRestartPointFname);
155 if (xlogRestoreCmd == NULL)
156 elog(
ERROR,
"could not build restore command \"%s\"",
171 rc = system(xlogRestoreCmd);
174 pfree(xlogRestoreCmd);
182 if (
stat(xlogpath, &stat_buf) == 0)
184 if (expectedSize > 0 && stat_buf.
st_size != expectedSize)
205 (
errmsg(
"archive file \"%s\" has wrong size: %lld instead of %lld",
207 (
long long int) stat_buf.
st_size,
208 (
long long int) expectedSize)));
214 (
errmsg(
"restored log file \"%s\" from archive",
216 strcpy(path, xlogpath);
227 errmsg(
"could not stat file \"%s\": %m", xlogpath),
228 errdetail(
"restore_command returned a zero exit status, but stat() failed.")));
260 (
errmsg(
"could not restore file \"%s\" from archive: %s",
299 Assert(command && commandName);
308 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
314 dp = xlogRecoveryCmd;
318 for (sp = command; *sp; sp++)
327 strlcpy(dp, lastRestartPointFname, endp - dp);
357 rc = system(xlogRecoveryCmd);
369 (
errmsg(
"%s \"%s\": %s", commandName,
389 if (
stat(xlogfpath, &statbuf) == 0)
394 static unsigned int deletedcounter = 1;
407 xlogfpath, deletedcounter++);
408 if (rename(xlogfpath, oldpath) != 0)
412 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
413 xlogfpath, oldpath)));
419 if (unlink(oldpath) != 0)
422 errmsg(
"could not remove file \"%s\": %m",
479 errmsg(
"could not create archive status file \"%s\": %m",
480 archiveStatusPath)));
487 errmsg(
"could not write archive status file \"%s\": %m",
488 archiveStatusPath)));
521 struct stat stat_buf;
526 if (
stat(archiveDone, &stat_buf) == 0)
531 if (
stat(archiveReady, &stat_buf) == 0)
543 errmsg(
"could not create archive status file \"%s\": %m",
551 errmsg(
"could not write archive status file \"%s\": %m",
575 struct stat stat_buf;
597 if (
stat(archiveStatusPath, &stat_buf) == 0)
602 if (
stat(archiveStatusPath, &stat_buf) == 0)
607 if (
stat(archiveStatusPath, &stat_buf) == 0)
629 struct stat stat_buf;
633 if (
stat(archiveStatusPath, &stat_buf) == 0)
638 if (
stat(archiveStatusPath, &stat_buf) == 0)
643 if (
stat(archiveStatusPath, &stat_buf) == 0)
652 if (
stat(archiveStatusPath, &stat_buf) != 0 &&
674 struct stat stat_buf;
678 if (
stat(archiveStatusPath, &stat_buf) == 0)
683 if (
stat(archiveStatusPath, &stat_buf) == 0)
688 if (
stat(archiveStatusPath, &stat_buf) == 0)
704 struct stat stat_buf;
707 if (
stat(archiveStatusPath, &stat_buf) == 0)
725 unlink(archiveStatusPath);
730 unlink(archiveStatusPath);
bool ArchiveRecoveryRequested
#define StatusFilePath(path, xlog, suffix)
void ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal)
bool XLogArchiveIsReadyOrDone(const char *xlog)
char * BuildRestoreCommand(const char *restoreCommand, const char *xlogpath, const char *xlogfname, const char *lastRestartPointFname)
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)
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)
void pfree(void *pointer)
#define XLogArchivingAlways()
bool wait_result_is_signal(int exit_status, int signum)
void PostRestoreCommand(void)
bool XLogArchiveCheckDone(const char *xlog)
char * recoveryRestoreCommand
int errdetail(const char *fmt,...)
int errcode_for_file_access(void)
FILE * AllocateFile(const char *name, const char *mode)
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
#define ereport(elevel,...)
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 XLogArchivingActive()
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
RecoveryState GetRecoveryState(void)
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)