PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <unistd.h>
#include "access/relation.h"
#include "access/xact.h"
#include "catalog/pg_class.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/bgworker.h"
#include "postmaster/interrupt.h"
#include "storage/buf_internals.h"
#include "storage/dsm.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lwlock.h"
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "storage/shmem.h"
#include "storage/smgr.h"
#include "tcop/tcopprot.h"
#include "utils/acl.h"
#include "utils/datetime.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/relfilenumbermap.h"
#include "utils/resowner.h"
Go to the source code of this file.
Data Structures | |
struct | BlockInfoRecord |
struct | AutoPrewarmSharedState |
Macros | |
#define | AUTOPREWARM_FILE "autoprewarm.blocks" |
#define | cmp_member_elem(fld) |
Typedefs | |
typedef struct BlockInfoRecord | BlockInfoRecord |
typedef struct AutoPrewarmSharedState | AutoPrewarmSharedState |
Functions | |
PGDLLEXPORT void | autoprewarm_main (Datum main_arg) |
PGDLLEXPORT void | autoprewarm_database_main (Datum main_arg) |
PG_FUNCTION_INFO_V1 (autoprewarm_start_worker) | |
PG_FUNCTION_INFO_V1 (autoprewarm_dump_now) | |
static void | apw_load_buffers (void) |
static int | apw_dump_now (bool is_bgworker, bool dump_unlogged) |
static void | apw_start_leader_worker (void) |
static void | apw_start_database_worker (void) |
static bool | apw_init_shmem (void) |
static void | apw_detach_shmem (int code, Datum arg) |
static int | apw_compare_blockinfo (const void *p, const void *q) |
static void | autoprewarm_shmem_request (void) |
void | _PG_init (void) |
Datum | autoprewarm_start_worker (PG_FUNCTION_ARGS) |
Datum | autoprewarm_dump_now (PG_FUNCTION_ARGS) |
Variables | |
static shmem_request_hook_type | prev_shmem_request_hook = NULL |
static AutoPrewarmSharedState * | apw_state = NULL |
static bool | autoprewarm = true |
static int | autoprewarm_interval = 300 |
#define AUTOPREWARM_FILE "autoprewarm.blocks" |
Definition at line 58 of file autoprewarm.c.
#define cmp_member_elem | ( | fld | ) |
typedef struct AutoPrewarmSharedState AutoPrewarmSharedState |
typedef struct BlockInfoRecord BlockInfoRecord |
void _PG_init | ( | void | ) |
Definition at line 112 of file autoprewarm.c.
References apw_start_leader_worker(), autoprewarm, autoprewarm_interval, autoprewarm_shmem_request(), DefineCustomBoolVariable(), DefineCustomIntVariable(), GUC_UNIT_S, MarkGUCPrefixReserved(), PGC_POSTMASTER, PGC_SIGHUP, prev_shmem_request_hook, process_shared_preload_libraries_in_progress, and shmem_request_hook.
|
static |
Definition at line 908 of file autoprewarm.c.
References a, b, cmp_member_elem, and tablespace.
Referenced by apw_load_buffers().
|
static |
Definition at line 802 of file autoprewarm.c.
References apw_state, AutoPrewarmSharedState::bgworker_pid, InvalidPid, AutoPrewarmSharedState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProcPid, and AutoPrewarmSharedState::pid_using_dumpfile.
Referenced by autoprewarm_dump_now(), and autoprewarm_main().
Definition at line 581 of file autoprewarm.c.
References AllocateFile(), apw_state, AUTOPREWARM_FILE, BlockInfoRecord::blocknum, buftag::blockNum, BM_PERMANENT, BM_TAG_VALID, BufTagGetForkNum(), BufTagGetRelNumber(), CHECK_FOR_INTERRUPTS, BlockInfoRecord::database, buftag::dbOid, DEBUG1, durable_rename(), ereport, errcode_for_file_access(), errmsg(), errmsg_internal(), ERROR, BlockInfoRecord::filenumber, BlockInfoRecord::forknum, fprintf, FreeFile(), GetBufferDescriptor(), i, InvalidPid, AutoPrewarmSharedState::lock, LockBufHdr(), LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, MyProcPid, NBuffers, palloc(), pfree(), AutoPrewarmSharedState::pid_using_dumpfile, snprintf, buftag::spcOid, BlockInfoRecord::tablespace, tablespace, BufferDesc::tag, and UnlockBufHdr().
Referenced by autoprewarm_dump_now(), and autoprewarm_main().
|
static |
Definition at line 776 of file autoprewarm.c.
References apw_state, AutoPrewarmSharedState::bgworker_pid, InvalidPid, AutoPrewarmSharedState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockInitialize(), LWLockNewTrancheId(), LWLockRegisterTranche(), LWLockRelease(), AutoPrewarmSharedState::pid_using_dumpfile, ShmemInitStruct(), and LWLock::tranche.
Referenced by autoprewarm_database_main(), autoprewarm_dump_now(), autoprewarm_main(), and autoprewarm_start_worker().
|
static |
Definition at line 287 of file autoprewarm.c.
References AllocateFile(), apw_compare_blockinfo(), apw_start_database_worker(), apw_state, Assert(), AUTOPREWARM_FILE, AutoPrewarmSharedState::block_info_handle, BlockInfoRecord::database, AutoPrewarmSharedState::database, dsm_create(), dsm_detach(), DSM_HANDLE_INVALID, dsm_segment_address(), dsm_segment_handle(), ereport, errcode_for_file_access(), errmsg(), ERROR, BlockInfoRecord::forknum, FreeFile(), have_free_buffer(), i, InvalidOid, InvalidPid, j, AutoPrewarmSharedState::lock, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProcPid, pg_qsort(), AutoPrewarmSharedState::pid_using_dumpfile, AutoPrewarmSharedState::prewarm_start_idx, AutoPrewarmSharedState::prewarm_stop_idx, AutoPrewarmSharedState::prewarmed_blocks, ShutdownRequestPending, and tablespace.
Referenced by autoprewarm_main().
|
static |
Definition at line 858 of file autoprewarm.c.
References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_SHMEM_ACCESS, BgWorkerStart_ConsistentState, ereport, errcode(), errhint(), errmsg(), ERROR, MemSet, MyProcPid, RegisterDynamicBackgroundWorker(), and WaitForBackgroundWorkerShutdown().
Referenced by apw_load_buffers().
|
static |
Definition at line 816 of file autoprewarm.c.
References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWH_STARTED, BGWORKER_SHMEM_ACCESS, BgWorkerStart_ConsistentState, ereport, errcode(), errhint(), errmsg(), ERROR, MemSet, MyProcPid, process_shared_preload_libraries_in_progress, RegisterBackgroundWorker(), RegisterDynamicBackgroundWorker(), and WaitForBackgroundWorkerStartup().
Referenced by _PG_init(), and autoprewarm_start_worker().
void autoprewarm_database_main | ( | Datum | main_arg | ) |
Definition at line 448 of file autoprewarm.c.
References AccessShareLock, apw_init_shmem(), apw_state, Assert(), BackgroundWorkerInitializeConnectionByOid(), BackgroundWorkerUnblockSignals(), AutoPrewarmSharedState::block_info_handle, BlockInfoRecord::blocknum, buf, BufferIsValid(), CHECK_FOR_INTERRUPTS, CommitTransactionCommand(), BlockInfoRecord::database, AutoPrewarmSharedState::database, die, dsm_attach(), dsm_detach(), dsm_segment_address(), ereport, errcode(), errmsg(), ERROR, BlockInfoRecord::filenumber, BlockInfoRecord::forknum, have_free_buffer(), InvalidForkNumber, InvalidOid, MAX_FORKNUM, OidIsValid, pqsignal(), AutoPrewarmSharedState::prewarm_start_idx, AutoPrewarmSharedState::prewarmed_blocks, RBM_NORMAL, ReadBufferExtended(), relation_close(), RelationGetNumberOfBlocksInFork(), RelationGetSmgr(), ReleaseBuffer(), RelidByRelfilenumber(), smgrexists(), StartTransactionCommand(), BlockInfoRecord::tablespace, and try_relation_open().
Datum autoprewarm_dump_now | ( | PG_FUNCTION_ARGS | ) |
Definition at line 755 of file autoprewarm.c.
References apw_detach_shmem(), apw_dump_now(), apw_init_shmem(), PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, and PG_RETURN_INT64.
void autoprewarm_main | ( | Datum | main_arg | ) |
Definition at line 168 of file autoprewarm.c.
References apw_detach_shmem(), apw_dump_now(), apw_init_shmem(), apw_load_buffers(), apw_state, autoprewarm_interval, BackgroundWorkerUnblockSignals(), AutoPrewarmSharedState::bgworker_pid, ConfigReloadPending, ereport, errmsg(), GetCurrentTimestamp(), InvalidPid, AutoPrewarmSharedState::lock, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyLatch, MyProcPid, on_shmem_exit(), PGC_SIGHUP, pqsignal(), ProcessConfigFile(), procsignal_sigusr1_handler(), ResetLatch(), ShutdownRequestPending, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGUSR1, TimestampDifferenceMilliseconds(), TimestampTzPlusMilliseconds, WAIT_EVENT_EXTENSION, WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.
|
static |
Definition at line 155 of file autoprewarm.c.
References MAXALIGN, prev_shmem_request_hook, and RequestAddinShmemSpace().
Referenced by _PG_init().
Datum autoprewarm_start_worker | ( | PG_FUNCTION_ARGS | ) |
Definition at line 723 of file autoprewarm.c.
References apw_init_shmem(), apw_start_leader_worker(), apw_state, autoprewarm, AutoPrewarmSharedState::bgworker_pid, ereport, errcode(), errmsg(), ERROR, InvalidPid, AutoPrewarmSharedState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), and PG_RETURN_VOID.
PG_FUNCTION_INFO_V1 | ( | autoprewarm_dump_now | ) |
PG_FUNCTION_INFO_V1 | ( | autoprewarm_start_worker | ) |
|
static |
Definition at line 102 of file autoprewarm.c.
Referenced by apw_detach_shmem(), apw_dump_now(), apw_init_shmem(), apw_load_buffers(), autoprewarm_database_main(), autoprewarm_main(), and autoprewarm_start_worker().
Definition at line 105 of file autoprewarm.c.
Referenced by _PG_init(), and autoprewarm_start_worker().
|
static |
Definition at line 106 of file autoprewarm.c.
Referenced by _PG_init(), and autoprewarm_main().
|
static |
Definition at line 99 of file autoprewarm.c.
Referenced by _PG_init(), and autoprewarm_shmem_request().