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)
 

Macro Definition Documentation

◆ MAX_XFN_CHARS

#define MAX_XFN_CHARS   40

Definition at line 26 of file pgarch.h.

Referenced by pgarch_ArchiverCopyLoop(), and pgarch_readyXlog().

◆ MIN_XFN_CHARS

#define MIN_XFN_CHARS   16

Definition at line 25 of file pgarch.h.

Referenced by pgarch_readyXlog().

◆ VALID_XFN_CHARS

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

Definition at line 27 of file pgarch.h.

Referenced by pgarch_readyXlog().

Function Documentation

◆ PgArchCanRestart()

bool PgArchCanRestart ( void  )

Definition at line 148 of file pgarch.c.

References PGARCH_RESTART_INTERVAL.

149 {
150  static time_t last_pgarch_start_time = 0;
151  time_t curtime = time(NULL);
152 
153  /*
154  * Return false and don't restart archiver if too soon since last archiver
155  * start.
156  */
157  if ((unsigned int) (curtime - last_pgarch_start_time) <
158  (unsigned int) PGARCH_RESTART_INTERVAL)
159  return false;
160 
161  last_pgarch_start_time = curtime;
162  return true;
163 }
#define PGARCH_RESTART_INTERVAL
Definition: pgarch.c:60

◆ PgArchiverMain()

void PgArchiverMain ( void  )

Definition at line 168 of file pgarch.c.

References Assert, MyProc, on_shmem_exit(), PG_SETMASK, pgarch_die(), pgarch_MainLoop(), pgarch_waken_stop(), PgArchData::pgprocno, PGPROC::pgprocno, pqsignal(), proc_exit(), procsignal_sigusr1_handler(), SIG_DFL, SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, UnBlockSig, and XLogArchivingActive.

Referenced by AuxiliaryProcessMain().

169 {
170  /*
171  * Ignore all signals usually bound to some action in the postmaster,
172  * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
173  */
175  pqsignal(SIGINT, SIG_IGN);
177  /* SIGQUIT handler was already set up by InitPostmasterChild */
182 
183  /* Reset some signals that are accepted by postmaster but not here */
185 
186  /* Unblock signals (they were blocked when the postmaster forked us) */
188 
189  /* We shouldn't be launched unnecessarily. */
191 
192  /* Arrange to clean up at archiver exit */
194 
195  /*
196  * Advertise our pgprocno so that backends can use our latch to wake us up
197  * while we're sleeping.
198  */
200 
201  pgarch_MainLoop();
202 
203  proc_exit(0);
204 }
static PgArchData * PgArch
Definition: pgarch.c:87
#define SIGUSR1
Definition: win32_port.h:179
#define SIGCHLD
Definition: win32_port.h:177
PGPROC * MyProc
Definition: proc.c:68
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:56
void proc_exit(int code)
Definition: ipc.c:104
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:227
#define SIGPIPE
Definition: win32_port.h:172
#define SIGUSR2
Definition: win32_port.h:180
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:695
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define SIGHUP
Definition: win32_port.h:167
sigset_t UnBlockSig
Definition: pqsignal.c:22
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:104
#define SIG_IGN
Definition: win32_port.h:164
static void pgarch_MainLoop(void)
Definition: pgarch.c:244
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
#define SIG_DFL
Definition: win32_port.h:162
#define Assert(condition)
Definition: c.h:804
#define XLogArchivingActive()
Definition: xlog.h:155
#define SIGALRM
Definition: win32_port.h:173
int pgprocno
Definition: pgarch.c:78
int pgprocno
Definition: proc.h:150
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:642

◆ PgArchShmemInit()

void PgArchShmemInit ( void  )

Definition at line 120 of file pgarch.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

121 {
122  bool found;
123 
124  PgArch = (PgArchData *)
125  ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
126 
127  if (!found)
128  {
129  /* First time through, so initialize */
132  }
133 }
Size PgArchShmemSize(void)
Definition: pgarch.c:109
static PgArchData * PgArch
Definition: pgarch.c:87
#define MemSet(start, val, len)
Definition: c.h:1008
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
#define INVALID_PGPROCNO
Definition: proc.h:80
int pgprocno
Definition: pgarch.c:78

◆ PgArchShmemSize()

Size PgArchShmemSize ( void  )

Definition at line 109 of file pgarch.c.

References add_size().

Referenced by CalculateShmemSize(), and PgArchShmemInit().

110 {
111  Size size = 0;
112 
113  size = add_size(size, sizeof(PgArchData));
114 
115  return size;
116 }
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:540

◆ PgArchWakeup()

void PgArchWakeup ( void  )

Definition at line 210 of file pgarch.c.

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

Referenced by XLogArchiveNotify().

211 {
212  int arch_pgprocno = PgArch->pgprocno;
213 
214  /*
215  * We don't acquire ProcArrayLock here. It's actually fine because
216  * procLatch isn't ever freed, so we just can potentially set the wrong
217  * process' (or no process') latch. Even in that case the archiver will
218  * be relaunched shortly and will start archiving.
219  */
220  if (arch_pgprocno != INVALID_PGPROCNO)
221  SetLatch(&ProcGlobal->allProcs[arch_pgprocno].procLatch);
222 }
static PgArchData * PgArch
Definition: pgarch.c:87
PROC_HDR * ProcGlobal
Definition: proc.c:80
void SetLatch(Latch *latch)
Definition: latch.c:567
Latch procLatch
Definition: proc.h:130
#define INVALID_PGPROCNO
Definition: proc.h:80
int pgprocno
Definition: pgarch.c:78
PGPROC * allProcs
Definition: proc.h:318