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
 

Macros

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

Typedefs

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)
 

Functions

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

Variables

PGDLLIMPORT char * XLogArchiveLibrary
 

Macro Definition Documentation

◆ MAX_XFN_CHARS

#define MAX_XFN_CHARS   40

Definition at line 26 of file pgarch.h.

◆ MIN_XFN_CHARS

#define MIN_XFN_CHARS   16

Definition at line 25 of file pgarch.h.

◆ VALID_XFN_CHARS

#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

◆ 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);
195 
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;
203 
204  last_pgarch_start_time = curtime;
#define PGARCH_RESTART_INTERVAL
Definition: pgarch.c:57

References PGARCH_RESTART_INTERVAL.

◆ PgArchForceDirScan()

void PgArchForceDirScan ( void  )

Definition at line 723 of file pgarch.c.

726 {
728  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 */
225 
226  /* Reset some signals that are accepted by postmaster but not here */
228 
229  /* Unblock signals (they were blocked when the postmaster forked us) */
231 
232  /* We shouldn't be launched unnecessarily. */
234 
235  /* Arrange to clean up at archiver exit */
237 
238  /*
239  * Advertise our pgprocno so that backends can use our latch to wake us up
240  * while we're sleeping.
241  */
243 
244  /* Create workspace for pgarch_readyXlog() */
245  arch_files = palloc(sizeof(struct arch_files_state));
247 
248  /* Initialize our max-heap for prioritizing files to archive. */
250  ready_file_comparator, NULL);
251 
252  /* Load the archive_library. */
254 
256  {
257  pgarch_MainLoop();
258  }
260 
262 
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:108
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:61
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
Definition: ipc.h:47
#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
Definition: ipc.h:52
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc(Size size)
Definition: mcxt.c:1068
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:756
static void pgarch_MainLoop(void)
Definition: pgarch.c:302
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:285
static struct arch_files_state * arch_files
Definition: pgarch.c:124
static void LoadArchiveLibrary(void)
Definition: pgarch.c:821
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition: pgarch.c:700
#define NUM_FILES_PER_DIRECTORY_SCAN
Definition: pgarch.c:74
static void call_archive_module_shutdown_callback(int code, Datum arg)
Definition: pgarch.c:855
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:638
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:180
PGPROC * MyProc
Definition: proc.c:68
int pgprocno
Definition: proc.h:188
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:177
#define SIGHUP
Definition: win32_port.h:167
#define SIG_DFL
Definition: win32_port.h:162
#define SIGPIPE
Definition: win32_port.h:172
#define SIGUSR1
Definition: win32_port.h:179
#define SIGALRM
Definition: win32_port.h:173
#define SIGUSR2
Definition: win32_port.h:180
#define SIG_IGN
Definition: win32_port.h:164
#define XLogArchivingActive()
Definition: xlog.h:94

References arch_files, arch_files_state::arch_files_size, arch_files_state::arch_heap, Assert(), binaryheap_allocate(), call_archive_module_shutdown_callback(), LoadArchiveLibrary(), MyProc, NUM_FILES_PER_DIRECTORY_SCAN, on_shmem_exit(), palloc(), PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, 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;
165 
166  PgArch = (PgArchData *)
167  ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
168 
169  if (!found)
170  {
171  /* First time through, so initialize */
#define MemSet(start, val, len)
Definition: c.h:1008
Size PgArchShmemSize(void)
Definition: pgarch.c:149
#define INVALID_PGPROCNO
Definition: proc.h:83
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;
154 
155  size = add_size(size, sizeof(PgArchData));
156 
size_t Size
Definition: c.h:540
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 268 of file pgarch.c.

271 {
272  int arch_pgprocno = PgArch->pgprocno;
273 
274  /*
275  * We don't acquire ProcArrayLock here. It's actually fine because
276  * procLatch isn't ever freed, so we just can potentially set the wrong
277  * process' (or no process') latch. Even in that case the archiver will
278  * be relaunched shortly and will start archiving.
279  */
280  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 28 of file shell_archive.c.

29 {
31 
34 }
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:963
void(* ArchiveModuleInit)(ArchiveModuleCallbacks *cb)
Definition: pgarch.h:64
static bool shell_archive_file(const char *file, const char *path)
Definition: shell_archive.c:43
static bool shell_archive_configured(void)
Definition: shell_archive.c:37
void shell_archive_init(ArchiveModuleCallbacks *cb)
Definition: shell_archive.c:28
ArchiveFileCB archive_file_cb
Definition: pgarch.h:56
ArchiveCheckConfiguredCB check_configured_cb
Definition: pgarch.h:55

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

Referenced by LoadArchiveLibrary().

Variable Documentation

◆ XLogArchiveLibrary

PGDLLIMPORT char* XLogArchiveLibrary
extern

Definition at line 89 of file pgarch.c.

Referenced by HandlePgArchInterrupts(), and LoadArchiveLibrary().