141 #define WRITES_PER_ABSORB 1000 185 sigjmp_buf local_sigjmp_buf;
246 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
340 bool do_checkpoint =
false;
362 do_checkpoint =
true;
378 do_checkpoint =
true;
387 bool ckpt_performed =
false;
388 bool do_restartpoint;
415 do_restartpoint =
false;
424 if (!do_restartpoint &&
428 (
errmsg_plural(
"checkpoints are occurring too frequently (%d second apart)",
429 "checkpoints are occurring too frequently (%d seconds apart)",
432 errhint(
"Consider increasing the configuration parameter \"max_wal_size\".")));
449 if (!do_restartpoint)
452 ckpt_performed =
true;
479 last_checkpoint_time =
now;
536 cur_timeout * 1000L ,
638 elog(
DEBUG1,
"write-ahead log switch forced (archive_timeout=%d)",
726 else if (--absorb_counter <= 0)
755 double elapsed_xlogs,
799 if (progress < elapsed_xlogs)
812 if (progress < elapsed_time)
832 int save_errno = errno;
890 MemSet(CheckpointerShmem, 0, size);
969 #define MAX_SIGNAL_TRIES 600 970 for (ntries = 0;; ntries++)
977 "could not signal for checkpoint: checkpointer is not running");
986 "could not signal for checkpoint: %m");
1014 if (new_started != old_started)
1031 new_done = CheckpointerShmem->
ckpt_done;
1035 if (new_done - new_started >= 0)
1043 if (new_failed != old_failed)
1045 (
errmsg(
"checkpoint request failed"),
1046 errhint(
"Consult recent messages in the server log for details.")));
1080 elog(
ERROR,
"ForwardSyncRequest must not be called in checkpointer");
1109 request->
ftag = *ftag;
1144 struct CheckpointerSlotMapping
1152 int num_skipped = 0;
1165 ctl.
entrysize =
sizeof(
struct CheckpointerSlotMapping);
1168 htab =
hash_create(
"CompactCheckpointerRequestQueue",
1188 struct CheckpointerSlotMapping *slotmap;
1198 request = &CheckpointerShmem->
requests[n];
1203 skip_slot[slotmap->slot] =
true;
1226 CheckpointerShmem->
requests[preserve_count++] = CheckpointerShmem->
requests[n];
1229 (
errmsg_internal(
"compacted fsync request queue from %d entries to %d entries",
1289 for (request = requests; n > 0; request++, n--)
1313 elog(
DEBUG2,
"checkpointer updated shared memory configuration values");
1323 static int ckpt_done = 0;
1325 bool FirstCall =
false;
1328 new_done = CheckpointerShmem->
ckpt_done;
1331 if (new_done != ckpt_done)
1334 ckpt_done = new_done;
XLogRecPtr GetLastImportantRecPtr(void)
PgStat_Counter m_buf_fsync_backend
void SyncRepUpdateSyncStandbysDefined(void)
void RememberSyncRequest(const FileTag *ftag, SyncRequestType type)
bool IsPostmasterEnvironment
void CheckpointWriteDelay(int flags, double progress)
void hash_destroy(HTAB *hashp)
static bool IsCheckpointOnSchedule(double progress)
int gettimeofday(struct timeval *tp, struct timezone *tzp)
#define AllocSetContextCreate
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
XLogRecPtr GetInsertRecPtr(void)
int errhint(const char *fmt,...)
pg_time_t GetLastSegSwitchData(XLogRecPtr *lastSwitchLSN)
void ProcessConfigFile(GucContext context)
static void ReqCheckpointHandler(SIGNAL_ARGS)
bool LWLockHeldByMe(LWLock *l)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
void CreateCheckPoint(int flags)
PgStat_Counter m_timed_checkpoints
void AtEOXact_Buffers(bool isCommit)
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void ReleaseAuxProcessResources(bool isCommit)
#define SpinLockInit(lock)
void ProcessProcSignalBarrier(void)
static void HandleCheckpointerInterrupts(void)
#define END_CRIT_SECTION()
bool CreateRestartPoint(int flags)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
void CheckpointerShmemInit(void)
PgStat_MsgBgWriter BgWriterStats
CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER]
#define FLEXIBLE_ARRAY_MEMBER
#define START_CRIT_SECTION()
void ConditionVariableBroadcast(ConditionVariable *cv)
#define MemSet(start, val, len)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
bool RecoveryInProgress(void)
void SetLatch(Latch *latch)
void FlushErrorState(void)
void ResetLatch(Latch *latch)
void AtEOXact_Files(bool isCommit)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
void LWLockRelease(LWLock *lock)
#define RESUME_INTERRUPTS()
ErrorContextCallback * error_context_stack
void ConditionVariablePrepareToSleep(ConditionVariable *cv)
#define CHECKPOINT_CAUSE_XLOG
PgStat_Counter m_requested_checkpoints
#define SpinLockAcquire(lock)
static bool ImmediateCheckpointRequested(void)
void ConditionVariableInit(ConditionVariable *cv)
void pg_usleep(long microsec)
void AbsorbSyncRequests(void)
void pfree(void *pointer)
void ConditionVariableCancelSleep(void)
#define AmBackgroundWriterProcess()
#define AmCheckpointerProcess()
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
static bool CompactCheckpointerRequestQueue(void)
bool ForwardSyncRequest(const FileTag *ftag, SyncRequestType type)
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
#define ALLOCSET_DEFAULT_SIZES
#define CHECKPOINT_REQUESTED
#define CHECKPOINT_END_OF_RECOVERY
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
static void pgstat_report_wait_end(void)
MemoryContext CurrentMemoryContext
MemoryContext TopMemoryContext
volatile sig_atomic_t ShutdownRequestPending
ConditionVariable done_cv
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
static CheckpointerShmemStruct * CheckpointerShmem
void ShutdownXLOG(int code, Datum arg)
#define MemoryContextResetAndDeleteChildren(ctx)
#define SpinLockRelease(lock)
static void UpdateSharedMemoryConfig(void)
Size mul_size(Size s1, Size s2)
void UpdateFullPageWrites(void)
void * palloc0(Size size)
bool FirstCallSinceLastCheckpoint(void)
Size add_size(Size s1, Size s2)
#define WRITES_PER_ABSORB
void pgstat_send_wal(void)
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
Size CheckpointerShmemSize(void)
void EmitErrorReport(void)
static pg_time_t last_xlog_switch_time
void pgstat_send_bgwriter(void)
uint32 num_backend_writes
void CheckpointerMain(void)
#define ereport(elevel,...)
static pg_time_t ckpt_start_time
pqsigfunc pqsignal(int signum, pqsigfunc handler)
static XLogRecPtr ckpt_start_recptr
Latch * checkpointerLatch
int errmsg_internal(const char *fmt,...)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
#define Assert(condition)
volatile sig_atomic_t ProcSignalBarrierPending
PgStat_Counter m_buf_written_backend
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
static double elapsed_time(instr_time *starttime)
sigjmp_buf * PG_exception_stack
int errmsg(const char *fmt,...)
static double ckpt_cached_elapsed
static void CheckArchiveTimeout(void)
#define HOLD_INTERRUPTS()
volatile sig_atomic_t ConfigReloadPending
#define CHECKPOINT_CAUSE_TIME
#define CHECKPOINT_IMMEDIATE
#define CHECK_FOR_INTERRUPTS()
void LWLockReleaseAll(void)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
void AtEOXact_HashTables(bool isCommit)
static pg_time_t last_checkpoint_time
Datum now(PG_FUNCTION_ARGS)
#define offsetof(type, field)
#define WL_EXIT_ON_PM_DEATH
void RequestCheckpoint(int flags)
double CheckPointCompletionTarget
ConditionVariable start_cv