55 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);
155 lastRestartPointFname);
156 if (xlogRestoreCmd == NULL)
157 elog(
ERROR,
"could not build restore command \"%s\"",
173 rc = system(xlogRestoreCmd);
177 pfree(xlogRestoreCmd);
185 if (
stat(xlogpath, &stat_buf) == 0)
187 if (expectedSize > 0 && stat_buf.
st_size != expectedSize)
208 (
errmsg(
"archive file \"%s\" has wrong size: %lld instead of %lld",
210 (
long long int) stat_buf.
st_size,
211 (
long long int) expectedSize)));
217 (
errmsg(
"restored log file \"%s\" from archive",
219 strcpy(path, xlogpath);
226 int elevel = (errno == ENOENT) ?
LOG :
FATAL;
230 errmsg(
"could not stat file \"%s\": %m", xlogpath),
231 errdetail(
"restore_command returned a zero exit status, but stat() failed.")));
263 (
errmsg(
"could not restore file \"%s\" from archive: %s",
291 bool failOnSignal,
uint32 wait_event_info)
303 Assert(command && commandName);
312 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
318 dp = xlogRecoveryCmd;
322 for (sp = command; *sp; sp++)
331 strlcpy(dp, lastRestartPointFname, endp - dp);
362 rc = system(xlogRecoveryCmd);
376 (
errmsg(
"%s \"%s\": %s", commandName,
401 static unsigned int deletedcounter = 1;
419 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
426 if (unlink(oldpath) != 0)
429 errmsg(
"could not remove file \"%s\": %m",
486 errmsg(
"could not create archive status file \"%s\": %m",
487 archiveStatusPath)));
494 errmsg(
"could not write archive status file \"%s\": %m",
495 archiveStatusPath)));
544 struct stat stat_buf;
549 if (
stat(archiveDone, &stat_buf) == 0)
554 if (
stat(archiveReady, &stat_buf) == 0)
566 errmsg(
"could not create archive status file \"%s\": %m",
574 errmsg(
"could not write archive status file \"%s\": %m",
598 struct stat stat_buf;
620 if (
stat(archiveStatusPath, &stat_buf) == 0)
625 if (
stat(archiveStatusPath, &stat_buf) == 0)
630 if (
stat(archiveStatusPath, &stat_buf) == 0)
652 struct stat stat_buf;
656 if (
stat(archiveStatusPath, &stat_buf) == 0)
661 if (
stat(archiveStatusPath, &stat_buf) == 0)
666 if (
stat(archiveStatusPath, &stat_buf) == 0)
675 if (
stat(archiveStatusPath, &stat_buf) != 0 &&
697 struct stat stat_buf;
701 if (
stat(archiveStatusPath, &stat_buf) == 0)
706 if (
stat(archiveStatusPath, &stat_buf) == 0)
711 if (
stat(archiveStatusPath, &stat_buf) == 0)
727 struct stat stat_buf;
730 if (
stat(archiveStatusPath, &stat_buf) == 0)
748 unlink(archiveStatusPath);
753 unlink(archiveStatusPath);
void PreRestoreCommand(void)
void PostRestoreCommand(void)
char * BuildRestoreCommand(const char *restoreCommand, const char *xlogpath, const char *xlogfname, const char *lastRestartPointFname)
int errmsg_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
FILE * AllocateFile(const char *name, const char *mode)
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
static char xlogfpath[MAXPGPATH]
void PgArchForceDirScan(void)
size_t strlcpy(char *dst, const char *src, size_t siz)
static int fd(const char *x, int i)
char * wait_result_to_str(int exitstatus)
bool wait_result_is_signal(int exit_status, int signum)
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
@ WAIT_EVENT_RESTORE_COMMAND
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
void WalSndRqstFileReload(void)
RecoveryState GetRecoveryState(void)
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
#define XLogArchivingActive()
#define XLogArchivingAlways()
#define IsTLHistoryFileName(fname)
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
#define StatusFilePath(path, xlog, suffix)
void XLogArchiveForceDone(const char *xlog)
bool XLogArchiveIsReadyOrDone(const char *xlog)
bool XLogArchiveIsBusy(const char *xlog)
bool XLogArchiveIsReady(const char *xlog)
void XLogArchiveNotifySeg(XLogSegNo segno, TimeLineID tli)
void ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal, uint32 wait_event_info)
bool XLogArchiveCheckDone(const char *xlog)
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
void XLogArchiveNotify(const char *xlog)
void KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
void XLogArchiveCleanup(const char *xlog)
bool ArchiveRecoveryRequested
char * recoveryRestoreCommand