PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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 <time.h>
29#include <sys/stat.h>
30#include <unistd.h>
31
32#include "access/xlog.h"
36#include "lib/binaryheap.h"
37#include "libpq/pqsignal.h"
38#include "pgstat.h"
41#include "postmaster/pgarch.h"
43#include "storage/aio_subsys.h"
44#include "storage/fd.h"
45#include "storage/ipc.h"
46#include "storage/latch.h"
47#include "storage/pmsignal.h"
48#include "storage/proc.h"
49#include "storage/procsignal.h"
50#include "storage/shmem.h"
51#include "utils/guc.h"
52#include "utils/memutils.h"
53#include "utils/ps_status.h"
54#include "utils/resowner.h"
55#include "utils/timeout.h"
56
57
58/* ----------
59 * Timer definitions.
60 * ----------
61 */
62#define PGARCH_AUTOWAKE_INTERVAL 60 /* How often to force a poll of the
63 * archive status directory; in seconds. */
64#define PGARCH_RESTART_INTERVAL 10 /* How often to attempt to restart a
65 * failed archiver; in seconds. */
66
67/*
68 * Maximum number of retries allowed when attempting to archive a WAL
69 * file.
70 */
71#define NUM_ARCHIVE_RETRIES 3
72
73/*
74 * Maximum number of retries allowed when attempting to remove an
75 * orphan archive status file.
76 */
77#define NUM_ORPHAN_CLEANUP_RETRIES 3
78
79/*
80 * Maximum number of .ready files to gather per directory scan.
81 */
82#define NUM_FILES_PER_DIRECTORY_SCAN 64
84/* Shared memory area for archiver process */
85typedef struct PgArchData
86{
87 int pgprocno; /* proc number of archiver process */
88
89 /*
90 * Forces a directory scan in pgarch_readyXlog().
91 */
95char *XLogArchiveLibrary = "";
97
98
99/* ----------
100 * Local data
101 * ----------
102 */
108
109
110/*
111 * Stuff for tracking multiple files to archive from each scan of
112 * archive_status. Minimizing the number of directory scans when there are
113 * many files to archive can significantly improve archival rate.
114 *
115 * arch_heap is a max-heap that is used during the directory scan to track
116 * the highest-priority files to archive. After the directory scan
117 * completes, the file names are stored in ascending order of priority in
118 * arch_files. pgarch_readyXlog() returns files from arch_files until it
119 * is empty, at which point another directory scan must be performed.
120 *
121 * We only need this data in the archiver process, so make it a palloc'd
122 * struct rather than a bunch of static arrays.
123 */
127 int arch_files_size; /* number of live entries in arch_files[] */
129 /* buffers underlying heap, and later arch_files[], entries: */
132
133static struct arch_files_state *arch_files = NULL;
134
135/*
136 * Flags set by interrupt handlers for later service in the main loop.
137 */
138static volatile sig_atomic_t ready_to_stop = false;
139
140/* ----------
141 * Local function forward declarations
142 * ----------
143 */
144static void pgarch_waken_stop(SIGNAL_ARGS);
145static void pgarch_MainLoop(void);
146static void pgarch_ArchiverCopyLoop(void);
147static bool pgarch_archiveXlog(char *xlog);
148static bool pgarch_readyXlog(char *xlog);
149static void pgarch_archiveDone(char *xlog);
150static void pgarch_die(int code, Datum arg);
151static void ProcessPgArchInterrupts(void);
152static int ready_file_comparator(Datum a, Datum b, void *arg);
153static void LoadArchiveLibrary(void);
154static void pgarch_call_module_shutdown_cb(int code, Datum arg);
155
156/* Report shared memory space needed by PgArchShmemInit */
157Size
158PgArchShmemSize(void)
159{
160 Size size = 0;
161
162 size = add_size(size, sizeof(PgArchData));
163
164 return size;
165}
166
167/* Allocate and initialize archiver-related shared memory */
168void
169PgArchShmemInit(void)
170{
171 bool found;
172
173 PgArch = (PgArchData *)
174 ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
175
176 if (!found)
177 {
178 /* First time through, so initialize */
182 }
183}
184
185/*
186 * PgArchCanRestart
187 *
188 * Return true, indicating archiver is allowed to restart, if enough time has
189 * passed since it was last launched to reach PGARCH_RESTART_INTERVAL.
190 * Otherwise return false.
191 *
192 * This is a safety valve to protect against continuous respawn attempts if the
193 * archiver is dying immediately at launch. Note that since we will retry to
194 * launch the archiver from the postmaster main loop, we will get another
195 * chance later.
196 */
197bool
199{
201 time_t curtime = time(NULL);
202
203 /*
204 * If first time through, or time somehow went backwards, always update
205 * last_pgarch_start_time to match the current clock and allow archiver
206 * start. Otherwise allow it only once enough time has elapsed.
207 */
208 if (last_pgarch_start_time == 0 ||
211 {
213 return true;
214 }
215 return false;
216}
217
218
219/* Main entry point for archiver process */
220void
222{
224
226
227 /*
228 * Ignore all signals usually bound to some action in the postmaster,
229 * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
230 */
234 /* SIGQUIT handler was already set up by InitPostmasterChild */
239
240 /* Reset some signals that are accepted by postmaster but not here */
242
243 /* Unblock signals (they were blocked when the postmaster forked us) */
245
246 /* We shouldn't be launched unnecessarily. */
248
249 /* Arrange to clean up at archiver exit */
251
252 /*
253 * Advertise our proc number so that backends can use our latch to wake us
254 * up while we're sleeping.
255 */
257
258 /* Create workspace for pgarch_readyXlog() */
261
262 /* Initialize our max-heap for prioritizing files to archive. */
265
266 /* Initialize our memory context. */
268 "archiver",
270
271 /* Load the archive_library. */
273
275
276 proc_exit(0);
277}
278
279/*
280 * Wake up the archiver
281 */
282void
283PgArchWakeup(void)
284{
286
287 /*
288 * We don't acquire ProcArrayLock here. It's actually fine because
289 * procLatch isn't ever freed, so we just can potentially set the wrong
290 * process' (or no process') latch. Even in that case the archiver will
291 * be relaunched shortly and will start archiving.
292 */
295}
296
297
298/* SIGUSR2 signal handler for archiver process */
299static void
301{
302 /* set flag to do a final cycle and shut down afterwards */
303 ready_to_stop = true;
305}
306
307/*
308 * pgarch_MainLoop
309 *
310 * Main loop for archiver
311 */
312static void
313pgarch_MainLoop(void)
314{
315 bool time_to_stop;
316
317 /*
318 * There shouldn't be anything for the archiver to do except to wait for a
319 * signal ... however, the archiver exists to protect our data, so it
320 * wakes up occasionally to allow itself to be proactive.
321 */
322 do
323 {
325
326 /* When we get SIGUSR2, we do one more archive cycle, then exit */
328
329 /* Check for barrier events and config update */
331
332 /*
333 * If we've gotten SIGTERM, we normally just sit and do nothing until
334 * SIGUSR2 arrives. However, that means a random SIGTERM would
335 * disable archiving indefinitely, which doesn't seem like a good
336 * idea. If more than 60 seconds pass since SIGTERM, exit anyway, so
337 * that the postmaster can start a new archiver if needed. Also exit
338 * if time unexpectedly goes backward.
339 */
341 {
342 time_t curtime = time(NULL);
343
344 if (last_sigterm_time == 0)
346 else if (curtime < last_sigterm_time ||
348 break;
349 }
350
351 /* Do what we're here for */
353
354 /*
355 * Sleep until a signal is received, or until a poll is forced by
356 * PGARCH_AUTOWAKE_INTERVAL, or until postmaster dies.
357 */
358 if (!time_to_stop) /* Don't wait during last iteration */
359 {
360 int rc;
361
362 rc = WaitLatch(MyLatch,
366 if (rc & WL_POSTMASTER_DEATH)
367 time_to_stop = true;
368 }
369
370 /*
371 * The archiver quits either when the postmaster dies (not expected)
372 * or after completing one more archiving cycle after receiving
373 * SIGUSR2.
374 */
375 } while (!time_to_stop);
376}
377
378/*
379 * pgarch_ArchiverCopyLoop
380 *
381 * Archives all outstanding xlogs then returns
382 */
383static void
385{
386 char xlog[MAX_XFN_CHARS + 1];
387
388 /* force directory scan in the first call to pgarch_readyXlog() */
390
391 /*
392 * loop through all xlogs with archive_status of .ready and archive
393 * them...mostly we expect this to be a single file, though it is possible
394 * some backend will add files onto the list of those that need archiving
395 * while we are still copying earlier archives
396 */
397 while (pgarch_readyXlog(xlog))
398 {
399 int failures = 0;
400 int failures_orphan = 0;
401
402 for (;;)
403 {
404 struct stat stat_buf;
405 char pathname[MAXPGPATH];
406
407 /*
408 * Do not initiate any more archive commands after receiving
409 * SIGTERM, nor after the postmaster has died unexpectedly. The
410 * first condition is to try to keep from having init SIGKILL the
411 * command, and the second is to avoid conflicts with another
412 * archiver spawned by a newer postmaster.
413 */
415 return;
416
417 /*
418 * Check for barrier events and config update. This is so that
419 * we'll adopt a new setting for archive_command as soon as
420 * possible, even if there is a backlog of files to be archived.
421 */
423
424 /* Reset variables that might be set by the callback */
426
427 /* can't do anything if not configured ... */
430 {
432 (errmsg("\"archive_mode\" enabled, yet archiving is not configured"),
435 return;
436 }
437
438 /*
439 * Since archive status files are not removed in a durable manner,
440 * a system crash could leave behind .ready files for WAL segments
441 * that have already been recycled or removed. In this case,
442 * simply remove the orphan status file and move on. unlink() is
443 * used here as even on subsequent crashes the same orphan files
444 * would get removed, so there is no need to worry about
445 * durability.
446 */
447 snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
448 if (stat(pathname, &stat_buf) != 0 && errno == ENOENT)
449 {
450 char xlogready[MAXPGPATH];
451
452 StatusFilePath(xlogready, xlog, ".ready");
453 if (unlink(xlogready) == 0)
454 {
456 (errmsg("removed orphan archive status file \"%s\"",
457 xlogready)));
458
459 /* leave loop and move to the next status file */
460 break;
461 }
462
464 {
466 (errmsg("removal of orphan archive status file \"%s\" failed too many times, will try again later",
467 xlogready)));
468
469 /* give up cleanup of orphan status files */
470 return;
471 }
472
473 /* wait a bit before retrying */
474 pg_usleep(1000000L);
475 continue;
476 }
477
478 if (pgarch_archiveXlog(xlog))
479 {
480 /* successful */
481 pgarch_archiveDone(xlog);
482
483 /*
484 * Tell the cumulative stats system about the WAL file that we
485 * successfully archived
486 */
487 pgstat_report_archiver(xlog, false);
488
489 break; /* out of inner retry loop */
490 }
491 else
492 {
493 /*
494 * Tell the cumulative stats system about the WAL file that we
495 * failed to archive
496 */
497 pgstat_report_archiver(xlog, true);
498
499 if (++failures >= NUM_ARCHIVE_RETRIES)
500 {
502 (errmsg("archiving write-ahead log file \"%s\" failed too many times, will try again later",
503 xlog)));
504 return; /* give up archiving for now */
505 }
506 pg_usleep(1000000L); /* wait a bit before retrying */
507 }
508 }
509 }
510}
511
512/*
513 * pgarch_archiveXlog
514 *
515 * Invokes archive_file_cb to copy one archive file to wherever it should go
516 *
517 * Returns true if successful
518 */
519static bool
520pgarch_archiveXlog(char *xlog)
521{
523 MemoryContext oldcontext;
524 char pathname[MAXPGPATH];
525 char activitymsg[MAXFNAMELEN + 16];
526 bool ret;
527
528 snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
529
530 /* Report archive activity in PS display */
531 snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
533
535
536 /*
537 * Since the archiver operates at the bottom of the exception stack,
538 * ERRORs turn into FATALs and cause the archiver process to restart.
539 * However, using ereport(ERROR, ...) when there are problems is easy to
540 * code and maintain. Therefore, we create our own exception handler to
541 * catch ERRORs and return false instead of restarting the archiver
542 * whenever there is a failure.
543 *
544 * We assume ERRORs from the archiving callback are the most common
545 * exceptions experienced by the archiver, so we opt to handle exceptions
546 * here instead of PgArchiverMain() to avoid reinitializing the archiver
547 * too frequently. We could instead add a sigsetjmp() block to
548 * PgArchiverMain() and use PG_TRY/PG_CATCH here, but the extra code to
549 * avoid the odd archiver restart doesn't seem worth it.
550 */
551 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
552 {
553 /* Since not using PG_TRY, must reset error stack by hand */
555
556 /* Prevent interrupts while cleaning up */
558
559 /* Report the error to the server log. */
561
562 /*
563 * Try to clean up anything the archive module left behind. We try to
564 * cover anything that an archive module could conceivably have left
565 * behind, but it is of course possible that modules could be doing
566 * unexpected things that require additional cleanup. Module authors
567 * should be sure to do any extra required cleanup in a PG_CATCH block
568 * within the archiving callback, and they are encouraged to notify
569 * the pgsql-hackers mailing list so that we can add it here.
570 */
577 AtEOXact_Files(false);
578 AtEOXact_HashTables(false);
579
580 /*
581 * Return to the original memory context and clear ErrorContext for
582 * next time.
583 */
584 MemoryContextSwitchTo(oldcontext);
586
587 /* Flush any leaked data */
589
590 /* Remove our exception handler */
592
593 /* Now we can allow interrupts again */
595
596 /* Report failure so that the archiver retries this file */
597 ret = false;
598 }
599 else
600 {
601 /* Enable our exception handler */
603
604 /* Archive the file! */
606 xlog, pathname);
607
608 /* Remove our exception handler */
610
611 /* Reset our memory context and switch back to the original one */
612 MemoryContextSwitchTo(oldcontext);
614 }
615
616 if (ret)
617 snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
618 else
619 snprintf(activitymsg, sizeof(activitymsg), "failed on %s", xlog);
621
622 return ret;
623}
624
625/*
626 * pgarch_readyXlog
627 *
628 * Return name of the oldest xlog file that has not yet been archived.
629 * No notification is set that file archiving is now in progress, so
630 * this would need to be extended if multiple concurrent archival
631 * tasks were created. If a failure occurs, we will completely
632 * re-copy the file at the next available opportunity.
633 *
634 * It is important that we return the oldest, so that we archive xlogs
635 * in order that they were written, for two reasons:
636 * 1) to maintain the sequential chain of xlogs required for recovery
637 * 2) because the oldest ones will sooner become candidates for
638 * recycling at time of checkpoint
639 *
640 * NOTE: the "oldest" comparison will consider any .history file to be older
641 * than any other file except another .history file. Segments on a timeline
642 * with a smaller ID will be older than all segments on a timeline with a
643 * larger ID; the net result being that past timelines are given higher
644 * priority for archiving. This seems okay, or at least not obviously worth
645 * changing.
646 */
647static bool
648pgarch_readyXlog(char *xlog)
649{
651 DIR *rldir;
652 struct dirent *rlde;
653
654 /*
655 * If a directory scan was requested, clear the stored file names and
656 * proceed.
657 */
660
661 /*
662 * If we still have stored file names from the previous directory scan,
663 * try to return one of those. We check to make sure the status file is
664 * still present, as the archive_command for a previous file may have
665 * already marked it done.
666 */
667 while (arch_files->arch_files_size > 0)
668 {
669 struct stat st;
671 char *arch_file;
672
676
677 if (stat(status_file, &st) == 0)
678 {
679 strcpy(xlog, arch_file);
680 return true;
681 }
682 else if (errno != ENOENT)
685 errmsg("could not stat file \"%s\": %m", status_file)));
686 }
687
688 /* arch_heap is probably empty, but let's make sure */
690
691 /*
692 * Open the archive status directory and read through the list of files
693 * with the .ready suffix, looking for the earliest files.
694 */
695 snprintf(XLogArchiveStatusDir, MAXPGPATH, XLOGDIR "/archive_status");
697
699 {
700 int basenamelen = (int) strlen(rlde->d_name) - 6;
701 char basename[MAX_XFN_CHARS + 1];
702 char *arch_file;
703
704 /* Ignore entries with unexpected number of characters */
707 continue;
708
709 /* Ignore entries with unexpected characters */
710 if (strspn(rlde->d_name, VALID_XFN_CHARS) < basenamelen)
711 continue;
712
713 /* Ignore anything not suffixed with .ready */
714 if (strcmp(rlde->d_name + basenamelen, ".ready") != 0)
715 continue;
716
717 /* Truncate off the .ready */
718 memcpy(basename, rlde->d_name, basenamelen);
719 basename[basenamelen] = '\0';
720
721 /*
722 * Store the file in our max-heap if it has a high enough priority.
723 */
725 {
726 /* If the heap isn't full yet, quickly add it. */
730
731 /* If we just filled the heap, make it a valid one. */
734 }
737 {
738 /*
739 * Remove the lowest priority file and add the current one to the
740 * heap.
741 */
745 }
746 }
747 FreeDir(rldir);
748
749 /* If no files were found, simply return. */
751 return false;
752
753 /*
754 * If we didn't fill the heap, we didn't make it a valid one. Do that
755 * now.
756 */
759
760 /*
761 * Fill arch_files array with the files to archive in ascending order of
762 * priority.
763 */
765 for (int i = 0; i < arch_files->arch_files_size; i++)
767
768 /* Return the highest priority file. */
771
772 return true;
773}
774
775/*
776 * ready_file_comparator
777 *
778 * Compares the archival priority of the given files to archive. If "a"
779 * has a higher priority than "b", a negative value will be returned. If
780 * "b" has a higher priority than "a", a positive value will be returned.
781 * If "a" and "b" have equivalent values, 0 will be returned.
782 */
783static int
785{
786 char *a_str = DatumGetCString(a);
787 char *b_str = DatumGetCString(b);
790
791 /* Timeline history files always have the highest priority. */
792 if (a_history != b_history)
793 return a_history ? -1 : 1;
794
795 /* Priority is given to older files. */
796 return strcmp(a_str, b_str);
797}
798
799/*
800 * PgArchForceDirScan
801 *
802 * When called, the next call to pgarch_readyXlog() will perform a
803 * directory scan. This is useful for ensuring that important files such
804 * as timeline history files are archived as quickly as possible.
805 */
806void
808{
810}
811
812/*
813 * pgarch_archiveDone
814 *
815 * Emit notification that an xlog file has been successfully archived.
816 * We do this by renaming the status file from NNN.ready to NNN.done.
817 * Eventually, a checkpoint process will notice this and delete both the
818 * NNN.done file and the xlog file itself.
819 */
820static void
821pgarch_archiveDone(char *xlog)
822{
823 char rlogready[MAXPGPATH];
824 char rlogdone[MAXPGPATH];
825
826 StatusFilePath(rlogready, xlog, ".ready");
827 StatusFilePath(rlogdone, xlog, ".done");
828
829 /*
830 * To avoid extra overhead, we don't durably rename the .ready file to
831 * .done. Archive commands and libraries must gracefully handle attempts
832 * to re-archive files (e.g., if the server crashes just before this
833 * function is called), so it should be okay if the .ready file reappears
834 * after a crash.
835 */
836 if (rename(rlogready, rlogdone) < 0)
839 errmsg("could not rename file \"%s\" to \"%s\": %m",
841}
842
843
844/*
845 * pgarch_die
846 *
847 * Exit-time cleanup handler
848 */
849static void
850pgarch_die(int code, Datum arg)
851{
853}
854
855/*
856 * Interrupt handler for WAL archiver process.
857 *
858 * This is called in the loops pgarch_MainLoop and pgarch_ArchiverCopyLoop.
859 * It checks for barrier events, config update and request for logging of
860 * memory contexts, but not shutdown request because how to handle
861 * shutdown request is different between those loops.
862 */
863static void
865{
868
869 /* Perform logging of memory contexts of this process */
872
874 {
877
878 ConfigReloadPending = false;
880
881 if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
884 errmsg("both \"archive_command\" and \"archive_library\" set"),
885 errdetail("Only one of \"archive_command\", \"archive_library\" may be set.")));
886
889
891 {
892 /*
893 * Ideally, we would simply unload the previous archive module and
894 * load the new one, but there is presently no mechanism for
895 * unloading a library (see the comment above
896 * internal_load_library()). To deal with this, we simply restart
897 * the archiver. The new archive module will be loaded when the
898 * new archiver process starts up. Note that this triggers the
899 * module's shutdown callback, if defined.
900 */
901 ereport(LOG,
902 (errmsg("restarting archiver process because value of "
903 "\"archive_library\" was changed")));
904
905 proc_exit(0);
906 }
907 }
908}
909
910/*
911 * LoadArchiveLibrary
912 *
913 * Loads the archiving callbacks into our local ArchiveCallbacks.
914 */
915static void
917{
919
920 if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
923 errmsg("both \"archive_command\" and \"archive_library\" set"),
924 errdetail("Only one of \"archive_command\", \"archive_library\" may be set.")));
925
926 /*
927 * If shell archiving is enabled, use our special initialization function.
928 * Otherwise, load the library and call its _PG_archive_module_init().
929 */
930 if (XLogArchiveLibrary[0] == '\0')
932 else
935 "_PG_archive_module_init", false, NULL);
936
937 if (archive_init == NULL)
939 (errmsg("archive modules have to define the symbol %s", "_PG_archive_module_init")));
940
941 ArchiveCallbacks = (*archive_init) ();
942
945 (errmsg("archive modules must register an archive callback")));
946
950
952}
953
954/*
955 * Call the shutdown callback of the loaded archive module, if defined.
956 */
957static void
959{
962}
void pgaio_error_cleanup(void)
Definition aio.c:1165
const ArchiveModuleCallbacks *(* ArchiveModuleInit)(void)
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:219
static void pg_atomic_write_membarrier_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:315
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition atomics.h:330
void AuxiliaryProcessMainCommon(void)
Definition auxprocess.c:39
sigset_t UnBlockSig
Definition pqsignal.c:22
void binaryheap_build(binaryheap *heap)
Definition binaryheap.c:136
void binaryheap_reset(binaryheap *heap)
Definition binaryheap.c:61
bh_node_type binaryheap_first(binaryheap *heap)
Definition binaryheap.c:175
void binaryheap_add(binaryheap *heap, bh_node_type d)
Definition binaryheap.c:152
bh_node_type binaryheap_remove_first(binaryheap *heap)
Definition binaryheap.c:190
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
Definition binaryheap.c:114
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
Definition binaryheap.c:37
#define binaryheap_size(h)
Definition binaryheap.h:66
#define binaryheap_empty(h)
Definition binaryheap.h:65
#define SIGNAL_ARGS
Definition c.h:1363
#define Assert(condition)
Definition c.h:873
#define MemSet(start, val, len)
Definition c.h:1013
size_t Size
Definition c.h:619
bool ConditionVariableCancelSleep(void)
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition dfmgr.c:95
void AtEOXact_HashTables(bool isCommit)
Definition dynahash.c:1931
void EmitErrorReport(void)
Definition elog.c:1704
int errdetail_internal(const char *fmt,...)
Definition elog.c:1243
int errcode_for_file_access(void)
Definition elog.c:886
int errdetail(const char *fmt,...)
Definition elog.c:1216
ErrorContextCallback * error_context_stack
Definition elog.c:95
void FlushErrorState(void)
Definition elog.c:1884
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
sigjmp_buf * PG_exception_stack
Definition elog.c:97
#define LOG
Definition elog.h:31
#define WARNING
Definition elog.h:36
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
int FreeDir(DIR *dir)
Definition fd.c:3008
void AtEOXact_Files(bool isCommit)
Definition fd.c:3213
DIR * AllocateDir(const char *dirname)
Definition fd.c:2890
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition fd.c:2956
#define palloc_object(type)
Definition fe_memutils.h:74
#define palloc0_object(type)
Definition fe_memutils.h:75
volatile sig_atomic_t LogMemoryContextPending
Definition globals.c:41
volatile sig_atomic_t ProcSignalBarrierPending
Definition globals.c:40
ProcNumber MyProcNumber
Definition globals.c:90
struct Latch * MyLatch
Definition globals.c:63
void ProcessConfigFile(GucContext context)
Definition guc-file.l:120
@ PGC_SIGHUP
Definition guc.h:75
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition interrupt.c:104
volatile sig_atomic_t ShutdownRequestPending
Definition interrupt.c:28
volatile sig_atomic_t ConfigReloadPending
Definition interrupt.c:27
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition interrupt.c:61
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:372
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:344
void proc_exit(int code)
Definition ipc.c:105
int b
Definition isn.c:74
int a
Definition isn.c:73
int i
Definition isn.c:77
void SetLatch(Latch *latch)
Definition latch.c:290
void ResetLatch(Latch *latch)
Definition latch.c:374
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition latch.c:172
void LWLockReleaseAll(void)
Definition lwlock.c:1892
void MemoryContextReset(MemoryContext context)
Definition mcxt.c:403
char * pstrdup(const char *in)
Definition mcxt.c:1781
void pfree(void *pointer)
Definition mcxt.c:1616
MemoryContext TopMemoryContext
Definition mcxt.c:166
void ProcessLogMemoryContextInterrupt(void)
Definition mcxt.c:1340
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
#define RESUME_INTERRUPTS()
Definition miscadmin.h:136
#define HOLD_INTERRUPTS()
Definition miscadmin.h:134
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
void * arg
#define MAXPGPATH
static volatile sig_atomic_t time_to_stop
static bool pgarch_archiveXlog(char *xlog)
Definition pgarch.c:518
static void pgarch_die(int code, Datum arg)
Definition pgarch.c:848
#define PGARCH_RESTART_INTERVAL
Definition pgarch.c:63
bool PgArchCanRestart(void)
Definition pgarch.c:196
static bool pgarch_readyXlog(char *xlog)
Definition pgarch.c:646
static PgArchData * PgArch
Definition pgarch.c:102
char * arch_module_check_errdetail_string
Definition pgarch.c:94
static void pgarch_MainLoop(void)
Definition pgarch.c:311
#define NUM_ARCHIVE_RETRIES
Definition pgarch.c:69
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition pgarch.c:298
static volatile sig_atomic_t ready_to_stop
Definition pgarch.c:136
static struct arch_files_state * arch_files
Definition pgarch.c:131
char * XLogArchiveLibrary
Definition pgarch.c:93
Size PgArchShmemSize(void)
Definition pgarch.c:156
static void LoadArchiveLibrary(void)
Definition pgarch.c:914
static void pgarch_ArchiverCopyLoop(void)
Definition pgarch.c:382
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition pgarch.c:782
void PgArchiverMain(const void *startup_data, size_t startup_data_len)
Definition pgarch.c:219
#define NUM_FILES_PER_DIRECTORY_SCAN
Definition pgarch.c:80
void PgArchForceDirScan(void)
Definition pgarch.c:805
static void ProcessPgArchInterrupts(void)
Definition pgarch.c:862
static const ArchiveModuleCallbacks * ArchiveCallbacks
Definition pgarch.c:103
static ArchiveModuleState * archive_module_state
Definition pgarch.c:104
void PgArchShmemInit(void)
Definition pgarch.c:167
static void pgarch_call_module_shutdown_cb(int code, Datum arg)
Definition pgarch.c:956
void PgArchWakeup(void)
Definition pgarch.c:281
static void pgarch_archiveDone(char *xlog)
Definition pgarch.c:819
#define NUM_ORPHAN_CLEANUP_RETRIES
Definition pgarch.c:75
static MemoryContext archive_context
Definition pgarch.c:105
#define PGARCH_AUTOWAKE_INTERVAL
Definition pgarch.c:62
static time_t last_sigterm_time
Definition pgarch.c:101
#define MIN_XFN_CHARS
Definition pgarch.h:25
#define MAX_XFN_CHARS
Definition pgarch.h:26
#define VALID_XFN_CHARS
Definition pgarch.h:27
void pgstat_report_archiver(const char *xlog, bool failed)
#define PostmasterIsAlive()
Definition pmsignal.h:107
#define pqsignal
Definition port.h:547
#define snprintf
Definition port.h:260
static char * DatumGetCString(Datum X)
Definition postgres.h:365
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
static int fb(int x)
#define GetPGProcByNumber(n)
Definition proc.h:440
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
void ProcessProcSignalBarrier(void)
Definition procsignal.c:499
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition procsignal.c:677
static void set_ps_display(const char *activity)
Definition ps_status.h:40
void ReleaseAuxProcessResources(bool isCommit)
Definition resowner.c:1016
const ArchiveModuleCallbacks * shell_archive_init(void)
Size add_size(Size s1, Size s2)
Definition shmem.c:482
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:378
void pg_usleep(long microsec)
Definition signal.c:53
ArchiveFileCB archive_file_cb
ArchiveShutdownCB shutdown_cb
ArchiveCheckConfiguredCB check_configured_cb
ArchiveStartupCB startup_cb
Definition dirent.c:26
int pgprocno
Definition pgarch.c:85
pg_atomic_uint32 force_dir_scan
Definition pgarch.c:90
char arch_filenames[NUM_FILES_PER_DIRECTORY_SCAN][MAX_XFN_CHARS+1]
Definition pgarch.c:128
int arch_files_size
Definition pgarch.c:125
char * arch_files[NUM_FILES_PER_DIRECTORY_SCAN]
Definition pgarch.c:126
binaryheap * arch_heap
Definition pgarch.c:124
void disable_all_timeouts(bool keep_indicators)
Definition timeout.c:751
static void pgstat_report_wait_end(void)
Definition wait_event.h:85
#define WL_TIMEOUT
#define WL_LATCH_SET
#define WL_POSTMASTER_DEATH
#define SIGCHLD
Definition win32_port.h:168
#define SIGHUP
Definition win32_port.h:158
#define stat
Definition win32_port.h:74
#define SIGPIPE
Definition win32_port.h:163
#define SIGUSR1
Definition win32_port.h:170
#define SIGALRM
Definition win32_port.h:164
#define SIGUSR2
Definition win32_port.h:171
char * XLogArchiveCommand
Definition xlog.c:123
#define XLogArchivingActive()
Definition xlog.h:101
static bool IsTLHistoryFileName(const char *fname)
#define MAXFNAMELEN
#define XLOGDIR
static void StatusFilePath(char *path, const char *xlog, const char *suffix)