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

References PGARCH_RESTART_INTERVAL.

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

◆ PgArchiverMain()

void PgArchiverMain ( void  )

Definition at line 167 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().

168 {
169  /*
170  * Ignore all signals usually bound to some action in the postmaster,
171  * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
172  */
174  pqsignal(SIGINT, SIG_IGN);
176  /* SIGQUIT handler was already set up by InitPostmasterChild */
181 
182  /* Reset some signals that are accepted by postmaster but not here */
184 
185  /* Unblock signals (they were blocked when the postmaster forked us) */
187 
188  /* We shouldn't be launched unnecessarily. */
190 
191  /* Arrange to clean up at archiver exit */
193 
194  /*
195  * Advertise our pgprocno so that backends can use our latch to wake us up
196  * while we're sleeping.
197  */
199 
200  pgarch_MainLoop();
201 
202  proc_exit(0);
203 }
static PgArchData * PgArch
Definition: pgarch.c:87
#define SIGUSR1
Definition: win32_port.h:171
#define SIGCHLD
Definition: win32_port.h:169
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:226
#define SIGPIPE
Definition: win32_port.h:164
#define SIGUSR2
Definition: win32_port.h:172
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:702
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define SIGHUP
Definition: win32_port.h:159
sigset_t UnBlockSig
Definition: pqsignal.c:22
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:104
#define SIG_IGN
Definition: win32_port.h:156
static void pgarch_MainLoop(void)
Definition: pgarch.c:243
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
#define SIG_DFL
Definition: win32_port.h:154
#define Assert(condition)
Definition: c.h:804
#define XLogArchivingActive()
Definition: xlog.h:190
#define SIGALRM
Definition: win32_port.h:165
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 119 of file pgarch.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

120 {
121  bool found;
122 
123  PgArch = (PgArchData *)
124  ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
125 
126  if (!found)
127  {
128  /* First time through, so initialize */
131  }
132 }
Size PgArchShmemSize(void)
Definition: pgarch.c:108
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 108 of file pgarch.c.

References add_size().

Referenced by CreateSharedMemoryAndSemaphores(), and PgArchShmemInit().

109 {
110  Size size = 0;
111 
112  size = add_size(size, sizeof(PgArchData));
113 
114  return size;
115 }
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 209 of file pgarch.c.

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

Referenced by XLogArchiveNotify().

210 {
211  int arch_pgprocno = PgArch->pgprocno;
212 
213  /*
214  * We don't acquire ProcArrayLock here. It's actually fine because
215  * procLatch isn't ever freed, so we just can potentially set the wrong
216  * process' (or no process') latch. Even in that case the archiver will
217  * be relaunched shortly and will start archiving.
218  */
219  if (arch_pgprocno != INVALID_PGPROCNO)
220  SetLatch(&ProcGlobal->allProcs[arch_pgprocno].procLatch);
221 }
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