59 #define PGARCH_AUTOWAKE_INTERVAL 60 61 #define PGARCH_RESTART_INTERVAL 10 68 #define NUM_ARCHIVE_RETRIES 3 74 #define NUM_ORPHAN_CLEANUP_RETRIES 3 87 static volatile sig_atomic_t
wakened =
false;
95 static pid_t pgarch_forkexec(
void);
141 curtime = time(NULL);
148 switch ((pgArchPid = pgarch_forkexec()))
155 (
errmsg(
"could not fork archiver: %m")));
175 return (
int) pgArchPid;
196 pgarch_forkexec(
void)
201 av[ac++] =
"postgres";
203 av[ac++] =
"--forkarch";
210 return postmaster_forkexec(ac, av);
252 int save_errno = errno;
265 int save_errno = errno;
321 time_t curtime = time(NULL);
335 last_copy_time = time(NULL);
371 }
while (!time_to_stop);
393 int failures_orphan = 0;
397 struct stat stat_buf;
425 (
errmsg(
"archive_mode enabled, yet archive_command is not set")));
439 if (
stat(pathname, &stat_buf) != 0 && errno == ENOENT)
444 if (unlink(xlogready) == 0)
447 (
errmsg(
"removed orphan archive status file \"%s\"",
457 (
errmsg(
"removal of orphan archive status file \"%s\" failed too many times, will try again later",
493 (
errmsg(
"archiving write-ahead log file \"%s\" failed too many times, will try again later",
539 strlcpy(dp, pathname, endp - dp);
575 snprintf(activitymsg,
sizeof(activitymsg),
"archiving %s", xlog);
578 rc = system(xlogarchcmd);
594 (
errmsg(
"archive command failed with exit code %d",
596 errdetail(
"The failed archive command was: %s",
603 (
errmsg(
"archive command was terminated by exception 0x%X",
605 errhint(
"See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
606 errdetail(
"The failed archive command was: %s",
610 (
errmsg(
"archive command was terminated by signal %d: %s",
612 errdetail(
"The failed archive command was: %s",
619 (
errmsg(
"archive command exited with unrecognized status %d",
621 errdetail(
"The failed archive command was: %s",
625 snprintf(activitymsg,
sizeof(activitymsg),
"failed on %s", xlog);
630 elog(
DEBUG1,
"archived write-ahead log file \"%s\"", xlog);
632 snprintf(activitymsg,
sizeof(activitymsg),
"last was %s", xlog);
673 bool historyFound =
false;
678 while ((rlde =
ReadDir(rldir, XLogArchiveStatusDir)) != NULL)
680 int basenamelen = (int) strlen(rlde->
d_name) - 6;
694 if (strcmp(rlde->
d_name + basenamelen,
".ready") != 0)
698 memcpy(basename, rlde->
d_name, basenamelen);
699 basename[basenamelen] =
'\0';
712 if (!found || (ishistory && !historyFound))
714 strcpy(xlog, basename);
716 historyFound = ishistory;
718 else if (ishistory || !historyFound)
720 if (strcmp(basename, xlog) < 0)
721 strcpy(xlog, basename);
#define StatusFilePath(path, xlog, suffix)
#define pg_attribute_noreturn()
#define NUM_ORPHAN_CLEANUP_RETRIES
int errhint(const char *fmt,...)
void ProcessConfigFile(GucContext context)
void InitPostmasterChild(void)
#define PGARCH_RESTART_INTERVAL
BackendType MyBackendType
static time_t last_sigterm_time
static time_t last_pgarch_start_time
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void make_native_path(char *path)
#define XLogArchiveCommandSet()
static void pgarch_waken_stop(SIGNAL_ARGS)
void SetLatch(Latch *latch)
void ClosePostmasterPorts(bool am_syslogger)
void PGSharedMemoryDetach(void)
void ResetLatch(Latch *latch)
#define PGARCH_AUTOWAKE_INTERVAL
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
void set_ps_display(const char *activity)
void pg_usleep(long microsec)
static volatile sig_atomic_t wakened
static bool pgarch_readyXlog(char *xlog)
#define NUM_ARCHIVE_RETRIES
static bool pgarch_archiveXlog(char *xlog)
char * XLogArchiveCommand
int errdetail(const char *fmt,...)
#define PostmasterIsAlive()
static void pgarch_ArchiverCopyLoop(void)
DIR * AllocateDir(const char *dirname)
static void pgarch_archiveDone(char *xlog)
static volatile bool time_to_stop
int durable_rename(const char *oldfile, const char *newfile, int elevel)
volatile sig_atomic_t ShutdownRequestPending
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
#define WL_POSTMASTER_DEATH
static void pgarch_MainLoop(void)
#define ereport(elevel,...)
pqsigfunc pqsignal(int signum, pqsigfunc handler)
size_t strlcpy(char *dst, const char *src, size_t siz)
int errmsg_internal(const char *fmt,...)
#define Assert(condition)
#define XLogArchivingActive()
struct dirent * ReadDir(DIR *dir, const char *dirname)
void pgstat_send_archiver(const char *xlog, bool failed)
const char * pg_strsignal(int signum)
void dsm_detach_all(void)
#define IsTLHistoryFileName(fname)
int errmsg(const char *fmt,...)
volatile sig_atomic_t ConfigReloadPending
void init_ps_display(const char *fixed_part)
static volatile sig_atomic_t ready_to_stop
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
static void pgarch_waken(SIGNAL_ARGS)
NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn()