PostgreSQL Source Code  git master
pgarch.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ArchiveModuleCallbacks


#define MIN_XFN_CHARS   16
#define MAX_XFN_CHARS   40
#define VALID_XFN_CHARS   "0123456789ABCDEF.history.backup.partial"


typedef bool(* ArchiveCheckConfiguredCB) (void)
typedef bool(* ArchiveFileCB) (const char *file, const char *path)
typedef void(* ArchiveShutdownCB) (void)
typedef struct ArchiveModuleCallbacks ArchiveModuleCallbacks
typedef void(* ArchiveModuleInit) (ArchiveModuleCallbacks *cb)


Size PgArchShmemSize (void)
void PgArchShmemInit (void)
bool PgArchCanRestart (void)
void PgArchiverMain (void) pg_attribute_noreturn()
void PgArchWakeup (void)
void PgArchForceDirScan (void)
PGDLLEXPORT void _PG_archive_module_init (ArchiveModuleCallbacks *cb)
void shell_archive_init (ArchiveModuleCallbacks *cb)


PGDLLIMPORT char * XLogArchiveLibrary

Macro Definition Documentation


#define MAX_XFN_CHARS   40

Definition at line 26 of file pgarch.h.


#define MIN_XFN_CHARS   16

Definition at line 25 of file pgarch.h.


#define VALID_XFN_CHARS   "0123456789ABCDEF.history.backup.partial"

Definition at line 27 of file pgarch.h.

Typedef Documentation

◆ ArchiveCheckConfiguredCB

typedef bool(* ArchiveCheckConfiguredCB) (void)

Definition at line 49 of file pgarch.h.

◆ ArchiveFileCB

typedef bool(* ArchiveFileCB) (const char *file, const char *path)

Definition at line 50 of file pgarch.h.

◆ ArchiveModuleCallbacks

◆ ArchiveModuleInit

typedef void(* ArchiveModuleInit) (ArchiveModuleCallbacks *cb)

Definition at line 64 of file pgarch.h.

◆ ArchiveShutdownCB

typedef void(* ArchiveShutdownCB) (void)

Definition at line 51 of file pgarch.h.

Function Documentation

◆ _PG_archive_module_init()

PGDLLEXPORT void _PG_archive_module_init ( ArchiveModuleCallbacks cb)

Definition at line 82 of file basic_archive.c.

83 {
88 }
void _PG_archive_module_init(ArchiveModuleCallbacks *cb)
Definition: basic_archive.c:82
static bool basic_archive_file(const char *file, const char *path)
static bool basic_archive_configured(void)
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:965
void(* ArchiveModuleInit)(ArchiveModuleCallbacks *cb)
Definition: pgarch.h:64
ArchiveFileCB archive_file_cb
Definition: pgarch.h:56
ArchiveCheckConfiguredCB check_configured_cb
Definition: pgarch.h:55

References ArchiveModuleCallbacks::archive_file_cb, AssertVariableIsOfType, basic_archive_configured(), basic_archive_file(), and ArchiveModuleCallbacks::check_configured_cb.

◆ PgArchCanRestart()

bool PgArchCanRestart ( void  )

Definition at line 189 of file pgarch.c.

