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