146#define WRITES_PER_ABSORB 1000
149#define CKPT_REQ_BATCH_SIZE 10000
152#define MAX_CHECKPOINT_REQUESTS 10000000
197 sigjmp_buf local_sigjmp_buf;
200 Assert(startup_data_len == 0);
276 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
364 bool do_checkpoint =
false;
369 bool chkpt_or_rstpt_requested =
false;
370 bool chkpt_or_rstpt_timed =
false;
391 do_checkpoint =
true;
392 chkpt_or_rstpt_requested =
true;
406 chkpt_or_rstpt_timed =
true;
407 do_checkpoint =
true;
416 bool ckpt_performed =
false;
417 bool do_restartpoint;
440 do_restartpoint =
false;
442 if (chkpt_or_rstpt_timed)
444 chkpt_or_rstpt_timed =
false;
451 if (chkpt_or_rstpt_requested)
453 chkpt_or_rstpt_requested =
false;
467 if (!do_restartpoint &&
471 (
errmsg_plural(
"checkpoints are occurring too frequently (%d second apart)",
472 "checkpoints are occurring too frequently (%d seconds apart)",
475 errhint(
"Consider increasing the configuration parameter \"%s\".",
"max_wal_size")));
492 if (!do_restartpoint)
514 if (!do_restartpoint)
595 cur_timeout * 1000L ,
596 WAIT_EVENT_CHECKPOINTER_MAIN);
644 WAIT_EVENT_CHECKPOINTER_SHUTDOWN);
740 elog(
DEBUG1,
"write-ahead log switch forced (\"archive_timeout\"=%d)",
827 WAIT_EVENT_CHECKPOINT_WRITE_DELAY);
830 else if (--absorb_counter <= 0)
859 double elapsed_xlogs,
1009 bool unlogged =
false;
1013 if (strcmp(opt->defname,
"mode") == 0)
1017 if (strcmp(
mode,
"spread") == 0)
1019 else if (strcmp(
mode,
"fast") != 0)
1021 (
errcode(ERRCODE_SYNTAX_ERROR),
1022 errmsg(
"unrecognized MODE option \"%s\"",
mode),
1025 else if (strcmp(opt->defname,
"flush_unlogged") == 0)
1029 (
errcode(ERRCODE_SYNTAX_ERROR),
1030 errmsg(
"unrecognized CHECKPOINT option \"%s\"", opt->defname),
1036 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1038 errmsg(
"permission denied to execute %s command",
1040 errdetail(
"Only roles with privileges of the \"%s\" role may execute this command.",
1117#define MAX_SIGNAL_TRIES 600
1118 for (ntries = 0;; ntries++)
1128 "could not notify checkpoint: checkpointer is not running");
1160 if (new_started != old_started)
1164 WAIT_EVENT_CHECKPOINT_START);
1181 if (new_done - new_started >= 0)
1185 WAIT_EVENT_CHECKPOINT_DONE);
1189 if (new_failed != old_failed)
1191 (
errmsg(
"checkpoint request failed"),
1192 errhint(
"Consult recent messages in the server log for details.")));
1227 elog(
ERROR,
"ForwardSyncRequest must not be called in checkpointer");
1247 request->
ftag = *ftag;
1291 struct CheckpointerSlotMapping
1298 int num_skipped = 0;
1319 skip_slot =
palloc0(
sizeof(
bool) * max_requests);
1325 ctl.entrysize =
sizeof(
struct CheckpointerSlotMapping);
1328 htab =
hash_create(
"CompactCheckpointerRequestQueue",
1346 for (n = 0; n < num_requests; n++)
1349 struct CheckpointerSlotMapping *slotmap;
1364 skip_slot[slotmap->ring_idx] =
true;
1368 slotmap->ring_idx = read_idx;
1371 read_idx = (read_idx + 1) % max_requests;
1385 read_idx = write_idx = head;
1386 for (n = 0; n < num_requests; n++)
1389 if (!skip_slot[read_idx])
1392 if (write_idx != read_idx)
1397 write_idx = (write_idx + 1) % max_requests;
1400 read_idx = (read_idx + 1) % max_requests;
1411 (
errmsg_internal(
"compacted fsync request queue from %d entries to %d entries",
1469 for (
i = 0;
i < n;
i++)
1486 for (request = requests; n > 0; request++, n--)
1511 elog(
DEBUG2,
"checkpointer updated shared memory configuration values");
1521 static int ckpt_done = 0;
1523 bool FirstCall =
false;
1529 if (new_done != ckpt_done)
1532 ckpt_done = new_done;
bool has_privs_of_role(Oid member, Oid role)
void pgaio_error_cleanup(void)
void AuxiliaryProcessMainCommon(void)
Datum now(PG_FUNCTION_ARGS)
void AtEOXact_Buffers(bool isCommit)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
static void UpdateSharedMemoryConfig(void)
static bool FastCheckpointRequested(void)
static XLogRecPtr ckpt_start_recptr
static bool IsCheckpointOnSchedule(double progress)
bool ForwardSyncRequest(const FileTag *ftag, SyncRequestType type)
static void ReqShutdownXLOG(SIGNAL_ARGS)
static void CheckArchiveTimeout(void)
static double ckpt_cached_elapsed
void CheckpointerMain(const void *startup_data, size_t startup_data_len)
static bool CompactCheckpointerRequestQueue(void)
static void ProcessCheckpointerInterrupts(void)
static volatile sig_atomic_t ShutdownXLOGPending
#define CKPT_REQ_BATCH_SIZE
void AbsorbSyncRequests(void)
#define WRITES_PER_ABSORB
double CheckPointCompletionTarget
static pg_time_t last_xlog_switch_time
#define MAX_CHECKPOINT_REQUESTS
void CheckpointerShmemInit(void)
bool FirstCallSinceLastCheckpoint(void)
static CheckpointerShmemStruct * CheckpointerShmem
void RequestCheckpoint(int flags)
static pg_time_t last_checkpoint_time
void ExecCheckpoint(ParseState *pstate, CheckPointStmt *stmt)
void CheckpointWriteDelay(int flags, double progress)
static pg_time_t ckpt_start_time
Size CheckpointerShmemSize(void)
bool ConditionVariableCancelSleep(void)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariablePrepareToSleep(ConditionVariable *cv)
void ConditionVariableInit(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
char * defGetString(DefElem *def)
bool defGetBoolean(DefElem *def)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void AtEOXact_HashTables(bool isCommit)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void hash_destroy(HTAB *hashp)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errmsg_internal(const char *fmt,...)
void EmitErrorReport(void)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
void FlushErrorState(void)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
sigjmp_buf * PG_exception_stack
#define ereport(elevel,...)
static double elapsed_time(instr_time *starttime)
void AtEOXact_Files(bool isCommit)
volatile sig_atomic_t LogMemoryContextPending
volatile sig_atomic_t ProcSignalBarrierPending
volatile uint32 CritSectionCount
bool IsPostmasterEnvironment
void ProcessConfigFile(GucContext context)
Assert(PointerIsAligned(start, uint64))
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
volatile sig_atomic_t ShutdownRequestPending
volatile sig_atomic_t ConfigReloadPending
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
void SetLatch(Latch *latch)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
bool LWLockHeldByMe(LWLock *lock)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void LWLockReleaseAll(void)
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext TopMemoryContext
MemoryContext CurrentMemoryContext
void ProcessLogMemoryContextInterrupt(void)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define AmCheckpointerProcess()
#define RESUME_INTERRUPTS()
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define HOLD_INTERRUPTS()
#define END_CRIT_SECTION()
BackendType MyBackendType
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
int parser_errposition(ParseState *pstate, int location)
static PgChecksumMode mode
#define foreach_ptr(type, var, lst)
void pgstat_before_server_shutdown(int code, Datum arg)
void pgstat_report_checkpointer(void)
PgStat_CheckpointerStats PendingCheckpointerStats
void pgstat_report_wal(bool force)
void SendPostmasterSignal(PMSignalReason reason)
@ PMSIGNAL_XLOG_IS_SHUTDOWN
#define GetPGProcByNumber(n)
#define INVALID_PROC_NUMBER
void ProcessProcSignalBarrier(void)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
void ReleaseAuxProcessResources(bool isCommit)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
void pg_usleep(long microsec)
void smgrdestroyall(void)
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
ConditionVariable done_cv
ConditionVariable start_cv
CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER]
ProcNumber checkpointerProc
PgStat_Counter restartpoints_requested
PgStat_Counter num_requested
PgStat_Counter num_performed
PgStat_Counter restartpoints_timed
PgStat_Counter restartpoints_performed
void RememberSyncRequest(const FileTag *ftag, SyncRequestType type)
void SyncRepUpdateSyncStandbysDefined(void)
static void pgstat_report_wait_end(void)
#define WL_EXIT_ON_PM_DEATH
int gettimeofday(struct timeval *tp, void *tzp)
void UpdateFullPageWrites(void)
bool RecoveryInProgress(void)
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
bool CreateRestartPoint(int flags)
XLogRecPtr GetInsertRecPtr(void)
void ShutdownXLOG(int code, Datum arg)
pg_time_t GetLastSegSwitchData(XLogRecPtr *lastSwitchLSN)
XLogRecPtr GetLastImportantRecPtr(void)
bool CreateCheckPoint(int flags)
#define CHECKPOINT_FLUSH_UNLOGGED
#define CHECKPOINT_CAUSE_XLOG
#define CHECKPOINT_END_OF_RECOVERY
#define CHECKPOINT_CAUSE_TIME
#define CHECKPOINT_REQUESTED
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)