Skip to content

Commit 255bcd2

Browse files
committed
Bring some clarity to the defaults for the xxx_flush_after parameters.
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>
1 parent 474de76 commit 255bcd2

File tree

7 files changed

+65
-40
lines changed

7 files changed

+65
-40
lines changed

doc/src/sgml/config.sgml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,10 +1902,10 @@ include_dir 'conf.d'
19021902
<xref linkend="guc-shared-buffers">, but smaller than the OS's page
19031903
cache, where performance might degrade. This setting may have no
19041904
effect on some platforms. The valid range is between
1905-
<literal>0</literal>, which disables controlled writeback, and
1905+
<literal>0</literal>, which disables forced writeback, and
19061906
<literal>2MB</literal>. The default is <literal>512kB</> on Linux,
1907-
<literal>0</> elsewhere. (Non-default values of
1908-
<symbol>BLCKSZ</symbol> change the default and maximum.)
1907+
<literal>0</> elsewhere. (If <symbol>BLCKSZ</symbol> is not 8kB,
1908+
the default and maximum values scale proportionally to it.)
19091909
This parameter can only be set in the <filename>postgresql.conf</>
19101910
file or on the server command line.
19111911
</para>
@@ -2054,10 +2054,10 @@ include_dir 'conf.d'
20542054
that are bigger than <xref linkend="guc-shared-buffers">, but smaller
20552055
than the OS's page cache, where performance might degrade. This
20562056
setting may have no effect on some platforms. The valid range is
2057-
between <literal>0</literal>, which disables controlled writeback,
2058-
and <literal>2MB</literal>. The default is <literal>0</> (i.e. no
2059-
flush control). (Non-default values of <symbol>BLCKSZ</symbol>
2060-
change the maximum.)
2057+
between <literal>0</literal>, which disables forced writeback,
2058+
and <literal>2MB</literal>. The default is <literal>0</>, i.e., no
2059+
forced writeback. (If <symbol>BLCKSZ</symbol> is not 8kB,
2060+
the maximum value scales proportionally to it.)
20612061
</para>
20622062
</listitem>
20632063
</varlistentry>
@@ -2517,10 +2517,11 @@ include_dir 'conf.d'
25172517
<para>
25182518
Specifies how often the WAL writer flushes WAL. After flushing WAL it
25192519
sleeps for <varname>wal_writer_delay</> milliseconds, unless woken up
2520-
by an asynchronously committing transaction. In case the last flush
2520+
by an asynchronously committing transaction. If the last flush
25212521
happened less than <varname>wal_writer_delay</> milliseconds ago and
25222522
less than <varname>wal_writer_flush_after</> bytes of WAL have been
2523-
produced since, WAL is only written to the OS, not flushed to disk.
2523+
produced since, then WAL is only written to the operating system, not
2524+
flushed to disk.
25242525
The default value is 200 milliseconds (<literal>200ms</>). Note that
25252526
on many systems, the effective resolution of sleep delays is 10
25262527
milliseconds; setting <varname>wal_writer_delay</> to a value that is
@@ -2539,12 +2540,12 @@ include_dir 'conf.d'
25392540
</term>
25402541
<listitem>
25412542
<para>
2542-
Specifies how often the WAL writer flushes WAL. In case the last flush
2543+
Specifies how often the WAL writer flushes WAL. If the last flush
25432544
happened less than <varname>wal_writer_delay</> milliseconds ago and
25442545
less than <varname>wal_writer_flush_after</> bytes of WAL have been
2545-
produced since, WAL is only written to the OS, not flushed to disk.
2546-
If <varname>wal_writer_flush_after</> is set to <literal>0</> WAL is
2547-
flushed every time the WAL writer has written WAL. The default is
2546+
produced since, then WAL is only written to the operating system, not
2547+
flushed to disk. If <varname>wal_writer_flush_after</> is set
2548+
to <literal>0</> then WAL data is flushed immediately. The default is
25482549
<literal>1MB</literal>. This parameter can only be set in the
25492550
<filename>postgresql.conf</> file or on the server command line.
25502551
</para>
@@ -2664,10 +2665,10 @@ include_dir 'conf.d'
26642665
that are bigger than <xref linkend="guc-shared-buffers">, but smaller
26652666
than the OS's page cache, where performance might degrade. This
26662667
setting may have no effect on some platforms. The valid range is
2667-
between <literal>0</literal>, which disables controlled writeback,
2668+
between <literal>0</literal>, which disables forced writeback,
26682669
and <literal>2MB</literal>. The default is <literal>256kB</> on
2669-
Linux, <literal>0</> elsewhere. (Non-default values of
2670-
<symbol>BLCKSZ</symbol> change the default and maximum.)
2670+
Linux, <literal>0</> elsewhere. (If <symbol>BLCKSZ</symbol> is not
2671+
8kB, the default and maximum values scale proportionally to it.)
26712672
This parameter can only be set in the <filename>postgresql.conf</>
26722673
file or on the server command line.
26732674
</para>

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,7 @@ XLogFlush(XLogRecPtr record)
27552755
* This routine is invoked periodically by the background walwriter process.
27562756
*
27572757
* Returns TRUE if there was any work to do, even if we skipped flushing due
2758-
* to wal_writer_delay/wal_flush_after.
2758+
* to wal_writer_delay/wal_writer_flush_after.
27592759
*/
27602760
bool
27612761
XLogBackgroundFlush(void)

