PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 (char *startup_data, size_t startup_data_len) 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 195 of file pgarch.c.

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

References PGARCH_RESTART_INTERVAL.

Referenced by LaunchMissingBackgroundProcesses().

◆ PgArchForceDirScan()

void PgArchForceDirScan ( void  )

Definition at line 800 of file pgarch.c.

803 {

References PgArchData::force_dir_scan, pg_atomic_write_membarrier_u32(), and PgArch.

Referenced by XLogArchiveNotify().

◆ PgArchiverMain()

void PgArchiverMain ( char *  startup_data,
size_t  startup_data_len 
)

Definition at line 215 of file pgarch.c.

218 {
219  Assert(startup_data_len == 0);
220 
223 
224  /*
225  * Ignore all signals usually bound to some action in the postmaster,
226  * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
227  */
229  pqsignal(SIGINT, SIG_IGN);
231  /* SIGQUIT handler was already set up by InitPostmasterChild */
236 
237  /* Reset some signals that are accepted by postmaster but not here */
239 
240  /* Unblock signals (they were blocked when the postmaster forked us) */
241  sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
242 
243  /* We shouldn't be launched unnecessarily. */
245 
246  /* Arrange to clean up at archiver exit */
248 
249  /*
250  * Advertise our proc number so that backends can use our latch to wake us
251  * up while we're sleeping.
252  */
254 
255  /* Create workspace for pgarch_readyXlog() */
256  arch_files = palloc(sizeof(struct arch_files_state));
258 
259  /* Initialize our max-heap for prioritizing files to archive. */
261  ready_file_comparator, NULL);
262 
263  /* Initialize our memory context. */
265  "archiver",
267 
268  /* Load the archive_library. */
270 
271  pgarch_MainLoop();
272 
void AuxiliaryProcessMainCommon(void)
Definition: auxprocess.c:39
sigset_t UnBlockSig
Definition: pqsignal.c:22
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
Definition: binaryheap.c:39
#define Assert(condition)
Definition: c.h:863
ProcNumber MyProcNumber
Definition: globals.c:89
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
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void * palloc(Size size)
Definition: mcxt.c:1317
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
@ B_ARCHIVER
Definition: miscadmin.h:353
BackendType MyBackendType
Definition: miscinit.c:64
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:843
static PgArchData * PgArch
Definition: pgarch.c:101
static void pgarch_MainLoop(void)
Definition: pgarch.c:308
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:295
static struct arch_files_state * arch_files
Definition: pgarch.c:130
static void LoadArchiveLibrary(void)
Definition: pgarch.c:909
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition: pgarch.c:777
#define NUM_FILES_PER_DIRECTORY_SCAN
Definition: pgarch.c:79
static MemoryContext archive_context
Definition: pgarch.c:104
pqsigfunc pqsignal(int signo, pqsigfunc func)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:671
int pgprocno
Definition: pgarch.c:84
int arch_files_size
Definition: pgarch.c:124
binaryheap * arch_heap
Definition: pgarch.c:123
#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:99

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, arch_files, arch_files_state::arch_files_size, arch_files_state::arch_heap, archive_context, Assert, AuxiliaryProcessMainCommon(), B_ARCHIVER, binaryheap_allocate(), LoadArchiveLibrary(), MyBackendType, 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, TopMemoryContext, UnBlockSig, and XLogArchivingActive.

◆ PgArchShmemInit()

void PgArchShmemInit ( void  )

Definition at line 166 of file pgarch.c.

169 {
170  bool found;
171 
172  PgArch = (PgArchData *)
173  ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
174 
175  if (!found)
176  {
177  /* First time through, so initialize */
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:221
#define MemSet(start, val, len)
Definition: c.h:1025
Size PgArchShmemSize(void)
Definition: pgarch.c:155
#define INVALID_PROC_NUMBER
Definition: procnumber.h:26
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387
pg_atomic_uint32 force_dir_scan
Definition: pgarch.c:89

References PgArchData::force_dir_scan, INVALID_PROC_NUMBER, MemSet, pg_atomic_init_u32(), PgArch, PgArchShmemSize(), PgArchData::pgprocno, and ShmemInitStruct().

Referenced by CreateOrAttachShmemStructs().

◆ PgArchShmemSize()

Size PgArchShmemSize ( void  )

Definition at line 155 of file pgarch.c.

158 {
159  Size size = 0;
160 
161  size = add_size(size, sizeof(PgArchData));
162 
size_t Size
Definition: c.h:610
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
static pg_noinline void Size size
Definition: slab.c:607

References add_size(), and size.

Referenced by CalculateShmemSize(), and PgArchShmemInit().

◆ PgArchWakeup()

void PgArchWakeup ( void  )

Definition at line 278 of file pgarch.c.

281 {
282  int arch_pgprocno = PgArch->pgprocno;
283 
284  /*
285  * We don't acquire ProcArrayLock here. It's actually fine because
286  * procLatch isn't ever freed, so we just can potentially set the wrong
287  * process' (or no process') latch. Even in that case the archiver will
288  * be relaunched shortly and will start archiving.
289  */
290  if (arch_pgprocno != INVALID_PROC_NUMBER)

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

Referenced by XLogArchiveNotify().