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)
 
pg_noreturn void PgArchiverMain (const void *startup_data, size_t startup_data_len)
 
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 196 of file pgarch.c.

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

References PGARCH_RESTART_INTERVAL.

Referenced by LaunchMissingBackgroundProcesses().

◆ PgArchForceDirScan()

void PgArchForceDirScan ( void  )

Definition at line 802 of file pgarch.c.

805{

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

Referenced by XLogArchiveNotify().

◆ PgArchiverMain()

pg_noreturn void PgArchiverMain ( const void *  startup_data,
size_t  startup_data_len 
)

Definition at line 216 of file pgarch.c.

219{
220 Assert(startup_data_len == 0);
221
224
225 /*
226 * Ignore all signals usually bound to some action in the postmaster,
227 * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
228 */
230 pqsignal(SIGINT, SIG_IGN);
232 /* SIGQUIT handler was already set up by InitPostmasterChild */
233 pqsignal(SIGALRM, SIG_IGN);
234 pqsignal(SIGPIPE, SIG_IGN);
237
238 /* Reset some signals that are accepted by postmaster but not here */
239 pqsignal(SIGCHLD, SIG_DFL);
240
241 /* Unblock signals (they were blocked when the postmaster forked us) */
242 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
243
244 /* We shouldn't be launched unnecessarily. */
246
247 /* Arrange to clean up at archiver exit */
249
250 /*
251 * Advertise our proc number so that backends can use our latch to wake us
252 * up while we're sleeping.
253 */
255
256 /* Create workspace for pgarch_readyXlog() */
257 arch_files = palloc(sizeof(struct arch_files_state));
259
260 /* Initialize our max-heap for prioritizing files to archive. */
263
264 /* Initialize our memory context. */
266 "archiver",
268
269 /* Load the archive_library. */
271
273
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
ProcNumber MyProcNumber
Definition: globals.c:91
Assert(PointerIsAligned(start, uint64))
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:109
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:65
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
MemoryContext TopMemoryContext
Definition: mcxt.c:165
void * palloc(Size size)
Definition: mcxt.c:1943
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
@ B_ARCHIVER
Definition: miscadmin.h:361
BackendType MyBackendType
Definition: miscinit.c:64
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:845
static PgArchData * PgArch
Definition: pgarch.c:102
static void pgarch_MainLoop(void)
Definition: pgarch.c:309
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:296
static struct arch_files_state * arch_files
Definition: pgarch.c:131
static void LoadArchiveLibrary(void)
Definition: pgarch.c:915
static int ready_file_comparator(Datum a, Datum b, void *arg)
Definition: pgarch.c:779
#define NUM_FILES_PER_DIRECTORY_SCAN
Definition: pgarch.c:80
static MemoryContext archive_context
Definition: pgarch.c:105
#define pqsignal
Definition: port.h:531
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:673
int pgprocno
Definition: pgarch.c:85
int arch_files_size
Definition: pgarch.c:125
binaryheap * arch_heap
Definition: pgarch.c:124
#define SIGCHLD
Definition: win32_port.h:168
#define SIGHUP
Definition: win32_port.h:158
#define SIGPIPE
Definition: win32_port.h:163
#define SIGUSR1
Definition: win32_port.h:170
#define SIGALRM
Definition: win32_port.h:164
#define SIGUSR2
Definition: win32_port.h:171
#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(), SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, TopMemoryContext, UnBlockSig, and XLogArchivingActive.

◆ PgArchShmemInit()

void PgArchShmemInit ( void  )

Definition at line 167 of file pgarch.c.

170{
171 bool found;
172
173 PgArch = (PgArchData *)
174 ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
175
176 if (!found)
177 {
178 /* 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:991
Size PgArchShmemSize(void)
Definition: pgarch.c:156
#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:90

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

159{
160 Size size = 0;
161
162 size = add_size(size, sizeof(PgArchData));
163
size_t Size
Definition: c.h:576
Size add_size(Size s1, Size s2)
Definition: shmem.c:493

References add_size().

Referenced by CalculateShmemSize(), and PgArchShmemInit().

◆ PgArchWakeup()

void PgArchWakeup ( void  )

Definition at line 279 of file pgarch.c.

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

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

Referenced by XLogArchiveNotify().