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 * If first time through, or time somehow went backwards, always update
205 * last_pgarch_start_time to match the current clock and allow archiver
206 * start. Otherwise allow it only once enough time has elapsed.
207 */
208 if (last_pgarch_start_time == 0 ||
209 curtime < last_pgarch_start_time ||
210 curtime - last_pgarch_start_time >= PGARCH_RESTART_INTERVAL)
211 {
212 last_pgarch_start_time = curtime;
213 return true;
214 }
#define PGARCH_RESTART_INTERVAL
Definition: pgarch.c:63

References PGARCH_RESTART_INTERVAL.

Referenced by LaunchMissingBackgroundProcesses().

◆ PgArchForceDirScan()

void PgArchForceDirScan ( void  )

Definition at line 806 of file pgarch.c.

809{

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

222{
223 Assert(startup_data_len == 0);
224
227
228 /*
229 * Ignore all signals usually bound to some action in the postmaster,
230 * except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
231 */
233 pqsignal(SIGINT, SIG_IGN);
235 /* SIGQUIT handler was already set up by InitPostmasterChild */
236 pqsignal(SIGALRM, SIG_IGN);
237 pqsignal(SIGPIPE, SIG_IGN);
240
241 /* Reset some signals that are accepted by postmaster but not here */
242 pqsignal(SIGCHLD, SIG_DFL);
243
244 /* Unblock signals (they were blocked when the postmaster forked us) */
245 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
246
247 /* We shouldn't be launched unnecessarily. */
249
250 /* Arrange to clean up at archiver exit */
252
253 /*
254 * Advertise our proc number so that backends can use our latch to wake us
255 * up while we're sleeping.
256 */
258
259 /* Create workspace for pgarch_readyXlog() */
260 arch_files = palloc(sizeof(struct arch_files_state));
262
263 /* Initialize our max-heap for prioritizing files to archive. */
266
267 /* Initialize our memory context. */
269 "archiver",
271
272 /* Load the archive_library. */
274
276
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:90
Assert(PointerIsAligned(start, uint64))
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:104
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:166
void * palloc(Size size)
Definition: mcxt.c:1365
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
@ B_ARCHIVER
Definition: miscadmin.h:361
BackendType MyBackendType
Definition: miscinit.c:64
static void pgarch_die(int code, Datum arg)
Definition: pgarch.c:849
static PgArchData * PgArch
Definition: pgarch.c:102
static void pgarch_MainLoop(void)
Definition: pgarch.c:312
static void pgarch_waken_stop(SIGNAL_ARGS)
Definition: pgarch.c:299
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:783
#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:674
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:219
#define MemSet(start, val, len)
Definition: c.h:1023
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:388
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:614
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 282 of file pgarch.c.

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

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

Referenced by XLogArchiveNotify().