src/backend/utils/misc/guc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,6 @@ static struct config_int ConfigureNamesInt[] =
22752275
GUC_UNIT_BLOCKS
22762276
},
22772277
&checkpoint_flush_after,
2278-
/* see bufmgr.h: OS dependent default */
22792278
DEFAULT_CHECKPOINT_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
22802279
NULL, NULL, NULL
22812280
},
@@ -2304,12 +2303,12 @@ static struct config_int ConfigureNamesInt[] =
23042303

23052304
{
23062305
{"wal_writer_flush_after", PGC_SIGHUP, WAL_SETTINGS,
2307-
gettext_noop("Amount of WAL written out by WAL writer triggering a flush."),
2306+
gettext_noop("Amount of WAL written out by WAL writer that triggers a flush."),
23082307
NULL,
23092308
GUC_UNIT_XBLOCKS
23102309
},
23112310
&WalWriterFlushAfter,
2312-
128, 0, INT_MAX,
2311+
(1024*1024) / XLOG_BLCKSZ, 0, INT_MAX,
23132312
NULL, NULL, NULL
23142313
},
23152314

@@ -2433,7 +2432,6 @@ static struct config_int ConfigureNamesInt[] =
24332432
GUC_UNIT_BLOCKS
24342433
},
24352434
&bgwriter_flush_after,
2436-
/* see bufmgr.h: OS dependent default */
24372435
DEFAULT_BGWRITER_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
24382436
NULL, NULL, NULL
24392437
},
@@ -2461,7 +2459,7 @@ static struct config_int ConfigureNamesInt[] =
24612459
GUC_UNIT_BLOCKS
24622460
},
24632461
&backend_flush_after,
2464-
0, 0, WRITEBACK_MAX_PENDING_FLUSHES,
2462+
DEFAULT_BACKEND_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
24652463
NULL, NULL, NULL
24662464
},
24672465

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,16 @@
156156
#bgwriter_delay = 200ms # 10-10000ms between rounds
157157
#bgwriter_lru_maxpages = 100 # 0-1000 max buffers written/round
158158
#bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round
159-
#bgwriter_flush_after = 0 # 0 disables,
160-
# default is 512kB on linux, 0 otherwise
159+
#bgwriter_flush_after = 0 # measured in pages, 0 disables
161160

162161
# - Asynchronous Behavior -
163162

164163
#effective_io_concurrency = 1 # 1-1000; 0 disables prefetching
165164
#max_worker_processes = 8 # (change requires restart)
166165
#max_parallel_workers_per_gather = 0 # taken from max_worker_processes
167166
#old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate
168-
# (change requires restart)
169-
#backend_flush_after = 0 # 0 disables, default is 0
167+
# (change requires restart)
168+
#backend_flush_after = 0 # measured in pages, 0 disables
170169

171170

172171
#------------------------------------------------------------------------------
@@ -196,7 +195,7 @@
196195
#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers
197196
# (change requires restart)
198197
#wal_writer_delay = 200ms # 1-10000 milliseconds
199-
#wal_writer_flush_after = 1MB # 0 disables
198+
#wal_writer_flush_after = 1MB # measured in pages, 0 disables
200199

