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);
177 rc = system(xlogRestoreCmd);
182 pfree(xlogRestoreCmd);
190 if (
stat(xlogpath, &stat_buf) == 0)
192 if (expectedSize > 0 && stat_buf.
st_size != expectedSize)
213 (
errmsg(
"archive file \"%s\" has wrong size: %lld instead of %lld",
215 (
long long int) stat_buf.
st_size,
216 (
long long int) expectedSize)));
222 (
errmsg(
"restored log file \"%s\" from archive",
224 strcpy(path, xlogpath);
231 int elevel = (errno == ENOENT) ?
LOG :
FATAL;
235 errmsg(
"could not stat file \"%s\": %m", xlogpath),
236 errdetail(
"\"restore_command\" returned a zero exit status, but stat() failed.")));
268 (
errmsg(
"could not restore file \"%s\" from archive: %s",
296 bool failOnSignal,
uint32 wait_event_info)
298 char *xlogRecoveryCmd;
305 Assert(command && commandName);
314 XLogFileName(lastRestartPointFname, restartTli, restartSegNo,
330 rc = system(xlogRecoveryCmd);
333 pfree(xlogRecoveryCmd);
346 (
errmsg(
"%s \"%s\": %s", commandName,
371 static unsigned int deletedcounter = 1;
389 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
396 if (unlink(oldpath) != 0)
399 errmsg(
"could not remove file \"%s\": %m",
456 errmsg(
"could not create archive status file \"%s\": %m",
457 archiveStatusPath)));
464 errmsg(
"could not write archive status file \"%s\": %m",
465 archiveStatusPath)));
514 struct stat stat_buf;
519 if (
stat(archiveDone, &stat_buf) == 0)
524 if (
stat(archiveReady, &stat_buf) == 0)
536 errmsg(
"could not create archive status file \"%s\": %m",
544 errmsg(
"could not write archive status file \"%s\": %m",
568 struct stat stat_buf;
590 if (
stat(archiveStatusPath, &stat_buf) == 0)
595 if (
stat(archiveStatusPath, &stat_buf) == 0)
600 if (
stat(archiveStatusPath, &stat_buf) == 0)
622 struct stat stat_buf;
626 if (
stat(archiveStatusPath, &stat_buf) == 0)
631 if (
stat(archiveStatusPath, &stat_buf) == 0)
636 if (
stat(archiveStatusPath, &stat_buf) == 0)
645 if (
stat(archiveStatusPath, &stat_buf) != 0 &&
667 struct stat stat_buf;
671 if (
stat(archiveStatusPath, &stat_buf) == 0)
676 if (
stat(archiveStatusPath, &stat_buf) == 0)
681 if (
stat(archiveStatusPath, &stat_buf) == 0)
697 struct stat stat_buf;
700 if (
stat(archiveStatusPath, &stat_buf) == 0)
718 unlink(archiveStatusPath);
723 unlink(archiveStatusPath);
void PreRestoreCommand(void)
void PostRestoreCommand(void)
#define Assert(condition)
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)
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