139 #define WRITES_PER_ABSORB 1000
183 sigjmp_buf local_sigjmp_buf;
254 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
347 bool do_checkpoint =
false;
369 do_checkpoint =
true;
385 do_checkpoint =
true;
394 bool ckpt_performed =
false;
395 bool do_restartpoint;
418 do_restartpoint =
false;
427 if (!do_restartpoint &&
431 (
errmsg_plural(
"checkpoints are occurring too frequently (%d second apart)",
432 "checkpoints are occurring too frequently (%d seconds apart)",
435 errhint(
"Consider increasing the configuration parameter \"max_wal_size\".")));
452 if (!do_restartpoint)
455 ckpt_performed =
true;
534 cur_timeout * 1000L ,
535 WAIT_EVENT_CHECKPOINTER_MAIN);
651 elog(
DEBUG1,
"write-ahead log switch forced (archive_timeout=%d)",
737 WAIT_EVENT_CHECKPOINT_WRITE_DELAY);
740 else if (--absorb_counter <= 0)
769 double elapsed_xlogs,
846 int save_errno = errno;
983 #define MAX_SIGNAL_TRIES 600
984 for (ntries = 0;; ntries++)
991 "could not signal for checkpoint: checkpointer is not running");
1000 "could not signal for checkpoint: %m");
1028 if (new_started != old_started)
1032 WAIT_EVENT_CHECKPOINT_START);
1049 if (new_done - new_started >= 0)
1053 WAIT_EVENT_CHECKPOINT_DONE);
1057 if (new_failed != old_failed)
1059 (
errmsg(
"checkpoint request failed"),
1060 errhint(
"Consult recent messages in the server log for details.")));
1094 elog(
ERROR,
"ForwardSyncRequest must not be called in checkpointer");
1123 request->
ftag = *ftag;
1158 struct CheckpointerSlotMapping
1166 int num_skipped = 0;
1179 ctl.
entrysize =
sizeof(
struct CheckpointerSlotMapping);
1182 htab =
hash_create(
"CompactCheckpointerRequestQueue",
1202 struct CheckpointerSlotMapping *slotmap;
1217 skip_slot[slotmap->slot] =
true;
1243 (
errmsg_internal(
"compacted fsync request queue from %d entries to %d entries",
1305 for (request = requests; n > 0; request++, n--)
1329 elog(
DEBUG2,
"checkpointer updated shared memory configuration values");
1339 static int ckpt_done = 0;
1341 bool FirstCall =
false;
1347 if (new_done != ckpt_done)
1350 ckpt_done = new_done;
Datum now(PG_FUNCTION_ARGS)
void AtEOXact_Buffers(bool isCommit)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
static void UpdateSharedMemoryConfig(void)
static XLogRecPtr ckpt_start_recptr
static bool ImmediateCheckpointRequested(void)
static bool IsCheckpointOnSchedule(double progress)
static void ReqCheckpointHandler(SIGNAL_ARGS)
bool ForwardSyncRequest(const FileTag *ftag, SyncRequestType type)
static void CheckArchiveTimeout(void)
static double ckpt_cached_elapsed
static bool CompactCheckpointerRequestQueue(void)
static void HandleCheckpointerInterrupts(void)
void CheckpointerMain(void)
void AbsorbSyncRequests(void)
#define WRITES_PER_ABSORB
double CheckPointCompletionTarget
static pg_time_t last_xlog_switch_time
void CheckpointerShmemInit(void)
bool FirstCallSinceLastCheckpoint(void)
static CheckpointerShmemStruct * CheckpointerShmem
void RequestCheckpoint(int flags)
static pg_time_t last_checkpoint_time
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)
elog(ERROR, "%s: %s", p2, msg)
void AtEOXact_HashTables(bool isCommit)
void hash_destroy(HTAB *hashp)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errmsg_internal(const char *fmt,...)
void EmitErrorReport(void)
ErrorContextCallback * error_context_stack
void FlushErrorState(void)
int errhint(const char *fmt,...)
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
bool IsPostmasterEnvironment
void ProcessConfigFile(GucContext context)
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)
#define WL_EXIT_ON_PM_DEATH
Assert(fmt[strlen(fmt) - 1] !='\n')
bool LWLockHeldByMe(LWLock *lock)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void LWLockReleaseAll(void)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void ProcessLogMemoryContextInterrupt(void)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define MemoryContextResetAndDeleteChildren(ctx)
#define AmCheckpointerProcess()
#define RESUME_INTERRUPTS()
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define AmBackgroundWriterProcess()
#define HOLD_INTERRUPTS()
#define END_CRIT_SECTION()
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
void pgstat_before_server_shutdown(int code, Datum arg)
void pgstat_report_checkpointer(void)
PgStat_CheckpointerStats PendingCheckpointerStats
void pgstat_report_wal(bool force)
pqsigfunc pqsignal(int signo, pqsigfunc func)
void ProcessProcSignalBarrier(void)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
void ReleaseAuxProcessResources(bool isCommit)
Size add_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Size mul_size(Size s1, Size s2)
void pg_usleep(long microsec)
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
ConditionVariable done_cv
ConditionVariable start_cv
uint32 num_backend_writes
CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER]
Latch * checkpointerLatch
PgStat_Counter buf_written_backend
PgStat_Counter requested_checkpoints
PgStat_Counter timed_checkpoints
PgStat_Counter buf_fsync_backend
void RememberSyncRequest(const FileTag *ftag, SyncRequestType type)
void SyncRepUpdateSyncStandbysDefined(void)
static void pgstat_report_wait_end(void)
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)
void CreateCheckPoint(int flags)
#define CHECKPOINT_CAUSE_XLOG
#define CHECKPOINT_END_OF_RECOVERY
#define CHECKPOINT_CAUSE_TIME
#define CHECKPOINT_REQUESTED
#define CHECKPOINT_IMMEDIATE
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)