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.

Macros

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

Functions

Size PgArchShmemSize (void)
 
void PgArchShmemInit (void)
 
bool PgArchCanRestart (void)
 
void PgArchiverMain (void) pg_attribute_noreturn()
 
void PgArchWakeup (void)
 
void PgArchForceDirScan (void)
 

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.

Function Documentation

◆ PgArchCanRestart()

bool PgArchCanRestart ( void  )

Definition at line 192 of file pgarch.c.

195 {
196  static time_t last_pgarch_start_time = 0;
197  time_t curtime = time(NULL);
198 
199  /*
200  * Return false and don't restart archiver if too soon since last archiver
201  * start.
202  */
203  if ((unsigned int) (curtime - last_pgarch_start_time) <
204  (unsigned int) PGARCH_RESTART_INTERVAL)
205  return false;
206 
207  last_pgarch_start_time = curtime;
#define PGARCH_RESTART_INTERVAL
Definition: pgarch.c:59

References PGARCH_RESTART_INTERVAL.

◆ PgArchForceDirScan()

void PgArchForceDirScan ( void  )

Definition at line 710 of file pgarch.c.

713 {
715  PgArch->force_dir_scan = true;
static PgArchData * PgArch
Definition: pgarch.c:99
#define SpinLockAcquire(lock)
Definition: spin.h:62
bool force_dir_scan
Definition: pgarch.c:86
slock_t arch_lck
Definition: pgarch.c:88

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

Referenced by XLogArchiveNotify().

◆ PgArchiverMain()

void PgArchiverMain ( void  )

Definition at line 212 of file pgarch.c.

215 {
216  /*
217  * Ignore all signals usually bound to some action in the postmaster,
218  * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
219  */
221  pqsignal(SIGINT, SIG_IGN);
223  /* SIGQUIT handler was already set up by InitPostmasterChild */
228 
229  /* Reset some signals that are accepted by postmaster but not here */
231 
232  /* Unblock signals (they were blocked when the postmaster forked us) */
233  sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
234 
235  /* We shouldn't be launched unnecessarily. */
237 
238  /* Arrange to clean up at archiver exit */
240 
241  /*
242  * Advertise our pgprocno so that backends can use our latch to wake us up
243  * while we're sleeping.
244  */
246 
247  /* Create workspace for pgarch_readyXlog() */
248  arch_files = palloc(sizeof(struct arch_files_state));
250 
251  /* Initialize our max-heap for prioritizing files to archive. */
253  ready_file_comparator, NULL);
254 
255  /* Load the archive_library. */
257 
258  pgarch_MainLoop();
259 
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:1226
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:755
static void pgarch_MainLoop(void)
Definition: pgarch.c:299
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:282
static struct arch_files_state * arch_files
Definition: pgarch.c:127
static void LoadArchiveLibrary(void)
Definition: pgarch.c:821
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition: pgarch.c:687
#define NUM_FILES_PER_DIRECTORY_SCAN
Definition: pgarch.c:76
pqsigfunc pqsignal(int signo, pqsigfunc func)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:639
PGPROC * MyProc
Definition: proc.c:66
int pgprocno
Definition: proc.h:191
int pgprocno
Definition: pgarch.c:81
int arch_files_size
Definition: pgarch.c:121
binaryheap * arch_heap
Definition: pgarch.c:120
#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(), 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 163 of file pgarch.c.

166 {
167  bool found;
168 
169  PgArch = (PgArchData *)
170  ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
171 
172  if (!found)
173  {
174  /* First time through, so initialize */
#define MemSet(start, val, len)
Definition: c.h:1004
Size PgArchShmemSize(void)
Definition: pgarch.c:152
#define INVALID_PGPROCNO
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 152 of file pgarch.c.

155 {
156  Size size = 0;
157 
158  size = add_size(size, sizeof(PgArchData));
159 
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 265 of file pgarch.c.

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

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

Referenced by XLogArchiveNotify().