192 {
193  static time_t last_pgarch_start_time = 0;
194  time_t curtime = time(NULL);
196  /*
197  * Return false and don't restart archiver if too soon since last archiver
198  * start.
199  */
200  if ((unsigned int) (curtime - last_pgarch_start_time) <
201  (unsigned int) PGARCH_RESTART_INTERVAL)
202  return false;
204  last_pgarch_start_time = curtime;
Definition: pgarch.c:57


◆ PgArchForceDirScan()

void PgArchForceDirScan ( void  )

Definition at line 717 of file pgarch.c.

720 {
722  PgArch->force_dir_scan = true;
static PgArchData * PgArch
Definition: pgarch.c:97
#define SpinLockAcquire(lock)
Definition: spin.h:62
bool force_dir_scan
Definition: pgarch.c:84
slock_t arch_lck
Definition: pgarch.c:86

References PgArchData::arch_lck, PgArchData::force_dir_scan, PgArch, SpinLockAcquire, and SpinLockRelease.

Referenced by XLogArchiveNotify().

◆ PgArchiverMain()

void PgArchiverMain ( void  )

Definition at line 209 of file pgarch.c.

212 {
213  /*
214  * Ignore all signals usually bound to some action in the postmaster,
215  * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
216  */
218  pqsignal(SIGINT, SIG_IGN);
220  /* SIGQUIT handler was already set up by InitPostmasterChild */
226  /* Reset some signals that are accepted by postmaster but not here */
229  /* Unblock signals (they were blocked when the postmaster forked us) */
232  /* We shouldn't be launched unnecessarily. */
235  /* Arrange to clean up at archiver exit */
238  /*
239  * Advertise our pgprocno so that backends can use our latch to wake us up
240  * while we're sleeping.
241  */
244  /* Create workspace for pgarch_readyXlog() */
245  arch_files = palloc(sizeof(struct arch_files_state));
248  /* Initialize our max-heap for prioritizing files to archive. */
250  ready_file_comparator, NULL);
252  /* Load the archive_library. */
255  pgarch_MainLoop();
sigset_t UnBlockSig
Definition: pqsignal.c:22
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
Definition: binaryheap.c:32
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:109
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:61
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc(Size size)
Definition: mcxt.c:1210
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:762
static void pgarch_MainLoop(void)
Definition: pgarch.c:296
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:279
static struct arch_files_state * arch_files
Definition: pgarch.c:124
static void LoadArchiveLibrary(void)
Definition: pgarch.c:828
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition: pgarch.c:694
Definition: pgarch.c:74
pqsigfunc pqsignal(int signo, pqsigfunc func)
#define PG_SETMASK(mask)
Definition: pqsignal.h:18
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:639
Definition: proc.c:66
int pgprocno
Definition: proc.h:191
int pgprocno
Definition: pgarch.c:79
int arch_files_size
Definition: pgarch.c:118
binaryheap * arch_heap
Definition: pgarch.c:117
#define SIGCHLD
Definition: win32_port.h:186
#define SIGHUP
Definition: win32_port.h:176
#define SIG_DFL
Definition: win32_port.h:171
#define SIGPIPE
Definition: win32_port.h:181
#define SIGUSR1
Definition: win32_port.h:188
#define SIGALRM
Definition: win32_port.h:182
#define SIGUSR2
Definition: win32_port.h:189
#define SIG_IGN
Definition: win32_port.h:173
#define XLogArchivingActive()
Definition: xlog.h:94

References arch_files, arch_files_state::arch_files_size, arch_files_state::arch_heap, Assert(), binaryheap_allocate(), LoadArchiveLibrary(), MyProc, NUM_FILES_PER_DIRECTORY_SCAN, on_shmem_exit(), palloc(), PG_SETMASK, PgArch, pgarch_die(), pgarch_MainLoop(), pgarch_waken_stop(), PgArchData::pgprocno, PGPROC::pgprocno, pqsignal(), proc_exit(), procsignal_sigusr1_handler(), ready_file_comparator(), SIG_DFL, SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, UnBlockSig, and XLogArchivingActive.

Referenced by AuxiliaryProcessMain().

◆ PgArchShmemInit()

void PgArchShmemInit ( void  )

Definition at line 160 of file pgarch.c.

163 {
164  bool found;
166  PgArch = (PgArchData *)
167  ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
169  if (!found)
170  {
171  /* First time through, so initialize */
#define MemSet(start, val, len)
Definition: c.h:1004
Size PgArchShmemSize(void)
Definition: pgarch.c:149
Definition: proc.h:85
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
#define SpinLockInit(lock)
Definition: spin.h:60

References PgArchData::arch_lck, INVALID_PGPROCNO, MemSet, PgArch, PgArchShmemSize(), PgArchData::pgprocno, ShmemInitStruct(), and SpinLockInit.

Referenced by CreateSharedMemoryAndSemaphores().

◆ PgArchShmemSize()

Size PgArchShmemSize ( void  )

Definition at line 149 of file pgarch.c.

152 {
153  Size size = 0;
155  size = add_size(size, sizeof(PgArchData));
size_t Size
Definition: c.h:589
Size add_size(Size s1, Size s2)
Definition: shmem.c:502

References add_size().

Referenced by CalculateShmemSize(), and PgArchShmemInit().

◆ PgArchWakeup()

void PgArchWakeup ( void  )

Definition at line 262 of file pgarch.c.

265 {
266  int arch_pgprocno = PgArch->pgprocno;
268  /*
269  * We don't acquire ProcArrayLock here. It's actually fine because
270  * procLatch isn't ever freed, so we just can potentially set the wrong
271  * process' (or no process') latch. Even in that case the archiver will
272  * be relaunched shortly and will start archiving.
273  */
274  if (arch_pgprocno != INVALID_PGPROCNO)

References PROC_HDR::allProcs, INVALID_PGPROCNO, PgArch, PgArchData::pgprocno, ProcGlobal, PGPROC::procLatch, and SetLatch().

Referenced by XLogArchiveNotify().

◆ shell_archive_init()

void shell_archive_init ( ArchiveModuleCallbacks cb)

Definition at line 30 of file shell_archive.c.

31 {
37 }
static void shell_archive_shutdown(void)
static bool shell_archive_file(const char *file, const char *path)
Definition: shell_archive.c:46
static bool shell_archive_configured(void)
Definition: shell_archive.c:40
void shell_archive_init(ArchiveModuleCallbacks *cb)
Definition: shell_archive.c:30
ArchiveShutdownCB shutdown_cb
Definition: pgarch.h:57

References ArchiveModuleCallbacks::archive_file_cb, AssertVariableIsOfType, ArchiveModuleCallbacks::check_configured_cb, shell_archive_configured(), shell_archive_file(), shell_archive_shutdown(), and ArchiveModuleCallbacks::shutdown_cb.

Referenced by LoadArchiveLibrary().

Variable Documentation

◆ XLogArchiveLibrary

PGDLLIMPORT char* XLogArchiveLibrary

Definition at line 89 of file pgarch.c.

Referenced by HandlePgArchInterrupts(), and LoadArchiveLibrary().