Change checkpoint_completion_target default to 0.9
authorStephen Frost <sfrost@snowman.net>
Wed, 24 Mar 2021 17:07:51 +0000 (13:07 -0400)
committerStephen Frost <sfrost@snowman.net>
Wed, 24 Mar 2021 17:07:51 +0000 (13:07 -0400)
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

doc/src/sgml/config.sgml
doc/src/sgml/wal.sgml
src/backend/postmaster/checkpointer.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/test/recovery/t/015_promotion_pages.pl

index d63aebb2ff1071ce7c744ad8224864e6cf33eb20..ddc6d789d8aeeb1d8f35cc4f976a29d337a2daa6 100644 (file)
@@ -3302,9 +3302,15 @@ include_dir 'conf.d'
       <listitem>
        <para>
         Specifies the target of checkpoint completion, as a fraction of
-        total time between checkpoints. The default is 0.5.
-        This parameter can only be set in the <filename>postgresql.conf</filename>
-        file or on the server command line.
+        total time between checkpoints. The default is 0.9, which spreads the
+        checkpoint across almost all of the available interval, providing fairly
+        consistent I/O load while also leaving some time for checkpoint
+        completion overhead.  Reducing this parameter is not recommended because
+        it causes the checkpoint to complete faster.  This results in a higher
+        rate of I/O during the checkpoint followed by a period of less I/O between
+        the checkpoint completion and the next scheduled checkpoint.  This
+        parameter can only be set in the <filename>postgresql.conf</filename> file
+        or on the server command line.
        </para>
       </listitem>
      </varlistentry>
index ae4a3c12931b6aa5f6151785c0c79d4227cf4132..7d48f427109feaa1230ed61064efa23a0cd5f053 100644 (file)
    writing dirty buffers during a checkpoint is spread over a period of time.
    That period is controlled by
    <xref linkend="guc-checkpoint-completion-target"/>, which is
-   given as a fraction of the checkpoint interval.
+   given as a fraction of the checkpoint interval (configured by using
+   <varname>checkpoint_timeout</varname>).
    The I/O rate is adjusted so that the checkpoint finishes when the
    given fraction of
    <varname>checkpoint_timeout</varname> seconds have elapsed, or before
    <varname>max_wal_size</varname> is exceeded, whichever is sooner.
-   With the default value of 0.5,
+   With the default value of 0.9,
    <productname>PostgreSQL</productname> can be expected to complete each checkpoint
-   in about half the time before the next checkpoint starts.  On a system
-   that's very close to maximum I/O throughput during normal operation,
-   you might want to increase <varname>checkpoint_completion_target</varname>
-   to reduce the I/O load from checkpoints.  The disadvantage of this is that
-   prolonging checkpoints affects recovery time, because more WAL segments
-   will need to be kept around for possible use in recovery.  Although
-   <varname>checkpoint_completion_target</varname> can be set as high as 1.0,
-   it is best to keep it less than that (perhaps 0.9 at most) since
-   checkpoints include some other activities besides writing dirty buffers.
+   a bit before the next scheduled checkpoint (at around 90% of the last checkpoint's
+   duration).  This spreads out the I/O as much as possible so that the checkpoint
+   I/O load is consistent throughout the checkpoint interval.  The disadvantage of
+   this is that prolonging checkpoints affects recovery time, because more WAL
+   segments will need to be kept around for possible use in recovery.  A user
+   concerned about the amount of time required to recover might wish to reduce
+   <varname>checkpoint_timeout</varname> so that checkpoints occur more frequently
+   but still spread the I/O across the checkpoint interval.  Alternatively,
+   <varname>checkpoint_completion_target</varname> could be reduced, but this would
+   result in times of more intense I/O (during the checkpoint) and times of less I/O
+   (after the checkpoint completed but before the next scheduled checkpoint) and
+   therefore is not recommended.
+   Although <varname>checkpoint_completion_target</varname> could be set as high as
+   1.0, it is typically recommended to set it to no higher than 0.9 (the default)
+   since checkpoints include some other activities besides writing dirty buffers.
    A setting of 1.0 is quite likely to result in checkpoints not being
    completed on time, which would result in performance loss due to
    unexpected variation in the number of WAL segments needed.
index 5907a7befc503ecc9ad601997c614cc7db6692cc..e7e6a2a4594b92bf72aa05a442745234146ac138 100644 (file)
@@ -145,7 +145,7 @@ static CheckpointerShmemStruct *CheckpointerShmem;
  */
 int                    CheckPointTimeout = 300;
 int                    CheckPointWarning = 30;
-double         CheckPointCompletionTarget = 0.5;
+double         CheckPointCompletionTarget = 0.9;
 
 /*
  * Private state
index cc0b9f6ad62c577e502a5661e056ae32ac027ba6..0c5dc4d3e8494a01c0fc3375c38440894355d2cf 100644 (file)
@@ -3725,7 +3725,7 @@ static struct config_real ConfigureNamesReal[] =
                        NULL
                },
                &CheckPointCompletionTarget,
-               0.5, 0.0, 1.0,
+               0.9, 0.0, 1.0,
                NULL, NULL, NULL
        },
 
index 74b416b74a8b57ea05ede158274b2535663f2370..b234a6bfe64f4a1a26c82724814b894d40337f74 100644 (file)
 #checkpoint_timeout = 5min             # range 30s-1d
 #max_wal_size = 1GB
 #min_wal_size = 80MB
-#checkpoint_completion_target = 0.5    # checkpoint target duration, 0.0 - 1.0
+#checkpoint_completion_target = 0.9    # checkpoint target duration, 0.0 - 1.0
 #checkpoint_flush_after = 0            # measured in pages, 0 disables
 #checkpoint_warning = 30s              # 0 disables
 
index 6fb70b5001b4c236f093e83e142864646d423d01..25a9e4764a2f47223acfbaa1bf1ae59d1ed50853 100644 (file)
@@ -26,7 +26,6 @@ my $bravo = get_new_node('bravo');
 $bravo->init_from_backup($alpha, 'bkp', has_streaming => 1);
 $bravo->append_conf('postgresql.conf', <<EOF);
 checkpoint_timeout=1h
-checkpoint_completion_target=0.9
 EOF
 $bravo->start;