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);
172 rc = system(xlogRestoreCmd);
176 pfree(xlogRestoreCmd);
184 if (
stat(xlogpath, &stat_buf) == 0)
186 if (expectedSize > 0 && stat_buf.
st_size != expectedSize)
207 (
errmsg(
"archive file \"%s\" has wrong size: %lld instead of %lld",
209 (
long long int) stat_buf.
st_size,
210 (
long long int) expectedSize)));
216 (
errmsg(
"restored log file \"%s\" from archive",
218 strcpy(path, xlogpath);
225 int elevel = (errno == ENOENT) ?
LOG :
FATAL;
229 errmsg(
"could not stat file \"%s\": %m", xlogpath),
230 errdetail(
"restore_command returned a zero exit status, but stat() failed.")));
262 (
errmsg(
"could not restore file \"%s\" from archive: %s",
290 bool failOnSignal,
uint32 wait_event_info)
292 char *xlogRecoveryCmd;
299 Assert(command && commandName);
308 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
324 rc = system(xlogRecoveryCmd);
327 pfree(xlogRecoveryCmd);
340 (
errmsg(
"%s \"%s\": %s", commandName,
365 static unsigned int deletedcounter = 1;
383 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
390 if (unlink(oldpath) != 0)
393 errmsg(
"could not remove file \"%s\": %m",
450 errmsg(
"could not create archive status file \"%s\": %m",
451 archiveStatusPath)));
458 errmsg(
"could not write archive status file \"%s\": %m",
459 archiveStatusPath)));
508 struct stat stat_buf;
513 if (
stat(archiveDone, &stat_buf) == 0)
518 if (
stat(archiveReady, &stat_buf) == 0)
530 errmsg(
"could not create archive status file \"%s\": %m",
538 errmsg(
"could not write archive status file \"%s\": %m",
562 struct stat stat_buf;
584 if (
stat(archiveStatusPath, &stat_buf) == 0)
589 if (
stat(archiveStatusPath, &stat_buf) == 0)
594 if (
stat(archiveStatusPath, &stat_buf) == 0)
616 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)
639 if (
stat(archiveStatusPath, &stat_buf) != 0 &&
661 struct stat stat_buf;
665 if (
stat(archiveStatusPath, &stat_buf) == 0)
670 if (
stat(archiveStatusPath, &stat_buf) == 0)
675 if (
stat(archiveStatusPath, &stat_buf) == 0)
691 struct stat stat_buf;
694 if (
stat(archiveStatusPath, &stat_buf) == 0)
712 unlink(archiveStatusPath);
717 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)
@ WAIT_EVENT_RESTORE_COMMAND
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