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 706 of file pgarch.c.

709 {
711  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:39
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:105
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:61
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc(Size size)
Definition: mcxt.c:1201
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:751
static void pgarch_MainLoop(void)
Definition: pgarch.c:295
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:817
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition: pgarch.c:683
#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
int MyProcNumber
Definition: proc.c:69
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:178
#define SIGHUP
Definition: win32_port.h:168
#define SIG_DFL
Definition: win32_port.h:163
#define SIGPIPE
Definition: win32_port.h:173
#define SIGUSR1
Definition: win32_port.h:180
#define SIGALRM
Definition: win32_port.h:174
#define SIGUSR2
Definition: win32_port.h:181
#define SIG_IGN
Definition: win32_port.h:165
#define XLogArchivingActive()
Definition: xlog.h:97

References arch_files, arch_files_state::arch_files_size, arch_files_state::arch_heap, Assert(), binaryheap_allocate(), LoadArchiveLibrary(), MyProcNumber, NUM_FILES_PER_DIRECTORY_SCAN, on_shmem_exit(), palloc(), PgArch, pgarch_die(), pgarch_MainLoop(), pgarch_waken_stop(), PgArchData::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:1009
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:388
#define SpinLockInit(lock)
Definition: spin.h:60

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

Referenced by CreateOrAttachShmemStructs().

◆ 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:594
Size add_size(Size s1, Size s2)
Definition: shmem.c:494

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().