]> granicus.if.org Git - postgresql/commitdiff
Bring some clarity to the defaults for the xxx_flush_after parameters.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 25 Nov 2016 23:36:10 +0000 (18:36 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 25 Nov 2016 23:36:10 +0000 (18:36 -0500)
Instead of confusingly stating platform-dependent defaults for these
parameters in the comments in postgresql.conf.sample (with the main
entry being a lie on Linux), teach initdb to install the correct
platform-dependent value in postgresql.conf, similarly to the way
we handle other platform-dependent defaults.  This won't do anything
for existing 9.6 installations, but since it's effectively only a
documentation improvement, that seems OK.

Since this requires initdb to have access to the default values,
move the #define's for those to pg_config_manual.h; the original
placement in bufmgr.h is unworkable because that file can't be
included by frontend programs.

Adjust the default value for wal_writer_flush_after so that it is 1MB
regardless of XLOG_BLCKSZ, conforming to what is stated in both the
SGML docs and postgresql.conf.  (We could alternatively make it scale
with XLOG_BLCKSZ, but I'm not sure I see the point.)

Copy-edit related SGML documentation.

Fabien Coelho and Tom Lane, per a gripe from Tomas Vondra.

Discussion: <30ebc6e3-8358-09cf-44a8-578252938424@2ndquadrant.com>

doc/src/sgml/config.sgml
src/backend/access/transam/xlog.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/bin/initdb/initdb.c
src/include/pg_config_manual.h
src/include/storage/bufmgr.h

index adab2f8378ded0408e476d406cb0cb88b4b94a0d..dcd06634fe64993b948cf6bb993d81cc85b78300 100644 (file)
@@ -1903,10 +1903,10 @@ include_dir 'conf.d'
          <xref linkend="guc-shared-buffers">, but smaller than the OS's page
          cache, where performance might degrade.  This setting may have no
          effect on some platforms.  The valid range is between
-         <literal>0</literal>, which disables controlled writeback, and
+         <literal>0</literal>, which disables forced writeback, and
          <literal>2MB</literal>.  The default is <literal>512kB</> on Linux,
-         <literal>0</> elsewhere.  (Non-default values of
-         <symbol>BLCKSZ</symbol> change the default and maximum.)
+         <literal>0</> elsewhere.  (If <symbol>BLCKSZ</symbol> is not 8kB,
+         the default and maximum values scale proportionally to it.)
          This parameter can only be set in the <filename>postgresql.conf</>
          file or on the server command line.
         </para>
@@ -2055,10 +2055,10 @@ include_dir 'conf.d'
          that are bigger than <xref linkend="guc-shared-buffers">, but smaller
          than the OS's page cache, where performance might degrade.  This
          setting may have no effect on some platforms.  The valid range is
-         between <literal>0</literal>, which disables controlled writeback,
-         and <literal>2MB</literal>.  The default is <literal>0</> (i.e. no
-         flush control).  (Non-default values of <symbol>BLCKSZ</symbol>
-         change the maximum.)
+         between <literal>0</literal>, which disables forced writeback,
+         and <literal>2MB</literal>.  The default is <literal>0</>, i.e., no
+         forced writeback.  (If <symbol>BLCKSZ</symbol> is not 8kB,
+         the maximum value scales proportionally to it.)
         </para>
        </listitem>
       </varlistentry>
@@ -2518,10 +2518,11 @@ include_dir 'conf.d'
       <para>
         Specifies how often the WAL writer flushes WAL. After flushing WAL it
         sleeps for <varname>wal_writer_delay</> milliseconds, unless woken up
-        by an asynchronously committing transaction. In case the last flush
+        by an asynchronously committing transaction. If the last flush
         happened less than <varname>wal_writer_delay</> milliseconds ago and
         less than <varname>wal_writer_flush_after</> bytes of WAL have been
-        produced since, WAL is only written to the OS, not flushed to disk.
+        produced since, then WAL is only written to the operating system, not
+        flushed to disk.
         The default value is 200 milliseconds (<literal>200ms</>).  Note that
         on many systems, the effective resolution of sleep delays is 10
         milliseconds; setting <varname>wal_writer_delay</> to a value that is
@@ -2540,12 +2541,12 @@ include_dir 'conf.d'
       </term>
       <listitem>
       <para>
-        Specifies how often the WAL writer flushes WAL. In case the last flush
+        Specifies how often the WAL writer flushes WAL. If the last flush
         happened less than <varname>wal_writer_delay</> milliseconds ago and
         less than <varname>wal_writer_flush_after</> bytes of WAL have been
-        produced since, WAL is only written to the OS, not flushed to disk.
-        If <varname>wal_writer_flush_after</> is set to <literal>0</> WAL is
-        flushed every time the WAL writer has written WAL.  The default is
+        produced since, then WAL is only written to the operating system, not
+        flushed to disk.  If <varname>wal_writer_flush_after</> is set
+        to <literal>0</> then WAL data is flushed immediately.  The default is
         <literal>1MB</literal>. This parameter can only be set in the
         <filename>postgresql.conf</> file or on the server command line.
        </para>
@@ -2665,10 +2666,10 @@ include_dir 'conf.d'
         that are bigger than <xref linkend="guc-shared-buffers">, but smaller
         than the OS's page cache, where performance might degrade.  This
         setting may have no effect on some platforms.  The valid range is
-        between <literal>0</literal>, which disables controlled writeback,
+        between <literal>0</literal>, which disables forced writeback,
         and <literal>2MB</literal>.  The default is <literal>256kB</> on
-        Linux, <literal>0</> elsewhere.  (Non-default values of
-        <symbol>BLCKSZ</symbol> change the default and maximum.)
+        Linux, <literal>0</> elsewhere.  (If <symbol>BLCKSZ</symbol> is not
+        8kB, the default and maximum values scale proportionally to it.)
         This parameter can only be set in the <filename>postgresql.conf</>
         file or on the server command line.
        </para>
index ce4f1fc29896d0e6f2e42e5d609d22dac00f50d6..084401d2f238d729243bca4e3fdad4ff5a82f123 100644 (file)
@@ -2759,7 +2759,7 @@ XLogFlush(XLogRecPtr record)
  * This routine is invoked periodically by the background walwriter process.
  *
  * Returns TRUE if there was any work to do, even if we skipped flushing due
- * to wal_writer_delay/wal_flush_after.
+ * to wal_writer_delay/wal_writer_flush_after.
  */
 bool
 XLogBackgroundFlush(void)
index da74f00ab24227410f56526f795eb2ca15871a68..28ebcb6f3fa3fc7af7f8594627720af63a48818c 100644 (file)
@@ -2281,7 +2281,6 @@ static struct config_int ConfigureNamesInt[] =
                        GUC_UNIT_BLOCKS
                },
                &checkpoint_flush_after,
-               /* see bufmgr.h: OS dependent default */
                DEFAULT_CHECKPOINT_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
                NULL, NULL, NULL
        },
