37
37
*
38
38
*
39
39
* IDENTIFICATION
40
- * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.16 2005/05/28 17:21:32 tgl Exp $
40
+ * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.17 2005/06/30 00:00:51 tgl Exp $
41
41
*
42
42
*-------------------------------------------------------------------------
43
43
*/
86
86
* 6. If ckpt_failed is different from the originally saved value,
87
87
* assume request failed; otherwise it was definitely successful.
88
88
*
89
+ * An additional field is ckpt_time_warn; this is also sig_atomic_t for
90
+ * simplicity, but is only used as a boolean. If a backend is requesting
91
+ * a checkpoint for which a checkpoints-too-close-together warning is
92
+ * reasonable, it should set this field TRUE just before sending the signal.
93
+ *
89
94
* The requests array holds fsync requests sent by backends and not yet
90
- * absorbed by the bgwriter.
95
+ * absorbed by the bgwriter. Unlike the checkpoint fields, the requests
96
+ * fields are protected by BgWriterCommLock.
91
97
*----------
92
98
*/
93
99
typedef struct
@@ -105,6 +111,8 @@ typedef struct
105
111
sig_atomic_t ckpt_done ; /* advances when checkpoint done */
106
112
sig_atomic_t ckpt_failed ; /* advances when checkpoint fails */
107
113
114
+ sig_atomic_t ckpt_time_warn ; /* warn if too soon since last ckpt? */
115
+
108
116
int num_requests ; /* current # of requests */
109
117
int max_requests ; /* allocated array size */
110
118
BgWriterRequest requests [1 ]; /* VARIABLE LENGTH ARRAY */
@@ -319,20 +327,20 @@ BackgroundWriterMain(void)
319
327
*/
320
328
if (do_checkpoint )
321
329
{
322
- if ( CheckPointWarning != 0 )
323
- {
324
- /*
325
- * Ideally we should only warn if this checkpoint was
326
- * requested due to running out of segment files, and not
327
- * if it was manually requested. However we can't tell
328
- * the difference with the current signalling mechanism.
329
- */
330
- if ( elapsed_secs < CheckPointWarning )
331
- ereport (LOG ,
332
- (errmsg ("checkpoints are occurring too frequently (%d seconds apart)" ,
333
- elapsed_secs ),
334
- errhint ("Consider increasing the configuration parameter \"checkpoint_segments\"." )));
335
- }
330
+ /*
331
+ * We will warn if (a) too soon since last checkpoint (whatever
332
+ * caused it) and (b) somebody has set the ckpt_time_warn flag
333
+ * since the last checkpoint start. Note in particular that
334
+ * this implementation will not generate warnings caused by
335
+ * CheckPointTimeout < CheckPointWarning.
336
+ */
337
+ if ( BgWriterShmem -> ckpt_time_warn &&
338
+ elapsed_secs < CheckPointWarning )
339
+ ereport (LOG ,
340
+ (errmsg ("checkpoints are occurring too frequently (%d seconds apart)" ,
341
+ elapsed_secs ),
342
+ errhint ("Consider increasing the configuration parameter \"checkpoint_segments\"." )));
343
+ BgWriterShmem -> ckpt_time_warn = false;
336
344
337
345
/*
338
346
* Indicate checkpoint start to any waiting backends.
@@ -497,9 +505,13 @@ BgWriterShmemInit(void)
497
505
* If waitforit is true, wait until the checkpoint is completed
498
506
* before returning; otherwise, just signal the request and return
499
507
* immediately.
508
+ *
509
+ * If warnontime is true, and it's "too soon" since the last checkpoint,
510
+ * the bgwriter will log a warning. This should be true only for checkpoints
511
+ * caused due to xlog filling, else the warning will be misleading.
500
512
*/
501
513
void
502
- RequestCheckpoint (bool waitforit )
514
+ RequestCheckpoint (bool waitforit , bool warnontime )
503
515
{
504
516
/* use volatile pointer to prevent code rearrangement */
505
517
volatile BgWriterShmemStruct * bgs = BgWriterShmem ;
@@ -523,6 +535,10 @@ RequestCheckpoint(bool waitforit)
523
535
return ;
524
536
}
525
537
538
+ /* Set warning request flag if appropriate */
539
+ if (warnontime )
540
+ bgs -> ckpt_time_warn = true;
541
+
526
542
/*
527
543
* Send signal to request checkpoint. When waitforit is false, we
528
544
* consider failure to send the signal to be nonfatal.
0 commit comments