56 const char *recovername, off_t expectedSize,
107 if (
stat(xlogpath, &stat_buf) != 0)
112 errmsg(
"could not stat file \"%s\": %m",
117 if (unlink(xlogpath) != 0)
120 errmsg(
"could not remove file \"%s\": %m",
145 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
148 Assert(strcmp(lastRestartPointFname, xlogfname) <= 0);
156 lastRestartPointFname);
178 rc = system(xlogRestoreCmd);
183 pfree(xlogRestoreCmd);
191 if (
stat(xlogpath, &stat_buf) == 0)
193 if (expectedSize > 0 && stat_buf.
st_size != expectedSize)
214 (
errmsg(
"archive file \"%s\" has wrong size: %lld instead of %lld",
216 (
long long int) stat_buf.
st_size,
217 (
long long int) expectedSize)));
223 (
errmsg(
"restored log file \"%s\" from archive",
225 strcpy(path, xlogpath);
232 int elevel = (errno == ENOENT) ?
LOG :
FATAL;
236 errmsg(
"could not stat file \"%s\": %m", xlogpath),
237 errdetail(
"restore_command returned a zero exit status, but stat() failed.")));
269 (
errmsg(
"could not restore file \"%s\" from archive: %s",
297 bool failOnSignal,
uint32 wait_event_info)
299 char *xlogRecoveryCmd;
306 Assert(command && commandName);
315 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
331 rc = system(xlogRecoveryCmd);
334 pfree(xlogRecoveryCmd);
347 (
errmsg(
"%s \"%s\": %s", commandName,
372 static unsigned int deletedcounter = 1;
390 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
397 if (unlink(oldpath) != 0)
400 errmsg(
"could not remove file \"%s\": %m",
457 errmsg(
"could not create archive status file \"%s\": %m",
458 archiveStatusPath)));
465 errmsg(
"could not write archive status file \"%s\": %m",
466 archiveStatusPath)));
515 struct stat stat_buf;
520 if (
stat(archiveDone, &stat_buf) == 0)
525 if (
stat(archiveReady, &stat_buf) == 0)
537 errmsg(
"could not create archive status file \"%s\": %m",
545 errmsg(
"could not write archive status file \"%s\": %m",
569 struct stat stat_buf;
591 if (
stat(archiveStatusPath, &stat_buf) == 0)
596 if (
stat(archiveStatusPath, &stat_buf) == 0)
601 if (
stat(archiveStatusPath, &stat_buf) == 0)
623 struct stat stat_buf;
627 if (
stat(archiveStatusPath, &stat_buf) == 0)
632 if (
stat(archiveStatusPath, &stat_buf) == 0)
637 if (
stat(archiveStatusPath, &stat_buf) == 0)
646 if (
stat(archiveStatusPath, &stat_buf) != 0 &&
668 struct stat stat_buf;
672 if (
stat(archiveStatusPath, &stat_buf) == 0)
677 if (
stat(archiveStatusPath, &stat_buf) == 0)
682 if (
stat(archiveStatusPath, &stat_buf) == 0)
698 struct stat stat_buf;
701 if (
stat(archiveStatusPath, &stat_buf) == 0)
719 unlink(archiveStatusPath);
724 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)
static void const char fflush(stdout)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
static char xlogfpath[MAXPGPATH]
char * replace_percent_placeholders(const char *instr, const char *param_name, const char *letters,...)
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)
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
void WalSndWakeup(bool physical, bool logical)
void WalSndRqstFileReload(void)
RecoveryState GetRecoveryState(void)
void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
#define XLogArchivingActive()
#define XLogArchivingAlways()
static bool IsTLHistoryFileName(const char *fname)
static void StatusFilePath(char *path, const char *xlog, const char *suffix)
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
static void XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
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