@@ -2310,12 +2309,12 @@ static struct config_int ConfigureNamesInt[] =
 
        {
                {"wal_writer_flush_after", PGC_SIGHUP, WAL_SETTINGS,
-                       gettext_noop("Amount of WAL written out by WAL writer triggering a flush."),
+                       gettext_noop("Amount of WAL written out by WAL writer that triggers a flush."),
                        NULL,
                        GUC_UNIT_XBLOCKS
                },
                &WalWriterFlushAfter,
-               128, 0, INT_MAX,
+               (1024*1024) / XLOG_BLCKSZ, 0, INT_MAX,
                NULL, NULL, NULL
        },
 
@@ -2439,7 +2438,6 @@ static struct config_int ConfigureNamesInt[] =
                        GUC_UNIT_BLOCKS
                },
                &bgwriter_flush_after,
-               /* see bufmgr.h: OS dependent default */
                DEFAULT_BGWRITER_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
                NULL, NULL, NULL
        },
@@ -2467,7 +2465,7 @@ static struct config_int ConfigureNamesInt[] =
                        GUC_UNIT_BLOCKS
                },
                &backend_flush_after,
-               0, 0, WRITEBACK_MAX_PENDING_FLUSHES,
+               DEFAULT_BACKEND_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
                NULL, NULL, NULL
        },
 
index 7c2daa54bc8d0aee348d283226b3f34a0a699aa9..0df15380a9ae6556a8f3cb3ec06bb359838e280e 100644 (file)
 #bgwriter_delay = 200ms                        # 10-10000ms between rounds
 #bgwriter_lru_maxpages = 100           # 0-1000 max buffers written/round
 #bgwriter_lru_multiplier = 2.0         # 0-10.0 multiplier on buffers scanned/round
-#bgwriter_flush_after = 0              # 0 disables,
-                                       # default is 512kB on linux, 0 otherwise
+#bgwriter_flush_after = 0              # measured in pages, 0 disables
 
 # - Asynchronous Behavior -
 
 #max_parallel_workers_per_gather = 2   # taken from max_worker_processes
 #old_snapshot_threshold = -1           # 1min-60d; -1 disables; 0 is immediate
                                        # (change requires restart)
-#backend_flush_after = 0               # 0 disables, default is 0
+#backend_flush_after = 0               # measured in pages, 0 disables
 
 
 #------------------------------------------------------------------------------
 #wal_buffers = -1                      # min 32kB, -1 sets based on shared_buffers
                                        # (change requires restart)
 #wal_writer_delay = 200ms              # 1-10000 milliseconds
-#wal_writer_flush_after = 1MB          # 0 disables
+#wal_writer_flush_after = 1MB          # measured in pages, 0 disables
 
 #commit_delay = 0                      # range 0-100000, in microseconds
 #commit_siblings = 5                   # range 1-1000
 #max_wal_size = 1GB
 #min_wal_size = 80MB
 #checkpoint_completion_target = 0.5    # checkpoint target duration, 0.0 - 1.0
