PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bgwriter.h File Reference
#include "storage/block.h"
#include "storage/relfilelocator.h"
#include "storage/smgr.h"
#include "storage/sync.h"
Include dependency graph for bgwriter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

pg_noreturn void BackgroundWriterMain (const void *startup_data, size_t startup_data_len)
 
pg_noreturn void CheckpointerMain (const void *startup_data, size_t startup_data_len)
 
void RequestCheckpoint (int flags)
 
void CheckpointWriteDelay (int flags, double progress)
 
bool ForwardSyncRequest (const FileTag *ftag, SyncRequestType type)
 
void AbsorbSyncRequests (void)
 
Size CheckpointerShmemSize (void)
 
void CheckpointerShmemInit (void)
 
bool FirstCallSinceLastCheckpoint (void)
 

Variables

PGDLLIMPORT int BgWriterDelay
 
PGDLLIMPORT int CheckPointTimeout
 
PGDLLIMPORT int CheckPointWarning
 
PGDLLIMPORT double CheckPointCompletionTarget
 

Function Documentation

◆ AbsorbSyncRequests()

void AbsorbSyncRequests ( void  )

Definition at line 1328 of file checkpointer.c.

1329{
1330 CheckpointerRequest *requests = NULL;
1331 CheckpointerRequest *request;
1332 int n;
1333
1334 if (!AmCheckpointerProcess())
1335 return;
1336
1337 LWLockAcquire(CheckpointerCommLock, LW_EXCLUSIVE);
1338
1339 /*
1340 * We try to avoid holding the lock for a long time by copying the request
1341 * array, and processing the requests after releasing the lock.
1342 *
1343 * Once we have cleared the requests from shared memory, we have to PANIC
1344 * if we then fail to absorb them (eg, because our hashtable runs out of
1345 * memory). This is because the system cannot run safely if we are unable
1346 * to fsync what we have been told to fsync. Fortunately, the hashtable
1347 * is so small that the problem is quite unlikely to arise in practice.
1348 */
1350 if (n > 0)
1351 {
1352 requests = (CheckpointerRequest *) palloc(n * sizeof(CheckpointerRequest));
1353 memcpy(requests, CheckpointerShmem->requests, n * sizeof(CheckpointerRequest));
1354 }
1355
1357
1359
1360 LWLockRelease(CheckpointerCommLock);
1361
1362 for (request = requests; n > 0; request++, n--)
1363 RememberSyncRequest(&request->ftag, request->type);
1364
1366
1367 if (requests)
1368 pfree(requests);
1369}
static CheckpointerShmemStruct * CheckpointerShmem
Definition: checkpointer.c:133
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1182
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1902
@ LW_EXCLUSIVE
Definition: lwlock.h:114
void pfree(void *pointer)
Definition: mcxt.c:2147
void * palloc(Size size)
Definition: mcxt.c:1940
#define AmCheckpointerProcess()
Definition: miscadmin.h:389
#define START_CRIT_SECTION()
Definition: miscadmin.h:150
#define END_CRIT_SECTION()
Definition: miscadmin.h:152
SyncRequestType type
Definition: checkpointer.c:109
CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER]
Definition: checkpointer.c:130
void RememberSyncRequest(const FileTag *ftag, SyncRequestType type)
Definition: sync.c:487

References AmCheckpointerProcess, CheckpointerShmem, END_CRIT_SECTION, CheckpointerRequest::ftag, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), CheckpointerShmemStruct::num_requests, palloc(), pfree(), RememberSyncRequest(), CheckpointerShmemStruct::requests, START_CRIT_SECTION, and CheckpointerRequest::type.

Referenced by CheckpointerMain(), CheckpointWriteDelay(), CreateCheckPoint(), ProcessSyncRequests(), SyncPostCheckpoint(), and SyncPreCheckpoint().

◆ BackgroundWriterMain()

pg_noreturn void BackgroundWriterMain ( const void *  startup_data,
size_t  startup_data_len 
)

Definition at line 88 of file bgwriter.c.

