58 #define PGARCH_AUTOWAKE_INTERVAL 60
60 #define PGARCH_RESTART_INTERVAL 10
67 #define NUM_ARCHIVE_RETRIES 3
73 #define NUM_ORPHAN_CLEANUP_RETRIES 3
78 #define NUM_FILES_PER_DIRECTORY_SCAN 64
196 static time_t last_pgarch_start_time = 0;
197 time_t curtime = time(NULL);
203 if ((
unsigned int) (curtime - last_pgarch_start_time) <
207 last_pgarch_start_time = curtime;
286 int save_errno = errno;
329 time_t curtime = time(NULL);
352 WAIT_EVENT_ARCHIVER_MAIN);
387 int failures_orphan = 0;
391 struct stat stat_buf;
416 (
errmsg(
"archive_mode enabled, yet archiving is not configured")));
430 if (
stat(pathname, &stat_buf) != 0 && errno == ENOENT)
435 if (unlink(xlogready) == 0)
438 (
errmsg(
"removed orphan archive status file \"%s\"",
448 (
errmsg(
"removal of orphan archive status file \"%s\" failed too many times, will try again later",
484 (
errmsg(
"archiving write-ahead log file \"%s\" failed too many times, will try again later",
511 snprintf(activitymsg,
sizeof(activitymsg),
"archiving %s", xlog);
516 snprintf(activitymsg,
sizeof(activitymsg),
"last was %s", xlog);
518 snprintf(activitymsg,
sizeof(activitymsg),
"failed on %s", xlog);
582 if (
stat(status_file, &st) == 0)
584 strcpy(xlog, arch_file);
587 else if (errno != ENOENT)
590 errmsg(
"could not stat file \"%s\": %m", status_file)));
603 while ((rlde =
ReadDir(rldir, XLogArchiveStatusDir)) != NULL)
605 int basenamelen = (int) strlen(rlde->
d_name) - 6;
619 if (strcmp(rlde->
d_name + basenamelen,
".ready") != 0)
623 memcpy(basename, rlde->
d_name, basenamelen);
624 basename[basenamelen] =
'\0';
633 strcpy(arch_file, basename);
648 strcpy(arch_file, basename);
697 if (a_history != b_history)
698 return a_history ? -1 : 1;
701 return strcmp(a_str, b_str);
743 if (rename(rlogready, rlogdone) < 0)
746 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
747 rlogready, rlogdone)));
783 bool archiveLibChanged;
790 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
791 errmsg(
"both archive_command and archive_library set"),
792 errdetail(
"Only one of archive_command, archive_library may be set.")));
797 if (archiveLibChanged)
809 (
errmsg(
"restarting archiver process because value of "
810 "\"archive_library\" was changed")));
829 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
830 errmsg(
"both archive_command and archive_library set"),
831 errdetail(
"Only one of archive_command, archive_library may be set.")));
842 "_PG_archive_module_init",
false, NULL);
844 if (archive_init == NULL)
846 (
errmsg(
"archive modules have to define the symbol %s",
"_PG_archive_module_init")));
852 (
errmsg(
"archive modules must register an archive callback")));
const ArchiveModuleCallbacks *(* ArchiveModuleInit)(void)
void binaryheap_build(binaryheap *heap)
void binaryheap_reset(binaryheap *heap)
bh_node_type binaryheap_first(binaryheap *heap)
void binaryheap_add(binaryheap *heap, bh_node_type d)
bh_node_type binaryheap_remove_first(binaryheap *heap)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
#define MemSet(start, val, len)
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
struct dirent * ReadDir(DIR *dir, const char *dirname)
DIR * AllocateDir(const char *dirname)
volatile sig_atomic_t LogMemoryContextPending
volatile sig_atomic_t ProcSignalBarrierPending
void ProcessConfigFile(GucContext context)
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
volatile sig_atomic_t ShutdownRequestPending
volatile sig_atomic_t ConfigReloadPending
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
void SetLatch(Latch *latch)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
#define WL_POSTMASTER_DEATH
Assert(fmt[strlen(fmt) - 1] !='\n')
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
void ProcessLogMemoryContextInterrupt(void)
static volatile sig_atomic_t time_to_stop
static bool pgarch_archiveXlog(char *xlog)
static void pgarch_die(int code, Datum arg)
#define PGARCH_RESTART_INTERVAL
bool PgArchCanRestart(void)
static bool pgarch_readyXlog(char *xlog)
static PgArchData * PgArch
static void pgarch_MainLoop(void)
#define NUM_ARCHIVE_RETRIES
struct PgArchData PgArchData
static void pgarch_waken_stop(SIGNAL_ARGS)
static volatile sig_atomic_t ready_to_stop
void PgArchiverMain(void)
static struct arch_files_state * arch_files
char * XLogArchiveLibrary
Size PgArchShmemSize(void)
static void LoadArchiveLibrary(void)
static void pgarch_ArchiverCopyLoop(void)
static int ready_file_comparator(Datum a, Datum b, void *arg)
#define NUM_FILES_PER_DIRECTORY_SCAN
void PgArchForceDirScan(void)
static void HandlePgArchInterrupts(void)
static const ArchiveModuleCallbacks * ArchiveCallbacks
static ArchiveModuleState * archive_module_state
void PgArchShmemInit(void)
static void pgarch_call_module_shutdown_cb(int code, Datum arg)
static void pgarch_archiveDone(char *xlog)
#define NUM_ORPHAN_CLEANUP_RETRIES
#define PGARCH_AUTOWAKE_INTERVAL
static time_t last_sigterm_time
void pgstat_report_archiver(const char *xlog, bool failed)
#define PostmasterIsAlive()
pqsigfunc pqsignal(int signo, pqsigfunc func)
static char * DatumGetCString(Datum X)
static Datum CStringGetDatum(const char *X)
void ProcessProcSignalBarrier(void)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
static void set_ps_display(const char *activity)
const ArchiveModuleCallbacks * shell_archive_init(void)
Size add_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
void pg_usleep(long microsec)
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
ArchiveFileCB archive_file_cb
ArchiveShutdownCB shutdown_cb
ArchiveCheckConfiguredCB check_configured_cb
ArchiveStartupCB startup_cb
char arch_filenames[NUM_FILES_PER_DIRECTORY_SCAN][MAX_XFN_CHARS+1]
char * arch_files[NUM_FILES_PER_DIRECTORY_SCAN]
char * XLogArchiveCommand
#define XLogArchivingActive()
static bool IsTLHistoryFileName(const char *fname)
static void StatusFilePath(char *path, const char *xlog, const char *suffix)