-#checkpoint_flush_after = 0            # 0 disables,
-                                       # default is 256kB on linux, 0 otherwise
+#checkpoint_flush_after = 0            # measured in pages, 0 disables
 #checkpoint_warning = 30s              # 0 disables
 
 # - Archiving -
index c8a8c52c3d7f1e0a52a981c139d69333a845e1ff..24f9cc8eae263dc3741d7d2eadba3674a79ce3a1 100644 (file)
 #include "common/file_utils.h"
 #include "common/restricted_token.h"
 #include "common/username.h"
-#include "mb/pg_wchar.h"
+#include "fe_utils/string_utils.h"
 #include "getaddrinfo.h"
 #include "getopt_long.h"
+#include "mb/pg_wchar.h"
 #include "miscadmin.h"
-#include "fe_utils/string_utils.h"
 
 
 /* Ideally this would be in a .h file, but it hardly seems worth the trouble */
@@ -1095,6 +1095,27 @@ setup_config(void)
        conflines = replace_token(conflines, "#dynamic_shared_memory_type = posix",
                                                          repltok);
 
+#if DEFAULT_BACKEND_FLUSH_AFTER > 0
+       snprintf(repltok, sizeof(repltok), "#backend_flush_after = %dkB",
+                        DEFAULT_BACKEND_FLUSH_AFTER * (BLCKSZ / 1024));
+       conflines = replace_token(conflines, "#backend_flush_after = 0",
+                                                         repltok);
+#endif
+
+#if DEFAULT_BGWRITER_FLUSH_AFTER > 0
+       snprintf(repltok, sizeof(repltok), "#bgwriter_flush_after = %dkB",
+                        DEFAULT_BGWRITER_FLUSH_AFTER * (BLCKSZ / 1024));
+       conflines = replace_token(conflines, "#bgwriter_flush_after = 0",
+                                                         repltok);
+#endif
+
+#if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
+       snprintf(repltok, sizeof(repltok), "#checkpoint_flush_after = %dkB",
+                        DEFAULT_CHECKPOINT_FLUSH_AFTER * (BLCKSZ / 1024));
+       conflines = replace_token(conflines, "#checkpoint_flush_after = 0",
+                                                         repltok);
+#endif
+
 #ifndef USE_PREFETCH
        conflines = replace_token(conflines,
                                                          "#effective_io_concurrency = 1",
index a2b2b614becfdf69d35e00b7e12e95b3870daa0d..96885bb9901e8f8b4ffa5280f4e5de6800f32104 100644 (file)
 #define USE_PREFETCH
 #endif
 
+/*
+ * Default and maximum values for backend_flush_after, bgwriter_flush_after
+ * and checkpoint_flush_after; measured in blocks.  Currently, these are
+ * enabled by default if sync_file_range() exists, ie, only on Linux.  Perhaps
+ * we could also enable by default if we have mmap and msync(MS_ASYNC)?
+ */
+#ifdef HAVE_SYNC_FILE_RANGE
+#define DEFAULT_BACKEND_FLUSH_AFTER 0  /* never enabled by default */
+#define DEFAULT_BGWRITER_FLUSH_AFTER 64
+#define DEFAULT_CHECKPOINT_FLUSH_AFTER 32
+#else
+#define DEFAULT_BACKEND_FLUSH_AFTER 0
+#define DEFAULT_BGWRITER_FLUSH_AFTER 0
+#define DEFAULT_CHECKPOINT_FLUSH_AFTER 0
+#endif
+/* upper limit for all three variables */
+#define WRITEBACK_MAX_PENDING_FLUSHES 256
+
 /*
  * USE_SSL code should be compiled only when compiling with an SSL
  * implementation.  (Currently, only OpenSSL is supported, but we might add
index 821bee5eceaf5f26bd0be2766a8ecbd213449041..c543ad6fdec8363826bc4030d2f34a1077e30067 100644 (file)
@@ -54,17 +54,6 @@ struct WritebackContext;
 extern PGDLLIMPORT int NBuffers;
 
 /* in bufmgr.c */
-#define WRITEBACK_MAX_PENDING_FLUSHES 256
-
-/* FIXME: Also default to on for mmap && msync(MS_ASYNC)? */
-#ifdef HAVE_SYNC_FILE_RANGE
-#define DEFAULT_CHECKPOINT_FLUSH_AFTER 32
-#define DEFAULT_BGWRITER_FLUSH_AFTER 64
-#else
-#define DEFAULT_CHECKPOINT_FLUSH_AFTER 0
-#define DEFAULT_BGWRITER_FLUSH_AFTER 0
-#endif   /* HAVE_SYNC_FILE_RANGE */
-
 extern bool zero_damaged_pages;
 extern int     bgwriter_lru_maxpages;
 extern double bgwriter_lru_multiplier;