89{
90 sigjmp_buf local_sigjmp_buf;
91 MemoryContext bgwriter_context;
92 bool prev_hibernate;
93 WritebackContext wb_context;
94
95 Assert(startup_data_len == 0);
96
99
100 /*
101 * Properly accept or ignore signals that might be sent to us.
102 */
104 pqsignal(SIGINT, SIG_IGN);
106 /* SIGQUIT handler was already set up by InitPostmasterChild */
107 pqsignal(SIGALRM, SIG_IGN);
108 pqsignal(SIGPIPE, SIG_IGN);
110 pqsignal(SIGUSR2, SIG_IGN);
111
112 /*
113 * Reset some signals that are accepted by postmaster but not here
114 */
115 pqsignal(SIGCHLD, SIG_DFL);
116
117 /*
118 * We just started, assume there has been either a shutdown or
119 * end-of-recovery snapshot.
120 */
122
123 /*
124 * Create a memory context that we will do all our work in. We do this so
125 * that we can reset the context during error recovery and thereby avoid
126 * possible memory leaks. Formerly this code just ran in
127 * TopMemoryContext, but resetting that would be a really bad idea.
128 */
129 bgwriter_context = AllocSetContextCreate(TopMemoryContext,
130 "Background Writer",
132 MemoryContextSwitchTo(bgwriter_context);
133
135
136 /*
137 * If an exception is encountered, processing resumes here.
138 *
139 * You might wonder why this isn't coded as an infinite loop around a
140 * PG_TRY construct. The reason is that this is the bottom of the
141 * exception stack, and so with PG_TRY there would be no exception handler
142 * in force at all during the CATCH part. By leaving the outermost setjmp
143 * always active, we have at least some chance of recovering from an error
144 * during error recovery. (If we get into an infinite loop thereby, it
145 * will soon be stopped by overflow of elog.c's internal state stack.)
146 *
147 * Note that we use sigsetjmp(..., 1), so that the prevailing signal mask
148 * (to wit, BlockSig) will be restored when longjmp'ing to here. Thus,
149 * signals other than SIGQUIT will be blocked until we complete error
150 * recovery. It might seem that this policy makes the HOLD_INTERRUPTS()
151 * call redundant, but it is not since InterruptPending might be set
152 * already.
153 */
154 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
155 {
156 /* Since not using PG_TRY, must reset error stack by hand */
157 error_context_stack = NULL;
158
159 /* Prevent interrupts while cleaning up */
161
162 /* Report the error to the server log */
164
165 /*
166 * These operations are really just a minimal subset of
167 * AbortTransaction(). We don't have very many resources to worry
168 * about in bgwriter, but we do have LWLocks, buffers, and temp files.
169 */
175 AtEOXact_Buffers(false);
177 AtEOXact_Files(false);
178 AtEOXact_HashTables(false);
179
180 /*
181 * Now return to normal top-level context and clear ErrorContext for
182 * next time.
183 */
184 MemoryContextSwitchTo(bgwriter_context);
186
187 /* Flush any leaked data in the top-level context */
188 MemoryContextReset(bgwriter_context);
189
190 /* re-initialize to avoid repeated errors causing problems */
192
193 /* Now we can allow interrupts again */
195
196 /*
197 * Sleep at least 1 second after any error. A write error is likely
198 * to be repeated, and we don't want to be filling the error logs as
199 * fast as we can.
200 */
201 pg_usleep(1000000L);
202
203 /* Report wait end here, when there is no further possibility of wait */
205 }
206
207 /* We can now handle ereport(ERROR) */
208 PG_exception_stack = &local_sigjmp_buf;
209
210 /*
211 * Unblock signals (they were blocked when the postmaster forked us)
212 */
213 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
214
215 /*
216 * Reset hibernation state after any error.
217 */
218 prev_hibernate = false;
219
220 /*
221 * Loop forever
222 */
223 for (;;)
224 {
225 bool can_hibernate;
226 int rc;
227
228 /* Clear any already-pending wakeups */
230
232
233 /*
234 * Do one cycle of dirty-buffer writing.
235 */
236 can_hibernate = BgBufferSync(&wb_context);
237
238 /* Report pending statistics to the cumulative stats system */
240 pgstat_report_wal(true);
241
243 {
244 /*
245 * After any checkpoint, free all smgr objects. Otherwise we
246 * would never do so for dropped relations, as the bgwriter does
247 * not process shared invalidation messages or call
248 * AtEOXact_SMgr().
249 */
251 }
252
253 /*
254 * Log a new xl_running_xacts every now and then so replication can
255 * get into a consistent state faster (think of suboverflowed
256 * snapshots) and clean up resources (locks, KnownXids*) more
257 * frequently. The costs of this are relatively low, so doing it 4
258 * times (LOG_SNAPSHOT_INTERVAL_MS) a minute seems fine.
259 *
260 * We assume the interval for writing xl_running_xacts is
261 * significantly bigger than BgWriterDelay, so we don't complicate the
262 * overall timeout handling but just assume we're going to get called
263 * often enough even if hibernation mode is active. It's not that
264 * important that LOG_SNAPSHOT_INTERVAL_MS is met strictly. To make
265 * sure we're not waking the disk up unnecessarily on an idle system
266 * we check whether there has been any WAL inserted since the last
267 * time we've logged a running xacts.
268 *
269 * We do this logging in the bgwriter as it is the only process that
270 * is run regularly and returns to its mainloop all the time. E.g.
271 * Checkpointer, when active, is barely ever in its mainloop and thus
272 * makes it hard to log regularly.
273 */
275 {
276 TimestampTz timeout = 0;
278
281
282 /*
283 * Only log if enough time has passed and interesting records have
284 * been inserted since the last snapshot. Have to compare with <=
285 * instead of < because GetLastImportantRecPtr() points at the
286 * start of a record, whereas last_snapshot_lsn points just past
287 * the end of the record.
288 */
289 if (now >= timeout &&
291 {
294 }
295 }
296
297 /*
298 * Sleep until we are signaled or BgWriterDelay has elapsed.
299 *
300 * Note: the feedback control loop in BgBufferSync() expects that we
301 * will call it every BgWriterDelay msec. While it's not critical for
302 * correctness that that be exact, the feedback loop might misbehave
303 * if we stray too far from that. Hence, avoid loading this process
304 * down with latch events that are likely to happen frequently during
305 * normal operation.
306 */
307 rc = WaitLatch(MyLatch,
309 BgWriterDelay /* ms */ , WAIT_EVENT_BGWRITER_MAIN);
310
311 /*
312 * If no latch event and BgBufferSync says nothing's happening, extend
313 * the sleep in "hibernation" mode, where we sleep for much longer
314 * than bgwriter_delay says. Fewer wakeups save electricity. When a
315 * backend starts using buffers again, it will wake us up by setting
316 * our latch. Because the extra sleep will persist only as long as no
317 * buffer allocations happen, this should not distort the behavior of
318 * BgBufferSync's control loop too badly; essentially, it will think
319 * that the system-wide idle interval didn't exist.
320 *
321 * There is a race condition here, in that a backend might allocate a
322 * buffer between the time BgBufferSync saw the alloc count as zero
323 * and the time we call StrategyNotifyBgWriter. While it's not
324 * critical that we not hibernate anyway, we try to reduce the odds of
325 * that by only hibernating when BgBufferSync says nothing's happening
326 * for two consecutive cycles. Also, we mitigate any possible
327 * consequences of a missed wakeup by not hibernating forever.
328 */
329 if (rc == WL_TIMEOUT && can_hibernate && prev_hibernate)
330 {
331 /* Ask for notification at next buffer allocation */
333 /* Sleep ... */
334 (void) WaitLatch(MyLatch,
337 WAIT_EVENT_BGWRITER_HIBERNATE);
338 /* Reset the notification request in case we timed out */
340 }
341
342 prev_hibernate = can_hibernate;
343 }
344}
void pgaio_error_cleanup(void)
Definition: aio.c:1062
void AuxiliaryProcessMainCommon(void)
Definition: auxprocess.c:39
sigset_t UnBlockSig
Definition: pqsignal.c:22
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1645
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1609
static XLogRecPtr last_snapshot_lsn
Definition: bgwriter.c:78
static TimestampTz last_snapshot_ts
Definition: bgwriter.c:77
int BgWriterDelay
Definition: bgwriter.c:58
#define HIBERNATE_FACTOR
Definition: bgwriter.c:64
#define LOG_SNAPSHOT_INTERVAL_MS
Definition: bgwriter.c:70
void AtEOXact_Buffers(bool isCommit)
Definition: bufmgr.c:3996
bool BgBufferSync(WritebackContext *wb_context)
Definition: bufmgr.c:3625
void UnlockBuffers(void)
Definition: bufmgr.c:5579
int bgwriter_flush_after
Definition: bufmgr.c:179
void WritebackContextInit(WritebackContext *context, int *max_pending)
Definition: bufmgr.c:6401
bool FirstCallSinceLastCheckpoint(void)
bool ConditionVariableCancelSleep(void)
int64 TimestampTz
Definition: timestamp.h:39
void AtEOXact_HashTables(bool isCommit)
Definition: dynahash.c:1912
void EmitErrorReport(void)
Definition: elog.c:1709
ErrorContextCallback * error_context_stack
Definition: elog.c:95
void FlushErrorState(void)
Definition: elog.c:1889
sigjmp_buf * PG_exception_stack
Definition: elog.c:97
void AtEOXact_Files(bool isCommit)
Definition: fd.c:3229
void StrategyNotifyBgWriter(int bgwprocno)
Definition: freelist.c:431
ProcNumber MyProcNumber
Definition: globals.c:91
struct Latch * MyLatch
Definition: globals.c:64
Assert(PointerIsAligned(start, uint64))
void SignalHandlerForShutdownRequest(SIGNAL_ARGS)
Definition: interrupt.c:109
void ProcessMainLoopInterrupts(void)
Definition: interrupt.c:34
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition: interrupt.c:65
void ResetLatch(Latch *latch)
Definition: latch.c:372
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:172
void LWLockReleaseAll(void)
Definition: lwlock.c:1953
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:414
MemoryContext TopMemoryContext
Definition: mcxt.c:165
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:136
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:134
@ B_BG_WRITER
Definition: miscadmin.h:362
BackendType MyBackendType
Definition: miscinit.c:64
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void pgstat_report_bgwriter(void)
void pgstat_report_wal(bool force)
Definition: pgstat_wal.c:46
#define pqsignal
Definition: port.h:531
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:673
void ReleaseAuxProcessResources(bool isCommit)
Definition: resowner.c:1019
void pg_usleep(long microsec)
Definition: signal.c:53
void smgrdestroyall(void)
Definition: smgr.c:386
void AtEOXact_SMgr(void)
Definition: smgr.c:1008
XLogRecPtr LogStandbySnapshot(void)
Definition: standby.c:1282
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:85
static void pgstat_report_wait_end(void)
Definition: wait_event.h:101
#define WL_TIMEOUT
Definition: waiteventset.h:37
#define WL_EXIT_ON_PM_DEATH
Definition: waiteventset.h:39
#define WL_LATCH_SET
Definition: waiteventset.h:34
#define SIGCHLD
Definition: win32_port.h:168
#define SIGHUP
Definition: win32_port.h:158
#define SIGPIPE
Definition: win32_port.h:163
#define SIGUSR1
Definition: win32_port.h:170
#define SIGALRM
Definition: win32_port.h:164
#define SIGUSR2
Definition: win32_port.h:171
bool RecoveryInProgress(void)
Definition: xlog.c:6522
XLogRecPtr GetLastImportantRecPtr(void)
Definition: xlog.c:6744
#define XLogStandbyInfoActive()
Definition: xlog.h:123

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), AtEOXact_Buffers(), AtEOXact_Files(), AtEOXact_HashTables(), AtEOXact_SMgr(), AuxiliaryProcessMainCommon(), B_BG_WRITER, BgBufferSync(), bgwriter_flush_after, BgWriterDelay, ConditionVariableCancelSleep(), EmitErrorReport(), error_context_stack, FirstCallSinceLastCheckpoint(), FlushErrorState(), GetCurrentTimestamp(), GetLastImportantRecPtr(), HIBERNATE_FACTOR, HOLD_INTERRUPTS, last_snapshot_lsn, last_snapshot_ts, LOG_SNAPSHOT_INTERVAL_MS, LogStandbySnapshot(), LWLockReleaseAll(), MemoryContextReset(), MemoryContextSwitchTo(), MyBackendType, MyLatch, MyProcNumber, now(), PG_exception_stack, pg_usleep(), pgaio_error_cleanup(), pgstat_report_bgwriter(), pgstat_report_wait_end(), pgstat_report_wal(), pqsignal, ProcessMainLoopInterrupts(), procsignal_sigusr1_handler(), RecoveryInProgress(), ReleaseAuxProcessResources(), ResetLatch(), RESUME_INTERRUPTS, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, smgrdestroyall(), StrategyNotifyBgWriter(), TimestampTzPlusMilliseconds, TopMemoryContext, UnBlockSig, UnlockBuffers(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_TIMEOUT, WritebackContextInit(), and XLogStandbyInfoActive.

◆ CheckpointerMain()

pg_noreturn void CheckpointerMain ( const void *  startup_data,
size_t  startup_data_len 
)

Definition at line 179 of file checkpointer.c.

180{
181 sigjmp_buf local_sigjmp_buf;
182 MemoryContext checkpointer_context;
183
184 Assert(startup_data_len == 0);
185
188
190
191 /*
192 * Properly accept or ignore signals the postmaster might send us
193 *
194 * Note: we deliberately ignore SIGTERM, because during a standard Unix
195 * system shutdown cycle, init will SIGTERM all processes at once. We
196 * want to wait for the backends to exit, whereupon the postmaster will
197 * tell us it's okay to shut down (via SIGUSR2).
198 */
200 pqsignal(SIGINT, ReqShutdownXLOG);
201 pqsignal(SIGTERM, SIG_IGN); /* ignore SIGTERM */
202 /* SIGQUIT handler was already set up by InitPostmasterChild */
203 pqsignal(SIGALRM, SIG_IGN);
204 pqsignal(SIGPIPE, SIG_IGN);
207
208 /*
209 * Reset some signals that are accepted by postmaster but not here
210 */
211 pqsignal(SIGCHLD, SIG_DFL);
212
213 /*
214 * Initialize so that first time-driven event happens at the correct time.
215 */
217
218 /*
219 * Write out stats after shutdown. This needs to be called by exactly one
220 * process during a normal shutdown, and since checkpointer is shut down
221 * very late...
222 *
223 * While e.g. walsenders are active after the shutdown checkpoint has been
224 * written (and thus could produce more stats), checkpointer stays around
225 * after the shutdown checkpoint has been written. postmaster will only
226 * signal checkpointer to exit after all processes that could emit stats
227 * have been shut down.
228 */
230
231 /*
232 * Create a memory context that we will do all our work in. We do this so
233 * that we can reset the context during error recovery and thereby avoid
234 * possible memory leaks. Formerly this code just ran in
235 * TopMemoryContext, but resetting that would be a really bad idea.
236 */
237 checkpointer_context = AllocSetContextCreate(TopMemoryContext,
238 "Checkpointer",
240 MemoryContextSwitchTo(checkpointer_context);
241
242 /*
243 * If an exception is encountered, processing resumes here.
244 *
245 * You might wonder why this isn't coded as an infinite loop around a
246 * PG_TRY construct. The reason is that this is the bottom of the
247 * exception stack, and so with PG_TRY there would be no exception handler
248 * in force at all during the CATCH part. By leaving the outermost setjmp
249 * always active, we have at least some chance of recovering from an error
250 * during error recovery. (If we get into an infinite loop thereby, it
251 * will soon be stopped by overflow of elog.c's internal state stack.)
252 *
253 * Note that we use sigsetjmp(..., 1), so that the prevailing signal mask
254 * (to wit, BlockSig) will be restored when longjmp'ing to here. Thus,
255 * signals other than SIGQUIT will be blocked until we complete error
256 * recovery. It might seem that this policy makes the HOLD_INTERRUPTS()
257 * call redundant, but it is not since InterruptPending might be set
258 * already.
259 */
260 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
261 {
262 /* Since not using PG_TRY, must reset error stack by hand */
263 error_context_stack = NULL;
264
265 /* Prevent interrupts while cleaning up */
267
268 /* Report the error to the server log */
270
271 /*
272 * These operations are really just a minimal subset of
273 * AbortTransaction(). We don't have very many resources to worry
274 * about in checkpointer, but we do have LWLocks, buffers, and temp
275 * files.
276 */
283 AtEOXact_Buffers(false);
285 AtEOXact_Files(false);
286 AtEOXact_HashTables(false);
287
288 /* Warn any waiting backends that the checkpoint failed. */
289 if (ckpt_active)
290 {
295
297
298 ckpt_active = false;
299 }
300
301 /*
302 * Now return to normal top-level context and clear ErrorContext for
303 * next time.
304 */
305 MemoryContextSwitchTo(checkpointer_context);
307
308 /* Flush any leaked data in the top-level context */
309 MemoryContextReset(checkpointer_context);
310
311 /* Now we can allow interrupts again */
313
314 /*
315 * Sleep at least 1 second after any error. A write error is likely
316 * to be repeated, and we don't want to be filling the error logs as
317 * fast as we can.
318 */
319 pg_usleep(1000000L);
320 }
321
322 /* We can now handle ereport(ERROR) */
323 PG_exception_stack = &local_sigjmp_buf;
324
325 /*
326 * Unblock signals (they were blocked when the postmaster forked us)
327 */
328 sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
329
330 /*
331 * Ensure all shared memory values are set correctly for the config. Doing
332 * this here ensures no race conditions from other concurrent updaters.
333 */
335
336 /*
337 * Advertise our proc number that backends can use to wake us up while
338 * we're sleeping.
339 */
341
342 /*
343 * Loop until we've been asked to write the shutdown checkpoint or
344 * terminate.
345 */
346 for (;;)
347 {
348 bool do_checkpoint = false;
349 int flags = 0;
351 int elapsed_secs;
352 int cur_timeout;
353 bool chkpt_or_rstpt_requested = false;
354 bool chkpt_or_rstpt_timed = false;
355
356 /* Clear any already-pending wakeups */
358
359 /*
360 * Process any requests or signals received recently.
361 */
363
366 break;
367
368 /*
369 * Detect a pending checkpoint request by checking whether the flags
370 * word in shared memory is nonzero. We shouldn't need to acquire the
371 * ckpt_lck for this.
372 */
373 if (((volatile CheckpointerShmemStruct *) CheckpointerShmem)->ckpt_flags)
374 {
375 do_checkpoint = true;
376 chkpt_or_rstpt_requested = true;
377 }
378
379 /*
380 * Force a checkpoint if too much time has elapsed since the last one.
381 * Note that we count a timed checkpoint in stats only when this
382 * occurs without an external request, but we set the CAUSE_TIME flag
383 * bit even if there is also an external request.
384 */
385 now = (pg_time_t) time(NULL);
386 elapsed_secs = now - last_checkpoint_time;
387 if (elapsed_secs >= CheckPointTimeout)
388 {
389 if (!do_checkpoint)
390 chkpt_or_rstpt_timed = true;
391 do_checkpoint = true;
392 flags |= CHECKPOINT_CAUSE_TIME;
393 }
394
395 /*
396 * Do a checkpoint if requested.
397 */
398 if (do_checkpoint)
399 {
400 bool ckpt_performed = false;
401 bool do_restartpoint;
402
403 /* Check if we should perform a checkpoint or a restartpoint. */
404 do_restartpoint = RecoveryInProgress();
405
406 /*
407 * Atomically fetch the request flags to figure out what kind of a
408 * checkpoint we should perform, and increase the started-counter
409 * to acknowledge that we've started a new checkpoint.
410 */
416
418
419 /*
420 * The end-of-recovery checkpoint is a real checkpoint that's
421 * performed while we're still in recovery.
422 */
423 if (flags & CHECKPOINT_END_OF_RECOVERY)
424 do_restartpoint = false;
425
426 if (chkpt_or_rstpt_timed)
427 {
428 chkpt_or_rstpt_timed = false;
429 if (do_restartpoint)
431 else
433 }
434
435 if (chkpt_or_rstpt_requested)
436 {
437 chkpt_or_rstpt_requested = false;
438 if (do_restartpoint)
440 else
442 }
443
444 /*
445 * We will warn if (a) too soon since last checkpoint (whatever
446 * caused it) and (b) somebody set the CHECKPOINT_CAUSE_XLOG flag
447 * since the last checkpoint start. Note in particular that this
448 * implementation will not generate warnings caused by
449 * CheckPointTimeout < CheckPointWarning.
450 */
451 if (!do_restartpoint &&
452 (flags & CHECKPOINT_CAUSE_XLOG) &&
453 elapsed_secs < CheckPointWarning)
454 ereport(LOG,
455 (errmsg_plural("checkpoints are occurring too frequently (%d second apart)",
456 "checkpoints are occurring too frequently (%d seconds apart)",
457 elapsed_secs,
458 elapsed_secs),
459 errhint("Consider increasing the configuration parameter \"%s\".", "max_wal_size")));
460
461 /*
462 * Initialize checkpointer-private variables used during
463 * checkpoint.
464 */
465 ckpt_active = true;
466 if (do_restartpoint)
468 else
472
473 /*
474 * Do the checkpoint.
475 */
476 if (!do_restartpoint)
477 ckpt_performed = CreateCheckPoint(flags);
478 else
479 ckpt_performed = CreateRestartPoint(flags);
480
481 /*
482 * After any checkpoint, free all smgr objects. Otherwise we
483 * would never do so for dropped relations, as the checkpointer
484 * does not process shared invalidation messages or call
485 * AtEOXact_SMgr().
486 */
488
489 /*
490 * Indicate checkpoint completion to any waiting backends.
491 */
495
497
498 if (!do_restartpoint)
499 {
500 /*
501 * Note we record the checkpoint start time not end time as
502 * last_checkpoint_time. This is so that time-driven
503 * checkpoints happen at a predictable spacing.
504 */
506
507 if (ckpt_performed)
509 }
510 else
511 {
512 if (ckpt_performed)
513 {
514 /*
515 * The same as for checkpoint. Please see the
516 * corresponding comment.
517 */
519
521 }
522 else
523 {
524 /*
525 * We were not able to perform the restartpoint
526 * (checkpoints throw an ERROR in case of error). Most
527 * likely because we have not received any new checkpoint
528 * WAL records since the last restartpoint. Try again in
529 * 15 s.
530 */
532 }
533 }
534
535 ckpt_active = false;
536
537 /*
538 * We may have received an interrupt during the checkpoint and the
539 * latch might have been reset (e.g. in CheckpointWriteDelay).
540 */
543 break;
544 }
545
546 /* Check for archive_timeout and switch xlog files if necessary. */
548
549 /* Report pending statistics to the cumulative stats system */
551 pgstat_report_wal(true);
552
553 /*
554 * If any checkpoint flags have been set, redo the loop to handle the
555 * checkpoint without sleeping.
556 */
557 if (((volatile CheckpointerShmemStruct *) CheckpointerShmem)->ckpt_flags)
558 continue;
559
560 /*
561 * Sleep until we are signaled or it's time for another checkpoint or
562 * xlog file switch.
563 */
564 now = (pg_time_t) time(NULL);
565 elapsed_secs = now - last_checkpoint_time;
566 if (elapsed_secs >= CheckPointTimeout)
567 continue; /* no sleep for us ... */
568 cur_timeout = CheckPointTimeout - elapsed_secs;
570 {
571 elapsed_secs = now - last_xlog_switch_time;
572 if (elapsed_secs >= XLogArchiveTimeout)
573 continue; /* no sleep for us ... */
574 cur_timeout = Min(cur_timeout, XLogArchiveTimeout - elapsed_secs);
575 }
576
577 (void) WaitLatch(MyLatch,
579 cur_timeout * 1000L /* convert to ms */ ,
580 WAIT_EVENT_CHECKPOINTER_MAIN);
581 }
582
583 /*
584 * From here on, elog(ERROR) should end with exit(1), not send control
585 * back to the sigsetjmp block above.
586 */
587 ExitOnAnyError = true;
588
590 {
591 /*
592 * Close down the database.
593 *
594 * Since ShutdownXLOG() creates restartpoint or checkpoint, and
595 * updates the statistics, increment the checkpoint request and flush
596 * out pending statistic.
597 */
599 ShutdownXLOG(0, 0);
601 pgstat_report_wal(true);
602
603 /*
604 * Tell postmaster that we're done.
605 */
607 ShutdownXLOGPending = false;
608 }
609
610 /*
611 * Wait until we're asked to shut down. By separating the writing of the
612 * shutdown checkpoint from checkpointer exiting, checkpointer can perform
613 * some should-be-as-late-as-possible work like writing out stats.
614 */
615 for (;;)
616 {
617 /* Clear any already-pending wakeups */
619
621
623 break;
624
625 (void) WaitLatch(MyLatch,
627 0,
628 WAIT_EVENT_CHECKPOINTER_SHUTDOWN);
629 }
630
631 /* Normal exit from the checkpointer is here */
632 proc_exit(0); /* done */
633}
#define Min(x, y)
Definition: c.h:975
static void UpdateSharedMemoryConfig(void)
static XLogRecPtr ckpt_start_recptr
Definition: checkpointer.c:153
static void ReqShutdownXLOG(SIGNAL_ARGS)
Definition: checkpointer.c:922
static void CheckArchiveTimeout(void)
Definition: checkpointer.c:685
static double ckpt_cached_elapsed
Definition: checkpointer.c:154
static bool ckpt_active
Definition: checkpointer.c:148
static void ProcessCheckpointerInterrupts(void)
Definition: checkpointer.c:639
static volatile sig_atomic_t ShutdownXLOGPending
Definition: checkpointer.c:149
void AbsorbSyncRequests(void)
static pg_time_t last_xlog_switch_time
Definition: checkpointer.c:157
int CheckPointWarning
Definition: checkpointer.c:142
int CheckPointTimeout
Definition: checkpointer.c:141
static pg_time_t last_checkpoint_time
Definition: checkpointer.c:156
static pg_time_t ckpt_start_time
Definition: checkpointer.c:152
void ConditionVariableBroadcast(ConditionVariable *cv)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1181
int errhint(const char *fmt,...)
Definition: elog.c:1318
#define LOG
Definition: elog.h:31
#define ereport(elevel,...)
Definition: elog.h:149
int MyProcPid
Definition: globals.c:48
bool ExitOnAnyError
Definition: globals.c:124
volatile sig_atomic_t ShutdownRequestPending
Definition: interrupt.c:28
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:337
void proc_exit(int code)
Definition: ipc.c:104
@ B_CHECKPOINTER
Definition: miscadmin.h:363
void pgstat_before_server_shutdown(int code, Datum arg)
Definition: pgstat.c:559
void pgstat_report_checkpointer(void)
PgStat_CheckpointerStats PendingCheckpointerStats
int64 pg_time_t
Definition: pgtime.h:23
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:165
@ PMSIGNAL_XLOG_IS_SHUTDOWN
Definition: pmsignal.h:44
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59
PROC_HDR * ProcGlobal
Definition: proc.c:79
ConditionVariable done_cv
Definition: checkpointer.c:126
ConditionVariable start_cv
Definition: checkpointer.c:125
ProcNumber checkpointerProc
Definition: proc.h:409
PgStat_Counter restartpoints_requested
Definition: pgstat.h:259
PgStat_Counter num_requested
Definition: pgstat.h:256
PgStat_Counter num_performed
Definition: pgstat.h:257
PgStat_Counter restartpoints_timed
Definition: pgstat.h:258
PgStat_Counter num_timed
Definition: pgstat.h:255
PgStat_Counter restartpoints_performed
Definition: pgstat.h:260
bool CreateRestartPoint(int flags)
Definition: xlog.c:7779
XLogRecPtr GetInsertRecPtr(void)
Definition: xlog.c:6670
void ShutdownXLOG(int code, Datum arg)
Definition: xlog.c:6790
int XLogArchiveTimeout
Definition: xlog.c:118
bool CreateCheckPoint(int flags)
Definition: xlog.c:7077
#define CHECKPOINT_CAUSE_XLOG
Definition: xlog.h:148
#define CHECKPOINT_END_OF_RECOVERY
Definition: xlog.h:140
#define CHECKPOINT_CAUSE_TIME
Definition: xlog.h:149
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)

References AbsorbSyncRequests(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), AtEOXact_Buffers(), AtEOXact_Files(), AtEOXact_HashTables(), AtEOXact_SMgr(), AuxiliaryProcessMainCommon(), B_CHECKPOINTER, before_shmem_exit(), CheckArchiveTimeout(), CHECKPOINT_CAUSE_TIME, CHECKPOINT_CAUSE_XLOG, CHECKPOINT_END_OF_RECOVERY, CheckpointerShmemStruct::checkpointer_pid, PROC_HDR::checkpointerProc, CheckpointerShmem, CheckPointTimeout, CheckPointWarning, ckpt_active, ckpt_cached_elapsed, CheckpointerShmemStruct::ckpt_done, CheckpointerShmemStruct::ckpt_failed, CheckpointerShmemStruct::ckpt_flags, CheckpointerShmemStruct::ckpt_lck, ckpt_start_recptr, ckpt_start_time, CheckpointerShmemStruct::ckpt_started, ConditionVariableBroadcast(), ConditionVariableCancelSleep(), CreateCheckPoint(), CreateRestartPoint(), CheckpointerShmemStruct::done_cv, EmitErrorReport(), ereport, errhint(), errmsg_plural(), error_context_stack, ExitOnAnyError, FlushErrorState(), GetInsertRecPtr(), GetXLogReplayRecPtr(), HOLD_INTERRUPTS, last_checkpoint_time, last_xlog_switch_time, LOG, LWLockReleaseAll(), MemoryContextReset(), MemoryContextSwitchTo(), Min, MyBackendType, MyLatch, MyProcNumber, MyProcPid, now(), PgStat_CheckpointerStats::num_performed, PgStat_CheckpointerStats::num_requested, PgStat_CheckpointerStats::num_timed, PendingCheckpointerStats, PG_exception_stack, pg_usleep(), pgaio_error_cleanup(), pgstat_before_server_shutdown(), pgstat_report_checkpointer(), pgstat_report_wait_end(), pgstat_report_wal(), PMSIGNAL_XLOG_IS_SHUTDOWN, pqsignal, proc_exit(), ProcessCheckpointerInterrupts(), ProcGlobal, procsignal_sigusr1_handler(), RecoveryInProgress(), ReleaseAuxProcessResources(), ReqShutdownXLOG(), ResetLatch(), PgStat_CheckpointerStats::restartpoints_performed, PgStat_CheckpointerStats::restartpoints_requested, PgStat_CheckpointerStats::restartpoints_timed, RESUME_INTERRUPTS, SendPostmasterSignal(), ShutdownRequestPending, ShutdownXLOG(), ShutdownXLOGPending, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, smgrdestroyall(), SpinLockAcquire, SpinLockRelease, CheckpointerShmemStruct::start_cv, TopMemoryContext, UnBlockSig, UnlockBuffers(), UpdateSharedMemoryConfig(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_TIMEOUT, and XLogArchiveTimeout.

◆ CheckpointerShmemInit()

void CheckpointerShmemInit ( void  )

Definition at line 958 of file checkpointer.c.

959{
961 bool found;
962
964 ShmemInitStruct("Checkpointer Data",
965 size,
966 &found);
967
968 if (!found)
969 {
970 /*
971 * First time through, so initialize. Note that we zero the whole
972 * requests array; this is so that CompactCheckpointerRequestQueue can
973 * assume that any pad bytes in the request structs are zeroes.
974 */
975 MemSet(CheckpointerShmem, 0, size);
980 }
981}
#define MemSet(start, val, len)
Definition: c.h:991
size_t Size
Definition: c.h:576
Size CheckpointerShmemSize(void)
Definition: checkpointer.c:939
void ConditionVariableInit(ConditionVariable *cv)
int NBuffers
Definition: globals.c:143
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387
#define SpinLockInit(lock)
Definition: spin.h:57

References CheckpointerShmem, CheckpointerShmemSize(), CheckpointerShmemStruct::ckpt_lck, ConditionVariableInit(), CheckpointerShmemStruct::done_cv, CheckpointerShmemStruct::max_requests, MemSet, NBuffers, ShmemInitStruct(), SpinLockInit, and CheckpointerShmemStruct::start_cv.

Referenced by CreateOrAttachShmemStructs().

◆ CheckpointerShmemSize()

Size CheckpointerShmemSize ( void  )

Definition at line 939 of file checkpointer.c.

940{
941 Size size;
942
943 /*
944 * Currently, the size of the requests[] array is arbitrarily set equal to
945 * NBuffers. This may prove too large or small ...
946 */
947 size = offsetof(CheckpointerShmemStruct, requests);
948 size = add_size(size, mul_size(NBuffers, sizeof(CheckpointerRequest)));
949
950 return size;
951}
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510

References add_size(), mul_size(), and NBuffers.

Referenced by CalculateShmemSize(), and CheckpointerShmemInit().

◆ CheckpointWriteDelay()

void CheckpointWriteDelay ( int  flags,
double  progress 
)

Definition at line 773 of file checkpointer.c.

774{
775 static int absorb_counter = WRITES_PER_ABSORB;
776
777 /* Do nothing if checkpoint is being executed by non-checkpointer process */
779 return;
780
781 /*
782 * Perform the usual duties and take a nap, unless we're behind schedule,
783 * in which case we just try to catch up as quickly as possible.
784 */
785 if (!(flags & CHECKPOINT_IMMEDIATE) &&
790 {
792 {
793 ConfigReloadPending = false;
795 /* update shmem copies of config variables */
797 }
798
800 absorb_counter = WRITES_PER_ABSORB;
801
803
804 /* Report interim statistics to the cumulative stats system */
806
807 /*
808 * This sleep used to be connected to bgwriter_delay, typically 200ms.
809 * That resulted in more frequent wakeups if not much work to do.
810 * Checkpointer and bgwriter are no longer related so take the Big
811 * Sleep.
812 */
814 100,
815 WAIT_EVENT_CHECKPOINT_WRITE_DELAY);
817 }
818 else if (--absorb_counter <= 0)
819 {
820 /*
821 * Absorb pending fsync requests after each WRITES_PER_ABSORB write
822 * operations even when we don't sleep, to prevent overflow of the
823 * fsync request queue.
824 */
826 absorb_counter = WRITES_PER_ABSORB;
827 }
828
829 /* Check for barrier events. */
832}
static bool ImmediateCheckpointRequested(void)
Definition: checkpointer.c:746
static bool IsCheckpointOnSchedule(double progress)
Definition: checkpointer.c:843
#define WRITES_PER_ABSORB
Definition: checkpointer.c:136
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:40
void ProcessConfigFile(GucContext context)
Definition: guc-file.l:120
@ PGC_SIGHUP
Definition: guc.h:75
volatile sig_atomic_t ConfigReloadPending
Definition: interrupt.c:27
static int progress
Definition: pgbench.c:262
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:498
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:141

References AbsorbSyncRequests(), AmCheckpointerProcess, CheckArchiveTimeout(), CHECKPOINT_IMMEDIATE, ConfigReloadPending, ImmediateCheckpointRequested(), IsCheckpointOnSchedule(), MyLatch, PGC_SIGHUP, pgstat_report_checkpointer(), ProcessConfigFile(), ProcessProcSignalBarrier(), ProcSignalBarrierPending, progress, ResetLatch(), ShutdownRequestPending, ShutdownXLOGPending, UpdateSharedMemoryConfig(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_TIMEOUT, and WRITES_PER_ABSORB.

Referenced by BufferSync().

◆ FirstCallSinceLastCheckpoint()

bool FirstCallSinceLastCheckpoint ( void  )

Definition at line 1394 of file checkpointer.c.

1395{
1396 static int ckpt_done = 0;
1397 int new_done;
1398 bool FirstCall = false;
1399
1401 new_done = CheckpointerShmem->ckpt_done;
1403
1404 if (new_done != ckpt_done)
1405 FirstCall = true;
1406
1407 ckpt_done = new_done;
1408
1409 return FirstCall;
1410}

References CheckpointerShmem, CheckpointerShmemStruct::ckpt_done, CheckpointerShmemStruct::ckpt_lck, SpinLockAcquire, and SpinLockRelease.

Referenced by BackgroundWriterMain().

◆ ForwardSyncRequest()

bool ForwardSyncRequest ( const FileTag ftag,
SyncRequestType  type 
)

Definition at line 1151 of file checkpointer.c.

1152{
1153 CheckpointerRequest *request;
1154 bool too_full;
1155
1156 if (!IsUnderPostmaster)
1157 return false; /* probably shouldn't even get here */
1158
1160 elog(ERROR, "ForwardSyncRequest must not be called in checkpointer");
1161
1162 LWLockAcquire(CheckpointerCommLock, LW_EXCLUSIVE);
1163
1164 /*
1165 * If the checkpointer isn't running or the request queue is full, the
1166 * backend will have to perform its own fsync request. But before forcing
1167 * that to happen, we can try to compact the request queue.
1168 */
1172 {
1173 LWLockRelease(CheckpointerCommLock);
1174 return false;
1175 }
1176
1177 /* OK, insert request */
1179 request->ftag = *ftag;
1180 request->type = type;
1181
1182 /* If queue is more than half full, nudge the checkpointer to empty it */
1183 too_full = (CheckpointerShmem->num_requests >=
1185
1186 LWLockRelease(CheckpointerCommLock);
1187
1188 /* ... but not till after we release the lock */
1189 if (too_full)
1190 {
1191 volatile PROC_HDR *procglobal = ProcGlobal;
1192 ProcNumber checkpointerProc = procglobal->checkpointerProc;
1193
1194 if (checkpointerProc != INVALID_PROC_NUMBER)
1195 SetLatch(&GetPGProcByNumber(checkpointerProc)->procLatch);
1196 }
1197
1198 return true;
1199}
static bool CompactCheckpointerRequestQueue(void)
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
bool IsUnderPostmaster
Definition: globals.c:121
void SetLatch(Latch *latch)
Definition: latch.c:288
#define GetPGProcByNumber(n)
Definition: proc.h:424
#define INVALID_PROC_NUMBER
Definition: procnumber.h:26
int ProcNumber
Definition: procnumber.h:24
Definition: proc.h:370
const char * type

References AmCheckpointerProcess, CheckpointerShmemStruct::checkpointer_pid, PROC_HDR::checkpointerProc, CheckpointerShmem, CompactCheckpointerRequestQueue(), elog, ERROR, CheckpointerRequest::ftag, GetPGProcByNumber, INVALID_PROC_NUMBER, IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), CheckpointerShmemStruct::max_requests, CheckpointerShmemStruct::num_requests, ProcGlobal, CheckpointerShmemStruct::requests, SetLatch(), CheckpointerRequest::type, and type.

Referenced by RegisterSyncRequest().

◆ RequestCheckpoint()

void RequestCheckpoint ( int  flags)

Definition at line 1001 of file checkpointer.c.

1002{
1003 int ntries;
1004 int old_failed,
1005 old_started;
1006
1007 /*
1008 * If in a standalone backend, just do it ourselves.
1009 */
1011 {
1012 /*
1013 * There's no point in doing slow checkpoints in a standalone backend,
1014 * because there's no other backends the checkpoint could disrupt.
1015 */
1017
1018 /* Free all smgr objects, as CheckpointerMain() normally would. */
1020
1021 return;
1022 }
1023
1024 /*
1025 * Atomically set the request flags, and take a snapshot of the counters.
1026 * When we see ckpt_started > old_started, we know the flags we set here
1027 * have been seen by checkpointer.
1028 *
1029 * Note that we OR the flags with any existing flags, to avoid overriding
1030 * a "stronger" request by another backend. The flag senses must be
1031 * chosen to make this work!
1032 */
1034
1035 old_failed = CheckpointerShmem->ckpt_failed;
1036 old_started = CheckpointerShmem->ckpt_started;
1038
1040
1041 /*
1042 * Set checkpointer's latch to request checkpoint. It's possible that the
1043 * checkpointer hasn't started yet, so we will retry a few times if
1044 * needed. (Actually, more than a few times, since on slow or overloaded
1045 * buildfarm machines, it's been observed that the checkpointer can take
1046 * several seconds to start.) However, if not told to wait for the
1047 * checkpoint to occur, we consider failure to set the latch to be
1048 * nonfatal and merely LOG it. The checkpointer should see the request
1049 * when it does start, with or without the SetLatch().
1050 */
1051#define MAX_SIGNAL_TRIES 600 /* max wait 60.0 sec */
1052 for (ntries = 0;; ntries++)
1053 {
1054 volatile PROC_HDR *procglobal = ProcGlobal;
1055 ProcNumber checkpointerProc = procglobal->checkpointerProc;
1056
1057 if (checkpointerProc == INVALID_PROC_NUMBER)
1058 {
1059 if (ntries >= MAX_SIGNAL_TRIES || !(flags & CHECKPOINT_WAIT))
1060 {
1061 elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG,
1062 "could not notify checkpoint: checkpointer is not running");
1063 break;
1064 }
1065 }
1066 else
1067 {
1068 SetLatch(&GetPGProcByNumber(checkpointerProc)->procLatch);
1069 /* notified successfully */
1070 break;
1071 }
1072
1074 pg_usleep(100000L); /* wait 0.1 sec, then retry */
1075 }
1076
1077 /*
1078 * If requested, wait for completion. We detect completion according to
1079 * the algorithm given above.
1080 */
1081 if (flags & CHECKPOINT_WAIT)
1082 {
1083 int new_started,
1084 new_failed;
1085
1086 /* Wait for a new checkpoint to start. */
1088 for (;;)
1089 {
1091 new_started = CheckpointerShmem->ckpt_started;
1093
1094 if (new_started != old_started)
1095 break;
1096
1098 WAIT_EVENT_CHECKPOINT_START);
1099 }
1101
1102 /*
1103 * We are waiting for ckpt_done >= new_started, in a modulo sense.
1104 */
1106 for (;;)
1107 {
1108 int new_done;
1109
1111 new_done = CheckpointerShmem->ckpt_done;
1112 new_failed = CheckpointerShmem->ckpt_failed;
1114
1115 if (new_done - new_started >= 0)
1116 break;
1117
1119 WAIT_EVENT_CHECKPOINT_DONE);
1120 }
1122
1123 if (new_failed != old_failed)
1124 ereport(ERROR,
1125 (errmsg("checkpoint request failed"),
1126 errhint("Consult recent messages in the server log for details.")));
1127 }
1128}
#define MAX_SIGNAL_TRIES
void ConditionVariablePrepareToSleep(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
int errmsg(const char *fmt,...)
Definition: elog.c:1071
bool IsPostmasterEnvironment
Definition: globals.c:120
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
#define CHECKPOINT_REQUESTED
Definition: xlog.h:146
#define CHECKPOINT_WAIT
Definition: xlog.h:145

References CHECK_FOR_INTERRUPTS, CHECKPOINT_IMMEDIATE, CHECKPOINT_REQUESTED, CHECKPOINT_WAIT, PROC_HDR::checkpointerProc, CheckpointerShmem, CheckpointerShmemStruct::ckpt_done, CheckpointerShmemStruct::ckpt_failed, CheckpointerShmemStruct::ckpt_flags, CheckpointerShmemStruct::ckpt_lck, CheckpointerShmemStruct::ckpt_started, ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableSleep(), CreateCheckPoint(), CheckpointerShmemStruct::done_cv, elog, ereport, errhint(), errmsg(), ERROR, GetPGProcByNumber, INVALID_PROC_NUMBER, IsPostmasterEnvironment, LOG, MAX_SIGNAL_TRIES, pg_usleep(), ProcGlobal, SetLatch(), smgrdestroyall(), SpinLockAcquire, SpinLockRelease, and CheckpointerShmemStruct::start_cv.

Referenced by CreateDatabaseUsingFileCopy(), do_pg_backup_start(), dropdb(), DropTableSpace(), movedb(), PerformRecoveryXLogAction(), standard_ProcessUtility(), StartupXLOG(), XLogPageRead(), and XLogWrite().

Variable Documentation

◆ BgWriterDelay

PGDLLIMPORT int BgWriterDelay
extern

Definition at line 58 of file bgwriter.c.

Referenced by BackgroundWriterMain(), and BgBufferSync().

◆ CheckPointCompletionTarget

PGDLLIMPORT double CheckPointCompletionTarget
extern

◆ CheckPointTimeout

PGDLLIMPORT int CheckPointTimeout
extern

Definition at line 141 of file checkpointer.c.

Referenced by CheckpointerMain(), and IsCheckpointOnSchedule().

◆ CheckPointWarning

PGDLLIMPORT int CheckPointWarning
extern

Definition at line 142 of file checkpointer.c.

Referenced by CheckpointerMain().