Skip to content

Commit bbcc4eb

Browse files
committed
Change checkpoint_completion_target default to 0.9
Common recommendations are that the checkpoint should be spread out as much as possible, provided we avoid having it take too long. This change updates the default to 0.9 (from 0.5) to match that recommendation. There was some debate about possibly removing the option entirely but it seems there may be some corner-cases where having it set much lower to try to force the checkpoint to be as fast as possible could result in fewer periods of time of reduced performance due to kernel flushing. General agreement is that the "spread more" is the preferred approach though and those who need to tune away from that value are much less common. Reviewed-By: Michael Paquier, Peter Eisentraut, Tom Lane, David Steele, Nathan Bossart Discussion: https://postgr.es/m/20201207175329.GM16415%40tamriel.snowman.net
1 parent e5595de commit bbcc4eb

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

doc/src/sgml/config.sgml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,9 +3302,15 @@ include_dir 'conf.d'
33023302
<listitem>
33033303
<para>
33043304
Specifies the target of checkpoint completion, as a fraction of
3305-
total time between checkpoints. The default is 0.5.
3306-
This parameter can only be set in the <filename>postgresql.conf</filename>
3307-
file or on the server command line.
3305+
total time between checkpoints. The default is 0.9, which spreads the
3306+
checkpoint across almost all of the available interval, providing fairly
3307+
consistent I/O load while also leaving some time for checkpoint
3308+
completion overhead. Reducing this parameter is not recommended because
3309+
it causes the checkpoint to complete faster. This results in a higher
3310+
rate of I/O during the checkpoint followed by a period of less I/O between
3311+
the checkpoint completion and the next scheduled checkpoint. This
3312+
parameter can only be set in the <filename>postgresql.conf</filename> file
3313+
or on the server command line.
33083314
</para>
33093315
</listitem>
33103316
</varlistentry>

doc/src/sgml/wal.sgml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -571,22 +571,29 @@
571571
writing dirty buffers during a checkpoint is spread over a period of time.
572572
That period is controlled by
573573
<xref linkend="guc-checkpoint-completion-target"/>, which is
574-
given as a fraction of the checkpoint interval.
574+
given as a fraction of the checkpoint interval (configured by using
575+
<varname>checkpoint_timeout</varname>).
575576
The I/O rate is adjusted so that the checkpoint finishes when the
576577
given fraction of
577578
<varname>checkpoint_timeout</varname> seconds have elapsed, or before
578579
<varname>max_wal_size</varname> is exceeded, whichever is sooner.
579-
With the default value of 0.5,
580+
With the default value of 0.9,
580581
<productname>PostgreSQL</productname> can be expected to complete each checkpoint
581-
in about half the time before the next checkpoint starts. On a system
582-
that's very close to maximum I/O throughput during normal operation,
583-
you might want to increase <varname>checkpoint_completion_target</varname>
584-
to reduce the I/O load from checkpoints. The disadvantage of this is that
585-
prolonging checkpoints affects recovery time, because more WAL segments
586-
will need to be kept around for possible use in recovery. Although
587-
<varname>checkpoint_completion_target</varname> can be set as high as 1.0,
588-
it is best to keep it less than that (perhaps 0.9 at most) since
589-
checkpoints include some other activities besides writing dirty buffers.
582+
a bit before the next scheduled checkpoint (at around 90% of the last checkpoint's
583+
duration). This spreads out the I/O as much as possible so that the checkpoint
584+
I/O load is consistent throughout the checkpoint interval. The disadvantage of
585+
this is that prolonging checkpoints affects recovery time, because more WAL
586+
segments will need to be kept around for possible use in recovery. A user
587+
concerned about the amount of time required to recover might wish to reduce
588+
<varname>checkpoint_timeout</varname> so that checkpoints occur more frequently
589+
but still spread the I/O across the checkpoint interval. Alternatively,
590+
<varname>checkpoint_completion_target</varname> could be reduced, but this would
591+
result in times of more intense I/O (during the checkpoint) and times of less I/O
592+
(after the checkpoint completed but before the next scheduled checkpoint) and
593+
therefore is not recommended.
594+
Although <varname>checkpoint_completion_target</varname> could be set as high as
595+
1.0, it is typically recommended to set it to no higher than 0.9 (the default)
596+
since checkpoints include some other activities besides writing dirty buffers.
590597
A setting of 1.0 is quite likely to result in checkpoints not being
591598
completed on time, which would result in performance loss due to
592599
unexpected variation in the number of WAL segments needed.

src/backend/postmaster/checkpointer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static CheckpointerShmemStruct *CheckpointerShmem;
145145
*/
146146
int CheckPointTimeout = 300;
147147
int CheckPointWarning = 30;
148-
double CheckPointCompletionTarget = 0.5;
148+
double CheckPointCompletionTarget = 0.9;
149149

150150
/*
151151
* Private state

src/backend/utils/misc/guc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3725,7 +3725,7 @@ static struct config_real ConfigureNamesReal[] =
37253725
NULL
37263726
},
37273727
&CheckPointCompletionTarget,
3728-
0.5, 0.0, 1.0,
3728+
0.9, 0.0, 1.0,
37293729
NULL, NULL, NULL
37303730
},
37313731

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
#checkpoint_timeout = 5min # range 30s-1d
232232
#max_wal_size = 1GB
233233
#min_wal_size = 80MB
234-
#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
234+
#checkpoint_completion_target = 0.9 # checkpoint target duration, 0.0 - 1.0
235235
#checkpoint_flush_after = 0 # measured in pages, 0 disables
236236
#checkpoint_warning = 30s # 0 disables
237237

src/test/recovery/t/015_promotion_pages.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
$bravo->init_from_backup($alpha, 'bkp', has_streaming => 1);
2727
$bravo->append_conf('postgresql.conf', <<EOF);
2828
checkpoint_timeout=1h
29-
checkpoint_completion_target=0.9
3029
EOF
3130
$bravo->start;
3231

0 commit comments

Comments
 (0)