201200
#commit_delay = 0 # range 0-100000, in microseconds
202201
#commit_siblings = 5 # range 1-1000
@@ -207,8 +206,7 @@
207206
#max_wal_size = 1GB
208207
#min_wal_size = 80MB
209208
#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
210-
#checkpoint_flush_after = 0 # 0 disables,
211-
# default is 256kB on linux, 0 otherwise
209+
#checkpoint_flush_after = 0 # measured in pages, 0 disables
212210
#checkpoint_warning = 30s # 0 disables
213211

214212
# - Archiving -

src/bin/initdb/initdb.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,27 @@ setup_config(void)
12871287
conflines = replace_token(conflines, "#dynamic_shared_memory_type = posix",
12881288
repltok);
12891289

1290+
#if DEFAULT_BACKEND_FLUSH_AFTER > 0
1291+
snprintf(repltok, sizeof(repltok), "#backend_flush_after = %dkB",
1292+
DEFAULT_BACKEND_FLUSH_AFTER * (BLCKSZ / 1024));
1293+
conflines = replace_token(conflines, "#backend_flush_after = 0",
1294+
repltok);
1295+
#endif
1296+
1297+
#if DEFAULT_BGWRITER_FLUSH_AFTER > 0
1298+
snprintf(repltok, sizeof(repltok), "#bgwriter_flush_after = %dkB",
1299+
DEFAULT_BGWRITER_FLUSH_AFTER * (BLCKSZ / 1024));
1300+
conflines = replace_token(conflines, "#bgwriter_flush_after = 0",
1301+
repltok);
1302+
#endif
1303+
1304+
#if DEFAULT_CHECKPOINT_FLUSH_AFTER > 0
1305+
snprintf(repltok, sizeof(repltok), "#checkpoint_flush_after = %dkB",
1306+
DEFAULT_CHECKPOINT_FLUSH_AFTER * (BLCKSZ / 1024));
1307+
conflines = replace_token(conflines, "#checkpoint_flush_after = 0",
1308+
repltok);
1309+
#endif
1310+
12901311
#ifndef USE_PREFETCH
12911312
conflines = replace_token(conflines,
12921313
"#effective_io_concurrency = 1",

src/include/pg_config_manual.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@
147147
#define USE_PREFETCH
148148
#endif
149149

150+
/*
151+
* Default and maximum values for backend_flush_after, bgwriter_flush_after
152+
* and checkpoint_flush_after; measured in blocks. Currently, these are
153+
* enabled by default if sync_file_range() exists, ie, only on Linux. Perhaps
154+
* we could also enable by default if we have mmap and msync(MS_ASYNC)?
155+
*/
156+
#ifdef HAVE_SYNC_FILE_RANGE
157+
#define DEFAULT_BACKEND_FLUSH_AFTER 0 /* never enabled by default */
158+
#define DEFAULT_BGWRITER_FLUSH_AFTER 64
159+
#define DEFAULT_CHECKPOINT_FLUSH_AFTER 32
160+
#else
161+
#define DEFAULT_BACKEND_FLUSH_AFTER 0
162+
#define DEFAULT_BGWRITER_FLUSH_AFTER 0
163+
#define DEFAULT_CHECKPOINT_FLUSH_AFTER 0
164+
#endif
165+
/* upper limit for all three variables */
166+
#define WRITEBACK_MAX_PENDING_FLUSHES 256
167+
150168
/*
151169
* USE_SSL code should be compiled only when compiling with an SSL
152170
* implementation. (Currently, only OpenSSL is supported, but we might add

src/include/storage/bufmgr.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ struct WritebackContext;
5454
extern PGDLLIMPORT int NBuffers;
5555

5656
/* in bufmgr.c */
57-
#define WRITEBACK_MAX_PENDING_FLUSHES 256
58-
59-
/* FIXME: Also default to on for mmap && msync(MS_ASYNC)? */
60-
#ifdef HAVE_SYNC_FILE_RANGE
61-
#define DEFAULT_CHECKPOINT_FLUSH_AFTER 32
62-
#define DEFAULT_BGWRITER_FLUSH_AFTER 64
63-
#else
64-
#define DEFAULT_CHECKPOINT_FLUSH_AFTER 0
65-
#define DEFAULT_BGWRITER_FLUSH_AFTER 0
66-
#endif /* HAVE_SYNC_FILE_RANGE */
67-
6857
extern bool zero_damaged_pages;
6958
extern int bgwriter_lru_maxpages;
7059
extern double bgwriter_lru_multiplier;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy