PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgarch.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pgarch.c
4  *
5  * PostgreSQL WAL archiver
6  *
7  * All functions relating to archiver are included here
8  *
9  * - All functions executed by archiver process
10  *
11  * - archiver is forked from postmaster, and the two
12  * processes then communicate using signals. All functions
13  * executed by postmaster are included in this file.
14  *
15  * Initial author: Simon Riggs simon@2ndquadrant.com
16  *
17  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
18  * Portions Copyright (c) 1994, Regents of the University of California
19  *
20  *
21  * IDENTIFICATION
22  * src/backend/postmaster/pgarch.c
23  *
24  *-------------------------------------------------------------------------
25  */
26 #include "postgres.h"
27 
28 #include <fcntl.h>
29 #include <signal.h>
30 #include <time.h>
31 #include <sys/time.h>
32 #include <sys/wait.h>
33 #include <unistd.h>
34 
35 #include "access/xlog.h"
36 #include "access/xlog_internal.h"
37 #include "libpq/pqsignal.h"
38 #include "miscadmin.h"
39 #include "pgstat.h"
41 #include "postmaster/pgarch.h"
42 #include "postmaster/postmaster.h"
43 #include "storage/dsm.h"
44 #include "storage/fd.h"
45 #include "storage/ipc.h"
46 #include "storage/latch.h"
47 #include "storage/pg_shmem.h"
48 #include "storage/pmsignal.h"
49 #include "utils/guc.h"
50 #include "utils/ps_status.h"
51 
52 
53 /* ----------
54  * Timer definitions.
55  * ----------
56  */
57 #define PGARCH_AUTOWAKE_INTERVAL 60 /* How often to force a poll of the
58  * archive status directory; in
59  * seconds. */
60 #define PGARCH_RESTART_INTERVAL 10 /* How often to attempt to restart a
61  * failed archiver; in seconds. */
62 
63 #define NUM_ARCHIVE_RETRIES 3
64 
65 
66 /* ----------
67  * Local data
68  * ----------
69  */
70 static time_t last_pgarch_start_time;
71 static time_t last_sigterm_time = 0;
72 
73 /*
74  * Flags set by interrupt handlers for later service in the main loop.
75  */
76 static volatile sig_atomic_t got_SIGHUP = false;
77 static volatile sig_atomic_t got_SIGTERM = false;
78 static volatile sig_atomic_t wakened = false;
79 static volatile sig_atomic_t ready_to_stop = false;
80 
81 /* ----------
82  * Local function forward declarations
83  * ----------
84  */
85 #ifdef EXEC_BACKEND
86 static pid_t pgarch_forkexec(void);
87 #endif
88 
89 NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn();
90 static void pgarch_exit(SIGNAL_ARGS);
91 static void ArchSigHupHandler(SIGNAL_ARGS);
92 static void ArchSigTermHandler(SIGNAL_ARGS);
93 static void pgarch_waken(SIGNAL_ARGS);
94 static void pgarch_waken_stop(SIGNAL_ARGS);
95 static void pgarch_MainLoop(void);
96 static void pgarch_ArchiverCopyLoop(void);
97 static bool pgarch_archiveXlog(char *xlog);
98 static bool pgarch_readyXlog(char *xlog);
99 static void pgarch_archiveDone(char *xlog);
100 
101 
102 /* ------------------------------------------------------------
103  * Public functions called from postmaster follow
104  * ------------------------------------------------------------
105  */
106 
107 /*
108  * pgarch_start
109  *
110  * Called from postmaster at startup or after an existing archiver
111  * died. Attempt to fire up a fresh archiver process.
112  *
113  * Returns PID of child process, or 0 if fail.
114  *
115  * Note: if fail, we will be called again from the postmaster main loop.
116  */
117 int
119 {
120  time_t curtime;
121  pid_t pgArchPid;
122 
123  /*
124  * Do nothing if no archiver needed
125  */
126  if (!XLogArchivingActive())
127  return 0;
128 
129  /*
130  * Do nothing if too soon since last archiver start. This is a safety
131  * valve to protect against continuous respawn attempts if the archiver is
132  * dying immediately at launch. Note that since we will be re-called from
133  * the postmaster main loop, we will get another chance later.
134  */
135  curtime = time(NULL);
136  if ((unsigned int) (curtime - last_pgarch_start_time) <
137  (unsigned int) PGARCH_RESTART_INTERVAL)
138  return 0;
139  last_pgarch_start_time = curtime;
140 
141 #ifdef EXEC_BACKEND
142  switch ((pgArchPid = pgarch_forkexec()))
143 #else
144  switch ((pgArchPid = fork_process()))
145 #endif
146  {
147  case -1:
148  ereport(LOG,
149  (errmsg("could not fork archiver: %m")));
150  return 0;
151 
152 #ifndef EXEC_BACKEND
153  case 0:
154  /* in postmaster child ... */
156 
157  /* Close the postmaster's sockets */
158  ClosePostmasterPorts(false);
159 
160  /* Drop our connection to postmaster's shared memory, as well */
161  dsm_detach_all();
163 
164  PgArchiverMain(0, NULL);
165  break;
166 #endif
167 
168  default:
169  return (int) pgArchPid;
170  }
171 
172  /* shouldn't get here */
173  return 0;
174 }
175 
176 /* ------------------------------------------------------------
177  * Local functions called by archiver follow
178  * ------------------------------------------------------------
179  */
180 
181 
182 #ifdef EXEC_BACKEND
183 
184 /*
185  * pgarch_forkexec() -
186  *
187  * Format up the arglist for, then fork and exec, archive process
188  */
189 static pid_t
190 pgarch_forkexec(void)
191 {
192  char *av[10];
193  int ac = 0;
194 
195  av[ac++] = "postgres";
196 
197  av[ac++] = "--forkarch";
198 
199  av[ac++] = NULL; /* filled in by postmaster_forkexec */
200 
201  av[ac] = NULL;
202  Assert(ac < lengthof(av));
203 
204  return postmaster_forkexec(ac, av);
205 }
206 #endif /* EXEC_BACKEND */
207 
208 
209 /*
210  * PgArchiverMain
211  *
212  * The argc/argv parameters are valid only in EXEC_BACKEND case. However,
213  * since we don't use 'em, it hardly matters...
214  */
215 NON_EXEC_STATIC void
216 PgArchiverMain(int argc, char *argv[])
217 {
218  /*
219  * Ignore all signals usually bound to some action in the postmaster,
220  * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
221  */
223  pqsignal(SIGINT, SIG_IGN);
224  pqsignal(SIGTERM, ArchSigTermHandler);
236 
237  /*
238  * Identify myself via ps
239  */
240  init_ps_display("archiver process", "", "", "");
241 
242  pgarch_MainLoop();
243 
244  exit(0);
245 }
246 
247 /* SIGQUIT signal handler for archiver process */
248 static void
250 {
251  /* SIGQUIT means curl up and die ... */
252  exit(1);
253 }
254 
255 /* SIGHUP signal handler for archiver process */
256 static void
258 {
259  int save_errno = errno;
260 
261  /* set flag to re-read config file at next convenient time */
262  got_SIGHUP = true;
263  SetLatch(MyLatch);
264 
265  errno = save_errno;
266 }
267 
268 /* SIGTERM signal handler for archiver process */
269 static void
271 {
272  int save_errno = errno;
273 
274  /*
275  * The postmaster never sends us SIGTERM, so we assume that this means
276  * that init is trying to shut down the whole system. If we hang around
277  * too long we'll get SIGKILL'd. Set flag to prevent starting any more
278  * archive commands.
279  */
280  got_SIGTERM = true;
281  SetLatch(MyLatch);
282 
283  errno = save_errno;
284 }
285 
286 /* SIGUSR1 signal handler for archiver process */
287 static void
289 {
290  int save_errno = errno;
291 
292  /* set flag that there is work to be done */
293  wakened = true;
294  SetLatch(MyLatch);
295 
296  errno = save_errno;
297 }
298 
299 /* SIGUSR2 signal handler for archiver process */
300 static void
302 {
303  int save_errno = errno;
304 
305  /* set flag to do a final cycle and shut down afterwards */
306  ready_to_stop = true;
307  SetLatch(MyLatch);
308 
309  errno = save_errno;
310 }
311 
312 /*
313  * pgarch_MainLoop
314  *
315  * Main loop for archiver
316  */
317 static void
319 {
320  pg_time_t last_copy_time = 0;
321  bool time_to_stop;
322 
323  /*
324  * We run the copy loop immediately upon entry, in case there are
325  * unarchived files left over from a previous database run (or maybe the
326  * archiver died unexpectedly). After that we wait for a signal or
327  * timeout before doing more.
328  */
329  wakened = true;
330 
331  /*
332  * There shouldn't be anything for the archiver to do except to wait for a
333  * signal ... however, the archiver exists to protect our data, so she
334  * wakes up occasionally to allow herself to be proactive.
335  */
336  do
337  {
339 
340  /* When we get SIGUSR2, we do one more archive cycle, then exit */
341  time_to_stop = ready_to_stop;
342 
343  /* Check for config update */
344  if (got_SIGHUP)
345  {
346  got_SIGHUP = false;
348  }
349 
350  /*
351  * If we've gotten SIGTERM, we normally just sit and do nothing until
352  * SIGUSR2 arrives. However, that means a random SIGTERM would
353  * disable archiving indefinitely, which doesn't seem like a good
354  * idea. If more than 60 seconds pass since SIGTERM, exit anyway, so
355  * that the postmaster can start a new archiver if needed.
356  */
357  if (got_SIGTERM)
358  {
359  time_t curtime = time(NULL);
360 
361  if (last_sigterm_time == 0)
362  last_sigterm_time = curtime;
363  else if ((unsigned int) (curtime - last_sigterm_time) >=
364  (unsigned int) 60)
365  break;
366  }
367 
368  /* Do what we're here for */
369  if (wakened || time_to_stop)
370  {
371  wakened = false;
373  last_copy_time = time(NULL);
374  }
375 
376  /*
377  * Sleep until a signal is received, or until a poll is forced by
378  * PGARCH_AUTOWAKE_INTERVAL having passed since last_copy_time, or
379  * until postmaster dies.
380  */
381  if (!time_to_stop) /* Don't wait during last iteration */
382  {
383  pg_time_t curtime = (pg_time_t) time(NULL);
384  int timeout;
385 
386  timeout = PGARCH_AUTOWAKE_INTERVAL - (curtime - last_copy_time);
387  if (timeout > 0)
388  {
389  int rc;
390 
391  rc = WaitLatch(MyLatch,
393  timeout * 1000L,
395  if (rc & WL_TIMEOUT)
396  wakened = true;
397  }
398  else
399  wakened = true;
400  }
401 
402  /*
403  * The archiver quits either when the postmaster dies (not expected)
404  * or after completing one more archiving cycle after receiving
405  * SIGUSR2.
406  */
407  } while (PostmasterIsAlive() && !time_to_stop);
408 }
409 
410 /*
411  * pgarch_ArchiverCopyLoop
412  *
413  * Archives all outstanding xlogs then returns
414  */
415 static void
417 {
418  char xlog[MAX_XFN_CHARS + 1];
419 
420  /*
421  * loop through all xlogs with archive_status of .ready and archive
422  * them...mostly we expect this to be a single file, though it is possible
423  * some backend will add files onto the list of those that need archiving
424  * while we are still copying earlier archives
425  */
426  while (pgarch_readyXlog(xlog))
427  {
428  int failures = 0;
429 
430  for (;;)
431  {
432  /*
433  * Do not initiate any more archive commands after receiving
434  * SIGTERM, nor after the postmaster has died unexpectedly. The
435  * first condition is to try to keep from having init SIGKILL the
436  * command, and the second is to avoid conflicts with another
437  * archiver spawned by a newer postmaster.
438  */
439  if (got_SIGTERM || !PostmasterIsAlive())
440  return;
441 
442  /*
443  * Check for config update. This is so that we'll adopt a new
444  * setting for archive_command as soon as possible, even if there
445  * is a backlog of files to be archived.
446  */
447  if (got_SIGHUP)
448  {
449  got_SIGHUP = false;
451  }
452 
453  /* can't do anything if no command ... */
454  if (!XLogArchiveCommandSet())
455  {
457  (errmsg("archive_mode enabled, yet archive_command is not set")));
458  return;
459  }
460 
461  if (pgarch_archiveXlog(xlog))
462  {
463  /* successful */
464  pgarch_archiveDone(xlog);
465 
466  /*
467  * Tell the collector about the WAL file that we successfully
468  * archived
469  */
470  pgstat_send_archiver(xlog, false);
471 
472  break; /* out of inner retry loop */
473  }
474  else
475  {
476  /*
477  * Tell the collector about the WAL file that we failed to
478  * archive
479  */
480  pgstat_send_archiver(xlog, true);
481 
482  if (++failures >= NUM_ARCHIVE_RETRIES)
483  {
485  (errmsg("archiving transaction log file \"%s\" failed too many times, will try again later",
486  xlog)));
487  return; /* give up archiving for now */
488  }
489  pg_usleep(1000000L); /* wait a bit before retrying */
490  }
491  }
492  }
493 }
494 
495 /*
496  * pgarch_archiveXlog
497  *
498  * Invokes system(3) to copy one archive file to wherever it should go
499  *
500  * Returns true if successful
501  */
502 static bool
504 {
505  char xlogarchcmd[MAXPGPATH];
506  char pathname[MAXPGPATH];
507  char activitymsg[MAXFNAMELEN + 16];
508  char *dp;
509  char *endp;
510  const char *sp;
511  int rc;
512 
513  snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
514 
515  /*
516  * construct the command to be executed
517  */
518  dp = xlogarchcmd;
519  endp = xlogarchcmd + MAXPGPATH - 1;
520  *endp = '\0';
521 
522  for (sp = XLogArchiveCommand; *sp; sp++)
523  {
524  if (*sp == '%')
525  {
526  switch (sp[1])
527  {
528  case 'p':
529  /* %p: relative path of source file */
530  sp++;
531  strlcpy(dp, pathname, endp - dp);
532  make_native_path(dp);
533  dp += strlen(dp);
534  break;
535  case 'f':
536  /* %f: filename of source file */
537  sp++;
538  strlcpy(dp, xlog, endp - dp);
539  dp += strlen(dp);
540  break;
541  case '%':
542  /* convert %% to a single % */
543  sp++;
544  if (dp < endp)
545  *dp++ = *sp;
546  break;
547  default:
548  /* otherwise treat the % as not special */
549  if (dp < endp)
550  *dp++ = *sp;
551  break;
552  }
553  }
554  else
555  {
556  if (dp < endp)
557  *dp++ = *sp;
558  }
559  }
560  *dp = '\0';
561 
562  ereport(DEBUG3,
563  (errmsg_internal("executing archive command \"%s\"",
564  xlogarchcmd)));
565 
566  /* Report archive activity in PS display */
567  snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
568  set_ps_display(activitymsg, false);
569 
570  rc = system(xlogarchcmd);
571  if (rc != 0)
572  {
573  /*
574  * If either the shell itself, or a called command, died on a signal,
575  * abort the archiver. We do this because system() ignores SIGINT and
576  * SIGQUIT while waiting; so a signal is very likely something that
577  * should have interrupted us too. If we overreact it's no big deal,
578  * the postmaster will just start the archiver again.
579  *
580  * Per the Single Unix Spec, shells report exit status > 128 when a
581  * called command died on a signal.
582  */
583  int lev = (WIFSIGNALED(rc) || WEXITSTATUS(rc) > 128) ? FATAL : LOG;
584 
585  if (WIFEXITED(rc))
586  {
587  ereport(lev,
588  (errmsg("archive command failed with exit code %d",
589  WEXITSTATUS(rc)),
590  errdetail("The failed archive command was: %s",
591  xlogarchcmd)));
592  }
593  else if (WIFSIGNALED(rc))
594  {
595 #if defined(WIN32)
596  ereport(lev,
597  (errmsg("archive command was terminated by exception 0x%X",
598  WTERMSIG(rc)),
599  errhint("See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
600  errdetail("The failed archive command was: %s",
601  xlogarchcmd)));
602 #elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
603  ereport(lev,
604  (errmsg("archive command was terminated by signal %d: %s",
605  WTERMSIG(rc),
606  WTERMSIG(rc) < NSIG ? sys_siglist[WTERMSIG(rc)] : "(unknown)"),
607  errdetail("The failed archive command was: %s",
608  xlogarchcmd)));
609 #else
610  ereport(lev,
611  (errmsg("archive command was terminated by signal %d",
612  WTERMSIG(rc)),
613  errdetail("The failed archive command was: %s",
614  xlogarchcmd)));
615 #endif
616  }
617  else
618  {
619  ereport(lev,
620  (errmsg("archive command exited with unrecognized status %d",
621  rc),
622  errdetail("The failed archive command was: %s",
623  xlogarchcmd)));
624  }
625 
626  snprintf(activitymsg, sizeof(activitymsg), "failed on %s", xlog);
627  set_ps_display(activitymsg, false);
628 
629  return false;
630  }
631  ereport(DEBUG1,
632  (errmsg("archived transaction log file \"%s\"", xlog)));
633 
634  snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
635  set_ps_display(activitymsg, false);
636 
637  return true;
638 }
639 
640 /*
641  * pgarch_readyXlog
642  *
643  * Return name of the oldest xlog file that has not yet been archived.
644  * No notification is set that file archiving is now in progress, so
645  * this would need to be extended if multiple concurrent archival
646  * tasks were created. If a failure occurs, we will completely
647  * re-copy the file at the next available opportunity.
648  *
649  * It is important that we return the oldest, so that we archive xlogs
650  * in order that they were written, for two reasons:
651  * 1) to maintain the sequential chain of xlogs required for recovery
652  * 2) because the oldest ones will sooner become candidates for
653  * recycling at time of checkpoint
654  *
655  * NOTE: the "oldest" comparison will presently consider all segments of
656  * a timeline with a smaller ID to be older than all segments of a timeline
657  * with a larger ID; the net result being that past timelines are given
658  * higher priority for archiving. This seems okay, or at least not
659  * obviously worth changing.
660  */
661 static bool
662 pgarch_readyXlog(char *xlog)
663 {
664  /*
665  * open xlog status directory and read through list of xlogs that have the
666  * .ready suffix, looking for earliest file. It is possible to optimise
667  * this code, though only a single file is expected on the vast majority
668  * of calls, so....
669  */
670  char XLogArchiveStatusDir[MAXPGPATH];
671  char newxlog[MAX_XFN_CHARS + 6 + 1];
672  DIR *rldir;
673  struct dirent *rlde;
674  bool found = false;
675 
676  snprintf(XLogArchiveStatusDir, MAXPGPATH, XLOGDIR "/archive_status");
677  rldir = AllocateDir(XLogArchiveStatusDir);
678  if (rldir == NULL)
679  ereport(ERROR,
681  errmsg("could not open archive status directory \"%s\": %m",
682  XLogArchiveStatusDir)));
683 
684  while ((rlde = ReadDir(rldir, XLogArchiveStatusDir)) != NULL)
685  {
686  int basenamelen = (int) strlen(rlde->d_name) - 6;
687 
688  if (basenamelen >= MIN_XFN_CHARS &&
689  basenamelen <= MAX_XFN_CHARS &&
690  strspn(rlde->d_name, VALID_XFN_CHARS) >= basenamelen &&
691  strcmp(rlde->d_name + basenamelen, ".ready") == 0)
692  {
693  if (!found)
694  {
695  strcpy(newxlog, rlde->d_name);
696  found = true;
697  }
698  else
699  {
700  if (strcmp(rlde->d_name, newxlog) < 0)
701  strcpy(newxlog, rlde->d_name);
702  }
703  }
704  }
705  FreeDir(rldir);
706 
707  if (found)
708  {
709  /* truncate off the .ready */
710  newxlog[strlen(newxlog) - 6] = '\0';
711  strcpy(xlog, newxlog);
712  }
713  return found;
714 }
715 
716 /*
717  * pgarch_archiveDone
718  *
719  * Emit notification that an xlog file has been successfully archived.
720  * We do this by renaming the status file from NNN.ready to NNN.done.
721  * Eventually, a checkpoint process will notice this and delete both the
722  * NNN.done file and the xlog file itself.
723  */
724 static void
726 {
727  char rlogready[MAXPGPATH];
728  char rlogdone[MAXPGPATH];
729 
730  StatusFilePath(rlogready, xlog, ".ready");
731  StatusFilePath(rlogdone, xlog, ".done");
732  (void) durable_rename(rlogready, rlogdone, WARNING);
733 }
#define StatusFilePath(path, xlog, suffix)
#define SIGUSR1
Definition: win32.h:211
#define DEBUG1
Definition: elog.h:25
int errhint(const char *fmt,...)
Definition: elog.c:987
#define SIGCONT
Definition: win32.h:205
static void ArchSigTermHandler(SIGNAL_ARGS)
Definition: pgarch.c:270
int64 pg_time_t
Definition: pgtime.h:23
#define WL_TIMEOUT
Definition: latch.h:127
void ProcessConfigFile(GucContext context)
void InitPostmasterChild(void)
Definition: miscinit.c:175
#define PGARCH_RESTART_INTERVAL
Definition: pgarch.c:60
static void pgarch_exit(SIGNAL_ARGS)
Definition: pgarch.c:249
#define DEBUG3
Definition: elog.h:23
static time_t last_sigterm_time
Definition: pgarch.c:71
pid_t fork_process(void)
Definition: fork_process.c:31
#define SIGWINCH
Definition: win32.h:209
static time_t last_pgarch_start_time
Definition: pgarch.c:70
void make_native_path(char *path)
Definition: path.c:166
#define XLogArchiveCommandSet()
Definition: xlog.h:139
#define SIGTTIN
Definition: win32.h:207
void set_ps_display(const char *activity, bool force)
Definition: ps_status.c:326
#define WIFEXITED(w)
Definition: win32.h:180
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:301
#define lengthof(array)
Definition: c.h:557
#define pg_attribute_noreturn()
Definition: c.h:648
void ResetLatch(volatile Latch *latch)
Definition: latch.c:462
#define LOG
Definition: elog.h:26
static volatile sig_atomic_t got_SIGHUP
Definition: pgarch.c:76
int pgarch_start(void)
Definition: pgarch.c:118
Definition: dirent.h:9
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2414
#define SIGQUIT
Definition: win32.h:197
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:768
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
#define PGARCH_AUTOWAKE_INTERVAL
Definition: pgarch.c:57
void pg_usleep(long microsec)
Definition: signal.c:53
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:301
#define SIG_IGN
Definition: win32.h:193
Definition: dirent.c:25
#define ERROR
Definition: elog.h:43
#define WIFSIGNALED(w)
Definition: win32.h:181
#define FATAL
Definition: elog.h:52
#define MAXPGPATH
static volatile sig_atomic_t wakened
Definition: pgarch.c:78
static bool pgarch_readyXlog(char *xlog)
Definition: pgarch.c:662
#define NUM_ARCHIVE_RETRIES
Definition: pgarch.c:63
static bool pgarch_archiveXlog(char *xlog)
Definition: pgarch.c:503
#define MIN_XFN_CHARS
Definition: pgarch.h:25
bool PostmasterIsAlive(void)
Definition: pmsignal.c:272
char * XLogArchiveCommand
Definition: xlog.c:93
int errdetail(const char *fmt,...)
Definition: elog.c:873
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgarch_ArchiverCopyLoop(void)
Definition: pgarch.c:416
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2207
static void pgarch_archiveDone(char *xlog)
Definition: pgarch.c:725
sigset_t UnBlockSig
Definition: pqsignal.c:22
#define ereport(elevel, rest)
Definition: elog.h:122
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:586
Definition: guc.h:72
#define WARNING
Definition: elog.h:40
#define MAXFNAMELEN
struct @18::@19 av[32]
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define XLOGDIR
#define VALID_XFN_CHARS
Definition: pgarch.h:27
#define MAX_XFN_CHARS
Definition: pgarch.h:26
#define SIGPIPE
Definition: win32.h:201
#define SIGHUP
Definition: win32.h:196
#define SIG_DFL
Definition: win32.h:191
static void pgarch_MainLoop(void)
Definition: pgarch.c:318
static volatile sig_atomic_t got_SIGTERM
Definition: pgarch.c:77
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
void SetLatch(volatile Latch *latch)
Definition: latch.c:380
#define SIGNAL_ARGS
Definition: c.h:1078
#define WEXITSTATUS(w)
Definition: win32.h:182
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
#define XLogArchivingActive()
Definition: xlog.h:134
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2273
void pgstat_send_archiver(const char *xlog, bool failed)
Definition: pgstat.c:3647
void dsm_detach_all(void)
Definition: dsm.c:655
static void ArchSigHupHandler(SIGNAL_ARGS)
Definition: pgarch.c:257
#define SIGTTOU
Definition: win32.h:208
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct Latch * MyLatch
Definition: globals.c:51
char d_name[MAX_PATH]
Definition: dirent.h:14
#define SIGCHLD
Definition: win32.h:206
static volatile sig_atomic_t ready_to_stop
Definition: pgarch.c:79
#define WTERMSIG(w)
Definition: win32.h:183
#define WL_LATCH_SET
Definition: latch.h:124
#define SIGALRM
Definition: win32.h:202
int FreeDir(DIR *dir)
Definition: fd.c:2316
#define SIGUSR2
Definition: win32.h:212
static void pgarch_waken(SIGNAL_ARGS)
Definition: pgarch.c:288
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:244
NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: pgarch.c:216
#define NON_EXEC_STATIC
Definition: c.h:1120