diff options
Diffstat (limited to 'src/include/postmaster')
-rw-r--r-- | src/include/postmaster/autovacuum.h | 83 | ||||
-rw-r--r-- | src/include/postmaster/auxprocess.h | 20 | ||||
-rw-r--r-- | src/include/postmaster/bgworker.h | 162 | ||||
-rw-r--r-- | src/include/postmaster/bgworker_internals.h | 64 | ||||
-rw-r--r-- | src/include/postmaster/bgwriter.h | 45 | ||||
-rw-r--r-- | src/include/postmaster/fork_process.h | 17 | ||||
-rw-r--r-- | src/include/postmaster/interrupt.h | 32 | ||||
-rw-r--r-- | src/include/postmaster/pgarch.h | 73 | ||||
-rw-r--r-- | src/include/postmaster/postmaster.h | 78 | ||||
-rw-r--r-- | src/include/postmaster/startup.h | 41 | ||||
-rw-r--r-- | src/include/postmaster/syslogger.h | 103 | ||||
-rw-r--r-- | src/include/postmaster/walwriter.h | 21 |
12 files changed, 739 insertions, 0 deletions
diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h new file mode 100644 index 0000000..9d40fd6 --- /dev/null +++ b/src/include/postmaster/autovacuum.h @@ -0,0 +1,83 @@ +/*------------------------------------------------------------------------- + * + * autovacuum.h + * header file for integrated autovacuum daemon + * + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/autovacuum.h + * + *------------------------------------------------------------------------- + */ +#ifndef AUTOVACUUM_H +#define AUTOVACUUM_H + +#include "storage/block.h" + +/* + * Other processes can request specific work from autovacuum, identified by + * AutoVacuumWorkItem elements. + */ +typedef enum +{ + AVW_BRINSummarizeRange +} AutoVacuumWorkItemType; + + +/* GUC variables */ +extern PGDLLIMPORT bool autovacuum_start_daemon; +extern PGDLLIMPORT int autovacuum_max_workers; +extern PGDLLIMPORT int autovacuum_work_mem; +extern PGDLLIMPORT int autovacuum_naptime; +extern PGDLLIMPORT int autovacuum_vac_thresh; +extern PGDLLIMPORT double autovacuum_vac_scale; +extern PGDLLIMPORT int autovacuum_vac_ins_thresh; +extern PGDLLIMPORT double autovacuum_vac_ins_scale; +extern PGDLLIMPORT int autovacuum_anl_thresh; +extern PGDLLIMPORT double autovacuum_anl_scale; +extern PGDLLIMPORT int autovacuum_freeze_max_age; +extern PGDLLIMPORT int autovacuum_multixact_freeze_max_age; +extern PGDLLIMPORT double autovacuum_vac_cost_delay; +extern PGDLLIMPORT int autovacuum_vac_cost_limit; + +/* autovacuum launcher PID, only valid when worker is shutting down */ +extern PGDLLIMPORT int AutovacuumLauncherPid; + +extern PGDLLIMPORT int Log_autovacuum_min_duration; + +/* Status inquiry functions */ +extern bool AutoVacuumingActive(void); +extern bool IsAutoVacuumLauncherProcess(void); +extern bool IsAutoVacuumWorkerProcess(void); + +#define IsAnyAutoVacuumProcess() \ + (IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess()) + +/* Functions to start autovacuum process, called from postmaster */ +extern void autovac_init(void); +extern int StartAutoVacLauncher(void); +extern int StartAutoVacWorker(void); + +/* called from postmaster when a worker could not be forked */ +extern void AutoVacWorkerFailed(void); + +/* autovacuum cost-delay balancer */ +extern void AutoVacuumUpdateDelay(void); + +#ifdef EXEC_BACKEND +extern void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn(); +extern void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn(); +extern void AutovacuumWorkerIAm(void); +extern void AutovacuumLauncherIAm(void); +#endif + +extern bool AutoVacuumRequestWork(AutoVacuumWorkItemType type, + Oid relationId, BlockNumber blkno); + +/* shared memory stuff */ +extern Size AutoVacuumShmemSize(void); +extern void AutoVacuumShmemInit(void); + +#endif /* AUTOVACUUM_H */ diff --git a/src/include/postmaster/auxprocess.h b/src/include/postmaster/auxprocess.h new file mode 100644 index 0000000..e3789fb --- /dev/null +++ b/src/include/postmaster/auxprocess.h @@ -0,0 +1,20 @@ +/*------------------------------------------------------------------------- + * auxprocess.h + * include file for functions related to auxiliary processes. + * + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/postmaster/auxprocess.h + *------------------------------------------------------------------------- + */ +#ifndef AUXPROCESS_H +#define AUXPROCESS_H + +#include "miscadmin.h" + +extern void AuxiliaryProcessMain(AuxProcType auxtype) pg_attribute_noreturn(); + +#endif /* AUXPROCESS_H */ diff --git a/src/include/postmaster/bgworker.h b/src/include/postmaster/bgworker.h new file mode 100644 index 0000000..96975bd --- /dev/null +++ b/src/include/postmaster/bgworker.h @@ -0,0 +1,162 @@ +/*-------------------------------------------------------------------- + * bgworker.h + * POSTGRES pluggable background workers interface + * + * A background worker is a process able to run arbitrary, user-supplied code, + * including normal transactions. + * + * Any external module loaded via shared_preload_libraries can register a + * worker. Workers can also be registered dynamically at runtime. In either + * case, the worker process is forked from the postmaster and runs the + * user-supplied "main" function. This code may connect to a database and + * run transactions. Workers can remain active indefinitely, but will be + * terminated if a shutdown or crash occurs. + * + * If the fork() call fails in the postmaster, it will try again later. Note + * that the failure can only be transient (fork failure due to high load, + * memory pressure, too many processes, etc); more permanent problems, like + * failure to connect to a database, are detected later in the worker and dealt + * with just by having the worker exit normally. A worker which exits with + * a return code of 0 will never be restarted and will be removed from worker + * list. A worker which exits with a return code of 1 will be restarted after + * the configured restart interval (unless that interval is BGW_NEVER_RESTART). + * The TerminateBackgroundWorker() function can be used to terminate a + * dynamically registered background worker; the worker will be sent a SIGTERM + * and will not be restarted after it exits. Whenever the postmaster knows + * that a worker will not be restarted, it unregisters the worker, freeing up + * that worker's slot for use by a new worker. + * + * Note that there might be more than one worker in a database concurrently, + * and the same module may request more than one worker running the same (or + * different) code. + * + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/postmaster/bgworker.h + *-------------------------------------------------------------------- + */ +#ifndef BGWORKER_H +#define BGWORKER_H + +/*--------------------------------------------------------------------- + * External module API. + *--------------------------------------------------------------------- + */ + +/* + * Pass this flag to have your worker be able to connect to shared memory. + * This flag is required. + */ +#define BGWORKER_SHMEM_ACCESS 0x0001 + +/* + * This flag means the bgworker requires a database connection. The connection + * is not established automatically; the worker must establish it later. + * It requires that BGWORKER_SHMEM_ACCESS was passed too. + */ +#define BGWORKER_BACKEND_DATABASE_CONNECTION 0x0002 + +/* + * This class is used internally for parallel queries, to keep track of the + * number of active parallel workers and make sure we never launch more than + * max_parallel_workers parallel workers at the same time. Third party + * background workers should not use this class. + */ +#define BGWORKER_CLASS_PARALLEL 0x0010 +/* add additional bgworker classes here */ + + +typedef void (*bgworker_main_type) (Datum main_arg); + +/* + * Points in time at which a bgworker can request to be started + */ +typedef enum +{ + BgWorkerStart_PostmasterStart, + BgWorkerStart_ConsistentState, + BgWorkerStart_RecoveryFinished +} BgWorkerStartTime; + +#define BGW_DEFAULT_RESTART_INTERVAL 60 +#define BGW_NEVER_RESTART -1 +#define BGW_MAXLEN 96 +#define BGW_EXTRALEN 128 + +typedef struct BackgroundWorker +{ + char bgw_name[BGW_MAXLEN]; + char bgw_type[BGW_MAXLEN]; + int bgw_flags; + BgWorkerStartTime bgw_start_time; + int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */ + char bgw_library_name[BGW_MAXLEN]; + char bgw_function_name[BGW_MAXLEN]; + Datum bgw_main_arg; + char bgw_extra[BGW_EXTRALEN]; + pid_t bgw_notify_pid; /* SIGUSR1 this backend on start/stop */ +} BackgroundWorker; + +typedef enum BgwHandleStatus +{ + BGWH_STARTED, /* worker is running */ + BGWH_NOT_YET_STARTED, /* worker hasn't been started yet */ + BGWH_STOPPED, /* worker has exited */ + BGWH_POSTMASTER_DIED /* postmaster died; worker status unclear */ +} BgwHandleStatus; + +struct BackgroundWorkerHandle; +typedef struct BackgroundWorkerHandle BackgroundWorkerHandle; + +/* Register a new bgworker during shared_preload_libraries */ +extern void RegisterBackgroundWorker(BackgroundWorker *worker); + +/* Register a new bgworker from a regular backend */ +extern bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, + BackgroundWorkerHandle **handle); + +/* Query the status of a bgworker */ +extern BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, + pid_t *pidp); +extern BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pid); +extern BgwHandleStatus + WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *); +extern const char *GetBackgroundWorkerTypeByPid(pid_t pid); + +/* Terminate a bgworker */ +extern void TerminateBackgroundWorker(BackgroundWorkerHandle *handle); + +/* This is valid in a running worker */ +extern PGDLLIMPORT BackgroundWorker *MyBgworkerEntry; + +/* + * Connect to the specified database, as the specified user. Only a worker + * that passed BGWORKER_BACKEND_DATABASE_CONNECTION during registration may + * call this. + * + * If username is NULL, bootstrapping superuser is used. + * If dbname is NULL, connection is made to no specific database; + * only shared catalogs can be accessed. + */ +extern void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, uint32 flags); + +/* Just like the above, but specifying database and user by OID. */ +extern void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags); + +/* + * Flags to BackgroundWorkerInitializeConnection et al + * + * + * Allow bypassing datallowconn restrictions when connecting to database + */ +#define BGWORKER_BYPASS_ALLOWCONN 1 + + +/* Block/unblock signals in a background worker process */ +extern void BackgroundWorkerBlockSignals(void); +extern void BackgroundWorkerUnblockSignals(void); + +#endif /* BGWORKER_H */ diff --git a/src/include/postmaster/bgworker_internals.h b/src/include/postmaster/bgworker_internals.h new file mode 100644 index 0000000..3876835 --- /dev/null +++ b/src/include/postmaster/bgworker_internals.h @@ -0,0 +1,64 @@ +/*-------------------------------------------------------------------- + * bgworker_internals.h + * POSTGRES pluggable background workers internals + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/postmaster/bgworker_internals.h + *-------------------------------------------------------------------- + */ +#ifndef BGWORKER_INTERNALS_H +#define BGWORKER_INTERNALS_H + +#include "datatype/timestamp.h" +#include "lib/ilist.h" +#include "postmaster/bgworker.h" + +/* GUC options */ + +/* + * Maximum possible value of parallel workers. + */ +#define MAX_PARALLEL_WORKER_LIMIT 1024 + +/* + * List of background workers, private to postmaster. + * + * A worker that requests a database connection during registration will have + * rw_backend set, and will be present in BackendList. Note: do not rely on + * rw_backend being non-NULL for shmem-connected workers! + */ +typedef struct RegisteredBgWorker +{ + BackgroundWorker rw_worker; /* its registry entry */ + struct bkend *rw_backend; /* its BackendList entry, or NULL */ + pid_t rw_pid; /* 0 if not running */ + int rw_child_slot; + TimestampTz rw_crashed_at; /* if not 0, time it last crashed */ + int rw_shmem_slot; + bool rw_terminate; + slist_node rw_lnode; /* list link */ +} RegisteredBgWorker; + +extern PGDLLIMPORT slist_head BackgroundWorkerList; + +extern Size BackgroundWorkerShmemSize(void); +extern void BackgroundWorkerShmemInit(void); +extern void BackgroundWorkerStateChange(bool allow_new_workers); +extern void ForgetBackgroundWorker(slist_mutable_iter *cur); +extern void ReportBackgroundWorkerPID(RegisteredBgWorker *); +extern void ReportBackgroundWorkerExit(slist_mutable_iter *cur); +extern void BackgroundWorkerStopNotifications(pid_t pid); +extern void ForgetUnstartedBackgroundWorkers(void); +extern void ResetBackgroundWorkerCrashTimes(void); + +/* Function to start a background worker, called from postmaster.c */ +extern void StartBackgroundWorker(void) pg_attribute_noreturn(); + +#ifdef EXEC_BACKEND +extern BackgroundWorker *BackgroundWorkerEntry(int slotno); +#endif + +#endif /* BGWORKER_INTERNALS_H */ diff --git a/src/include/postmaster/bgwriter.h b/src/include/postmaster/bgwriter.h new file mode 100644 index 0000000..2511ef4 --- /dev/null +++ b/src/include/postmaster/bgwriter.h @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + * + * bgwriter.h + * Exports from postmaster/bgwriter.c and postmaster/checkpointer.c. + * + * The bgwriter process used to handle checkpointing duties too. Now + * there is a separate process, but we did not bother to split this header. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * src/include/postmaster/bgwriter.h + * + *------------------------------------------------------------------------- + */ +#ifndef _BGWRITER_H +#define _BGWRITER_H + +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "storage/smgr.h" +#include "storage/sync.h" + + +/* GUC options */ +extern PGDLLIMPORT int BgWriterDelay; +extern PGDLLIMPORT int CheckPointTimeout; +extern PGDLLIMPORT int CheckPointWarning; +extern PGDLLIMPORT double CheckPointCompletionTarget; + +extern void BackgroundWriterMain(void) pg_attribute_noreturn(); +extern void CheckpointerMain(void) pg_attribute_noreturn(); + +extern void RequestCheckpoint(int flags); +extern void CheckpointWriteDelay(int flags, double progress); + +extern bool ForwardSyncRequest(const FileTag *ftag, SyncRequestType type); + +extern void AbsorbSyncRequests(void); + +extern Size CheckpointerShmemSize(void); +extern void CheckpointerShmemInit(void); + +extern bool FirstCallSinceLastCheckpoint(void); + +#endif /* _BGWRITER_H */ diff --git a/src/include/postmaster/fork_process.h b/src/include/postmaster/fork_process.h new file mode 100644 index 0000000..5fc8490 --- /dev/null +++ b/src/include/postmaster/fork_process.h @@ -0,0 +1,17 @@ +/*------------------------------------------------------------------------- + * + * fork_process.h + * Exports from postmaster/fork_process.c. + * + * Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * src/include/postmaster/fork_process.h + * + *------------------------------------------------------------------------- + */ +#ifndef FORK_PROCESS_H +#define FORK_PROCESS_H + +extern pid_t fork_process(void); + +#endif /* FORK_PROCESS_H */ diff --git a/src/include/postmaster/interrupt.h b/src/include/postmaster/interrupt.h new file mode 100644 index 0000000..289e045 --- /dev/null +++ b/src/include/postmaster/interrupt.h @@ -0,0 +1,32 @@ +/*------------------------------------------------------------------------- + * + * interrupt.h + * Interrupt handling routines. + * + * Responses to interrupts are fairly varied and many types of backends + * have their own implementations, but we provide a few generic things + * here to facilitate code reuse. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/postmaster/interrupt.h + * + *------------------------------------------------------------------------- + */ + +#ifndef INTERRUPT_H +#define INTERRUPT_H + +#include <signal.h> + +extern PGDLLIMPORT volatile sig_atomic_t ConfigReloadPending; +extern PGDLLIMPORT volatile sig_atomic_t ShutdownRequestPending; + +extern void HandleMainLoopInterrupts(void); +extern void SignalHandlerForConfigReload(SIGNAL_ARGS); +extern void SignalHandlerForCrashExit(SIGNAL_ARGS); +extern void SignalHandlerForShutdownRequest(SIGNAL_ARGS); + +#endif diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h new file mode 100644 index 0000000..f366a15 --- /dev/null +++ b/src/include/postmaster/pgarch.h @@ -0,0 +1,73 @@ +/*------------------------------------------------------------------------- + * + * pgarch.h + * Exports from postmaster/pgarch.c. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/pgarch.h + * + *------------------------------------------------------------------------- + */ +#ifndef _PGARCH_H +#define _PGARCH_H + +/* ---------- + * Archiver control info. + * + * We expect that archivable files within pg_wal will have names between + * MIN_XFN_CHARS and MAX_XFN_CHARS in length, consisting only of characters + * appearing in VALID_XFN_CHARS. The status files in archive_status have + * corresponding names with ".ready" or ".done" appended. + * ---------- + */ +#define MIN_XFN_CHARS 16 +#define MAX_XFN_CHARS 40 +#define VALID_XFN_CHARS "0123456789ABCDEF.history.backup.partial" + +extern Size PgArchShmemSize(void); +extern void PgArchShmemInit(void); +extern bool PgArchCanRestart(void); +extern void PgArchiverMain(void) pg_attribute_noreturn(); +extern void PgArchWakeup(void); +extern void PgArchForceDirScan(void); + +/* + * The value of the archive_library GUC. + */ +extern PGDLLIMPORT char *XLogArchiveLibrary; + +/* + * Archive module callbacks + * + * These callback functions should be defined by archive libraries and returned + * via _PG_archive_module_init(). ArchiveFileCB is the only required callback. + * For more information about the purpose of each callback, refer to the + * archive modules documentation. + */ +typedef bool (*ArchiveCheckConfiguredCB) (void); +typedef bool (*ArchiveFileCB) (const char *file, const char *path); +typedef void (*ArchiveShutdownCB) (void); + +typedef struct ArchiveModuleCallbacks +{ + ArchiveCheckConfiguredCB check_configured_cb; + ArchiveFileCB archive_file_cb; + ArchiveShutdownCB shutdown_cb; +} ArchiveModuleCallbacks; + +/* + * Type of the shared library symbol _PG_archive_module_init that is looked + * up when loading an archive library. + */ +typedef void (*ArchiveModuleInit) (ArchiveModuleCallbacks *cb); + +/* + * Since the logic for archiving via a shell command is in the core server + * and does not need to be loaded via a shared library, it has a special + * initialization function. + */ +extern void shell_archive_init(ArchiveModuleCallbacks *cb); + +#endif /* _PGARCH_H */ diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h new file mode 100644 index 0000000..90e333c --- /dev/null +++ b/src/include/postmaster/postmaster.h @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------- + * + * postmaster.h + * Exports from postmaster/postmaster.c. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/postmaster.h + * + *------------------------------------------------------------------------- + */ +#ifndef _POSTMASTER_H +#define _POSTMASTER_H + +/* GUC options */ +extern PGDLLIMPORT bool EnableSSL; +extern PGDLLIMPORT int ReservedBackends; +extern PGDLLIMPORT int PostPortNumber; +extern PGDLLIMPORT int Unix_socket_permissions; +extern PGDLLIMPORT char *Unix_socket_group; +extern PGDLLIMPORT char *Unix_socket_directories; +extern PGDLLIMPORT char *ListenAddresses; +extern PGDLLIMPORT bool ClientAuthInProgress; +extern PGDLLIMPORT int PreAuthDelay; +extern PGDLLIMPORT int AuthenticationTimeout; +extern PGDLLIMPORT bool Log_connections; +extern PGDLLIMPORT bool log_hostname; +extern PGDLLIMPORT bool enable_bonjour; +extern PGDLLIMPORT char *bonjour_name; +extern PGDLLIMPORT bool restart_after_crash; +extern PGDLLIMPORT bool remove_temp_files_after_crash; + +#ifdef WIN32 +extern PGDLLIMPORT HANDLE PostmasterHandle; +#else +extern PGDLLIMPORT int postmaster_alive_fds[2]; + +/* + * Constants that represent which of postmaster_alive_fds is held by + * postmaster, and which is used in children to check for postmaster death. + */ +#define POSTMASTER_FD_WATCH 0 /* used in children to check for + * postmaster death */ +#define POSTMASTER_FD_OWN 1 /* kept open by postmaster only */ +#endif + +extern PGDLLIMPORT const char *progname; + +extern void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn(); +extern void ClosePostmasterPorts(bool am_syslogger); +extern void InitProcessGlobals(void); + +extern int MaxLivePostmasterChildren(void); + +extern bool PostmasterMarkPIDForWorkerNotify(int); + +#ifdef EXEC_BACKEND +extern pid_t postmaster_forkexec(int argc, char *argv[]); +extern void SubPostmasterMain(int argc, char *argv[]) pg_attribute_noreturn(); + +extern Size ShmemBackendArraySize(void); +extern void ShmemBackendArrayAllocation(void); +#endif + +/* + * Note: MAX_BACKENDS is limited to 2^18-1 because that's the width reserved + * for buffer references in buf_internals.h. This limitation could be lifted + * by using a 64bit state; but it's unlikely to be worthwhile as 2^18-1 + * backends exceed currently realistic configurations. Even if that limitation + * were removed, we still could not a) exceed 2^23-1 because inval.c stores + * the backend ID as a 3-byte signed integer, b) INT_MAX/4 because some places + * compute 4*MaxBackends without any overflow check. This is rechecked in the + * relevant GUC check hooks and in RegisterBackgroundWorker(). + */ +#define MAX_BACKENDS 0x3FFFF + +#endif /* _POSTMASTER_H */ diff --git a/src/include/postmaster/startup.h b/src/include/postmaster/startup.h new file mode 100644 index 0000000..1289753 --- /dev/null +++ b/src/include/postmaster/startup.h @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + * + * startup.h + * Exports from postmaster/startup.c. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * src/include/postmaster/startup.h + * + *------------------------------------------------------------------------- + */ +#ifndef _STARTUP_H +#define _STARTUP_H + +/* + * Log the startup progress message if a timer has expired. + */ +#define ereport_startup_progress(msg, ...) \ + do { \ + long secs; \ + int usecs; \ + if (has_startup_progress_timeout_expired(&secs, &usecs)) \ + ereport(LOG, errmsg(msg, secs, (usecs / 10000), __VA_ARGS__ )); \ + } while(0) + +extern PGDLLIMPORT int log_startup_progress_interval; + +extern void HandleStartupProcInterrupts(void); +extern void StartupProcessMain(void) pg_attribute_noreturn(); +extern void PreRestoreCommand(void); +extern void PostRestoreCommand(void); +extern bool IsPromoteSignaled(void); +extern void ResetPromoteSignaled(void); + +extern void enable_startup_progress_timeout(void); +extern void disable_startup_progress_timeout(void); +extern void begin_startup_progress_phase(void); +extern void startup_progress_timeout_handler(void); +extern bool has_startup_progress_timeout_expired(long *secs, int *usecs); + +#endif /* _STARTUP_H */ diff --git a/src/include/postmaster/syslogger.h b/src/include/postmaster/syslogger.h new file mode 100644 index 0000000..6436724 --- /dev/null +++ b/src/include/postmaster/syslogger.h @@ -0,0 +1,103 @@ +/*------------------------------------------------------------------------- + * + * syslogger.h + * Exports from postmaster/syslogger.c. + * + * Copyright (c) 2004-2022, PostgreSQL Global Development Group + * + * src/include/postmaster/syslogger.h + * + *------------------------------------------------------------------------- + */ +#ifndef _SYSLOGGER_H +#define _SYSLOGGER_H + +#include <limits.h> /* for PIPE_BUF */ + + +/* + * Primitive protocol structure for writing to syslogger pipe(s). The idea + * here is to divide long messages into chunks that are not more than + * PIPE_BUF bytes long, which according to POSIX spec must be written into + * the pipe atomically. The pipe reader then uses the protocol headers to + * reassemble the parts of a message into a single string. The reader can + * also cope with non-protocol data coming down the pipe, though we cannot + * guarantee long strings won't get split apart. + * + * We use non-nul bytes in is_last to make the protocol a tiny bit + * more robust against finding a false double nul byte prologue. But + * we still might find it in the len and/or pid bytes unless we're careful. + */ + +#ifdef PIPE_BUF +/* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */ +#if PIPE_BUF > 65536 +#define PIPE_CHUNK_SIZE 65536 +#else +#define PIPE_CHUNK_SIZE ((int) PIPE_BUF) +#endif +#else /* not defined */ +/* POSIX says the value of PIPE_BUF must be at least 512, so use that */ +#define PIPE_CHUNK_SIZE 512 +#endif + +typedef struct +{ + char nuls[2]; /* always \0\0 */ + uint16 len; /* size of this chunk (counts data only) */ + int32 pid; /* writer's pid */ + bits8 flags; /* bitmask of PIPE_PROTO_* */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */ +} PipeProtoHeader; + +typedef union +{ + PipeProtoHeader proto; + char filler[PIPE_CHUNK_SIZE]; +} PipeProtoChunk; + +#define PIPE_HEADER_SIZE offsetof(PipeProtoHeader, data) +#define PIPE_MAX_PAYLOAD ((int) (PIPE_CHUNK_SIZE - PIPE_HEADER_SIZE)) + +/* flag bits for PipeProtoHeader->flags */ +#define PIPE_PROTO_IS_LAST 0x01 /* last chunk of message? */ +/* log destinations */ +#define PIPE_PROTO_DEST_STDERR 0x10 +#define PIPE_PROTO_DEST_CSVLOG 0x20 +#define PIPE_PROTO_DEST_JSONLOG 0x40 + +/* GUC options */ +extern PGDLLIMPORT bool Logging_collector; +extern PGDLLIMPORT int Log_RotationAge; +extern PGDLLIMPORT int Log_RotationSize; +extern PGDLLIMPORT char *Log_directory; +extern PGDLLIMPORT char *Log_filename; +extern PGDLLIMPORT bool Log_truncate_on_rotation; +extern PGDLLIMPORT int Log_file_mode; + +#ifndef WIN32 +extern PGDLLIMPORT int syslogPipe[2]; +#else +extern PGDLLIMPORT HANDLE syslogPipe[2]; +#endif + + +extern int SysLogger_Start(void); + +extern void write_syslogger_file(const char *buffer, int count, int dest); + +#ifdef EXEC_BACKEND +extern void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn(); +#endif + +extern bool CheckLogrotateSignal(void); +extern void RemoveLogrotateSignalFiles(void); + +/* + * Name of files saving meta-data information about the log + * files currently in use by the syslogger + */ +#define LOG_METAINFO_DATAFILE "current_logfiles" +#define LOG_METAINFO_DATAFILE_TMP LOG_METAINFO_DATAFILE ".tmp" + +#endif /* _SYSLOGGER_H */ diff --git a/src/include/postmaster/walwriter.h b/src/include/postmaster/walwriter.h new file mode 100644 index 0000000..ddc9436 --- /dev/null +++ b/src/include/postmaster/walwriter.h @@ -0,0 +1,21 @@ +/*------------------------------------------------------------------------- + * + * walwriter.h + * Exports from postmaster/walwriter.c. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * src/include/postmaster/walwriter.h + * + *------------------------------------------------------------------------- + */ +#ifndef _WALWRITER_H +#define _WALWRITER_H + +/* GUC options */ +extern PGDLLIMPORT int WalWriterDelay; +extern PGDLLIMPORT int WalWriterFlushAfter; + +extern void WalWriterMain(void) pg_attribute_noreturn(); + +#endif /* _WALWRITER_H */ |