PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "archive/archive_module.h"
#include "archive/shell_archive.h"
#include "lib/binaryheap.h"
#include "libpq/pqsignal.h"
#include "pgstat.h"
#include "postmaster/auxprocess.h"
#include "postmaster/interrupt.h"
#include "postmaster/pgarch.h"
#include "storage/condition_variable.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "storage/shmem.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/resowner.h"
#include "utils/timeout.h"
Go to the source code of this file.
Data Structures | |
struct | PgArchData |
struct | arch_files_state |
Macros | |
#define | PGARCH_AUTOWAKE_INTERVAL |
#define | PGARCH_RESTART_INTERVAL |
#define | NUM_ARCHIVE_RETRIES 3 |
#define | NUM_ORPHAN_CLEANUP_RETRIES 3 |
#define | NUM_FILES_PER_DIRECTORY_SCAN 64 |
Typedefs | |
typedef struct PgArchData | PgArchData |
Functions | |
static void | pgarch_waken_stop (SIGNAL_ARGS) |
static void | pgarch_MainLoop (void) |
static void | pgarch_ArchiverCopyLoop (void) |
static bool | pgarch_archiveXlog (char *xlog) |
static bool | pgarch_readyXlog (char *xlog) |
static void | pgarch_archiveDone (char *xlog) |
static void | pgarch_die (int code, Datum arg) |
static void | HandlePgArchInterrupts (void) |
static int | ready_file_comparator (Datum a, Datum b, void *arg) |
static void | LoadArchiveLibrary (void) |
static void | pgarch_call_module_shutdown_cb (int code, Datum arg) |
Size | PgArchShmemSize (void) |
void | PgArchShmemInit (void) |
bool | PgArchCanRestart (void) |
void | PgArchiverMain (char *startup_data, size_t startup_data_len) |
void | PgArchWakeup (void) |
void | PgArchForceDirScan (void) |
Variables | |
char * | XLogArchiveLibrary = "" |
char * | arch_module_check_errdetail_string |
static time_t | last_sigterm_time = 0 |
static PgArchData * | PgArch = NULL |
static const ArchiveModuleCallbacks * | ArchiveCallbacks |
static ArchiveModuleState * | archive_module_state |
static MemoryContext | archive_context |
static struct arch_files_state * | arch_files = NULL |
static volatile sig_atomic_t | ready_to_stop = false |
#define PGARCH_AUTOWAKE_INTERVAL |
#define PGARCH_RESTART_INTERVAL |
typedef struct PgArchData PgArchData |
|
static |
Definition at line 857 of file pgarch.c.
References ConfigReloadPending, ereport, errcode(), errdetail(), errmsg(), ERROR, LOG, LogMemoryContextPending, pfree(), PGC_SIGHUP, proc_exit(), ProcessConfigFile(), ProcessLogMemoryContextInterrupt(), ProcessProcSignalBarrier(), ProcSignalBarrierPending, pstrdup(), XLogArchiveCommand, and XLogArchiveLibrary.
Referenced by pgarch_ArchiverCopyLoop(), and pgarch_MainLoop().
|
static |
Definition at line 909 of file pgarch.c.
References ArchiveModuleCallbacks::archive_file_cb, archive_module_state, ArchiveCallbacks, before_shmem_exit(), ereport, errcode(), errdetail(), errmsg(), ERROR, load_external_function(), palloc0(), pgarch_call_module_shutdown_cb(), shell_archive_init(), ArchiveModuleCallbacks::startup_cb, XLogArchiveCommand, and XLogArchiveLibrary.
Referenced by PgArchiverMain().
|
static |
Definition at line 814 of file pgarch.c.
References ereport, errcode_for_file_access(), errmsg(), MAXPGPATH, StatusFilePath(), and WARNING.
Referenced by pgarch_ArchiverCopyLoop().
|
static |
Definition at line 378 of file pgarch.c.
References arch_files, arch_files_state::arch_files_size, arch_module_check_errdetail_string, archive_module_state, ArchiveCallbacks, ArchiveModuleCallbacks::check_configured_cb, ereport, errdetail_internal(), errmsg(), HandlePgArchInterrupts(), MAX_XFN_CHARS, MAXPGPATH, NUM_ARCHIVE_RETRIES, NUM_ORPHAN_CLEANUP_RETRIES, pg_usleep(), pgarch_archiveDone(), pgarch_archiveXlog(), pgarch_readyXlog(), pgstat_report_archiver(), PostmasterIsAlive, ShutdownRequestPending, snprintf, stat, StatusFilePath(), WARNING, and XLOGDIR.
Referenced by pgarch_MainLoop().
|
static |
Definition at line 514 of file pgarch.c.
References archive_context, ArchiveModuleCallbacks::archive_file_cb, archive_module_state, ArchiveCallbacks, AtEOXact_Files(), AtEOXact_HashTables(), ConditionVariableCancelSleep(), disable_all_timeouts(), EmitErrorReport(), error_context_stack, FlushErrorState(), HOLD_INTERRUPTS, LWLockReleaseAll(), MAXFNAMELEN, MAXPGPATH, MemoryContextReset(), MemoryContextSwitchTo(), PG_exception_stack, pgstat_report_wait_end(), ReleaseAuxProcessResources(), RESUME_INTERRUPTS, set_ps_display(), snprintf, and XLOGDIR.
Referenced by pgarch_ArchiverCopyLoop().
|
static |
Definition at line 951 of file pgarch.c.
References archive_module_state, ArchiveCallbacks, and ArchiveModuleCallbacks::shutdown_cb.
Referenced by LoadArchiveLibrary().
|
static |
Definition at line 843 of file pgarch.c.
References INVALID_PROC_NUMBER, PgArch, and PgArchData::pgprocno.
Referenced by PgArchiverMain().
|
static |
Definition at line 308 of file pgarch.c.
References HandlePgArchInterrupts(), last_sigterm_time, MyLatch, pgarch_ArchiverCopyLoop(), PGARCH_AUTOWAKE_INTERVAL, ready_to_stop, ResetLatch(), ShutdownRequestPending, time_to_stop, WaitLatch(), WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.
Referenced by PgArchiverMain().
|
static |
Definition at line 641 of file pgarch.c.
References AllocateDir(), arch_files_state::arch_filenames, arch_files_state::arch_files, arch_files, arch_files_state::arch_files_size, arch_files_state::arch_heap, binaryheap::bh_size, binaryheap_add(), binaryheap_add_unordered(), binaryheap_build(), binaryheap_first(), binaryheap_remove_first(), binaryheap_reset(), CStringGetDatum(), dirent::d_name, DatumGetCString(), ereport, errcode_for_file_access(), errmsg(), ERROR, PgArchData::force_dir_scan, FreeDir(), i, MAX_XFN_CHARS, MAXPGPATH, MIN_XFN_CHARS, NUM_FILES_PER_DIRECTORY_SCAN, pg_atomic_exchange_u32(), PgArch, ReadDir(), ready_file_comparator(), snprintf, stat, StatusFilePath(), VALID_XFN_CHARS, and XLOGDIR.
Referenced by pgarch_ArchiverCopyLoop().
|
static |
Definition at line 295 of file pgarch.c.
References MyLatch, ready_to_stop, and SetLatch().
Referenced by PgArchiverMain().
bool PgArchCanRestart | ( | void | ) |
Definition at line 195 of file pgarch.c.
References PGARCH_RESTART_INTERVAL.
Referenced by LaunchMissingBackgroundProcesses().
void PgArchForceDirScan | ( | void | ) |
Definition at line 800 of file pgarch.c.
References PgArchData::force_dir_scan, pg_atomic_write_membarrier_u32(), and PgArch.
Referenced by XLogArchiveNotify().
void PgArchiverMain | ( | char * | startup_data, |
size_t | startup_data_len | ||
) |
Definition at line 215 of file pgarch.c.
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.
void PgArchShmemInit | ( | void | ) |
Definition at line 166 of file pgarch.c.
References PgArchData::force_dir_scan, INVALID_PROC_NUMBER, MemSet, pg_atomic_init_u32(), PgArch, PgArchShmemSize(), PgArchData::pgprocno, and ShmemInitStruct().
Referenced by CreateOrAttachShmemStructs().
Size PgArchShmemSize | ( | void | ) |
Definition at line 155 of file pgarch.c.
References add_size(), and size.
Referenced by CalculateShmemSize(), and PgArchShmemInit().
void PgArchWakeup | ( | void | ) |
Definition at line 278 of file pgarch.c.
References PROC_HDR::allProcs, INVALID_PROC_NUMBER, PgArch, PgArchData::pgprocno, ProcGlobal, PGPROC::procLatch, and SetLatch().
Referenced by XLogArchiveNotify().
Definition at line 777 of file pgarch.c.
References a, b, DatumGetCString(), and IsTLHistoryFileName().
Referenced by pgarch_readyXlog(), and PgArchiverMain().
|
static |
Definition at line 130 of file pgarch.c.
Referenced by pgarch_ArchiverCopyLoop(), pgarch_readyXlog(), and PgArchiverMain().
char* arch_module_check_errdetail_string |
Definition at line 93 of file pgarch.c.
Referenced by pgarch_ArchiverCopyLoop().
|
static |
Definition at line 104 of file pgarch.c.
Referenced by pgarch_archiveXlog(), and PgArchiverMain().
|
static |
Definition at line 103 of file pgarch.c.
Referenced by LoadArchiveLibrary(), pgarch_ArchiverCopyLoop(), pgarch_archiveXlog(), and pgarch_call_module_shutdown_cb().
|
static |
Definition at line 102 of file pgarch.c.
Referenced by LoadArchiveLibrary(), pgarch_ArchiverCopyLoop(), pgarch_archiveXlog(), and pgarch_call_module_shutdown_cb().
|
static |
Definition at line 100 of file pgarch.c.
Referenced by pgarch_MainLoop().
|
static |
Definition at line 101 of file pgarch.c.
Referenced by pgarch_die(), pgarch_readyXlog(), PgArchForceDirScan(), PgArchiverMain(), PgArchShmemInit(), and PgArchWakeup().
|
static |
Definition at line 135 of file pgarch.c.
Referenced by pgarch_MainLoop(), and pgarch_waken_stop().
char* XLogArchiveLibrary = "" |
Definition at line 92 of file pgarch.c.
Referenced by HandlePgArchInterrupts(), and LoadArchiveLibrary().