Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbdfd11

Browse files
committed
Bring some clarity to the defaults for the xxx_flush_after parameters.
Instead of confusingly stating platform-dependent defaults for theseparameters in the comments in postgresql.conf.sample (with the mainentry being a lie on Linux), teach initdb to install the correctplatform-dependent value in postgresql.conf, similarly to the waywe handle other platform-dependent defaults. This won't do anythingfor existing 9.6 installations, but since it's effectively only adocumentation 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 originalplacement in bufmgr.h is unworkable because that file can't beincluded by frontend programs.Adjust the default value for wal_writer_flush_after so that it is 1MBregardless of XLOG_BLCKSZ, conforming to what is stated in both theSGML docs and postgresql.conf. (We could alternatively make it scalewith 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 parentab77a5a commitdbdfd11

File tree

7 files changed

+66
-41
lines changed

7 files changed

+66
-41
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,10 @@ include_dir 'conf.d'
19031903
<xref linkend="guc-shared-buffers">, but smaller than the OS's page
19041904
cache, where performance might degrade. This setting may have no
19051905
effect on some platforms. The valid range is between
1906-
<literal>0</literal>, which disablescontrolled writeback, and
1906+
<literal>0</literal>, which disablesforced writeback, and
19071907
<literal>2MB</literal>. The default is <literal>512kB</> on Linux,
1908-
<literal>0</> elsewhere. (Non-default values of
1909-
<symbol>BLCKSZ</symbol> changethe default and maximum.)
1908+
<literal>0</> elsewhere. (If <symbol>BLCKSZ</symbol> is not 8kB,
1909+
the default and maximum values scale proportionally to it.)
19101910
This parameter can only be set in the <filename>postgresql.conf</>
19111911
file or on the server command line.
19121912
</para>
@@ -2055,10 +2055,10 @@ include_dir 'conf.d'
20552055
that are bigger than <xref linkend="guc-shared-buffers">, but smaller
20562056
than the OS's page cache, where performance might degrade. This
20572057
setting may have no effect on some platforms. The valid range is
2058-
between <literal>0</literal>, which disablescontrolled writeback,
2059-
and <literal>2MB</literal>. The default is <literal>0</> (i.e. no
2060-
flush control). (Non-default values of<symbol>BLCKSZ</symbol>
2061-
changethe maximum.)
2058+
between <literal>0</literal>, which disablesforced writeback,
2059+
and <literal>2MB</literal>. The default is <literal>0</>,i.e., no
2060+
forced writeback. (If<symbol>BLCKSZ</symbol> is not 8kB,
2061+
the maximum value scales proportionally to it.)
20622062
</para>
20632063
</listitem>
20642064
</varlistentry>
@@ -2518,10 +2518,11 @@ include_dir 'conf.d'
25182518
<para>
25192519
Specifies how often the WAL writer flushes WAL. After flushing WAL it
25202520
sleeps for <varname>wal_writer_delay</> milliseconds, unless woken up
2521-
by an asynchronously committing transaction.In case the last flush
2521+
by an asynchronously committing transaction.If the last flush
25222522
happened less than <varname>wal_writer_delay</> milliseconds ago and
25232523
less than <varname>wal_writer_flush_after</> bytes of WAL have been
2524-
produced since, WAL is only written to the OS, not flushed to disk.
2524+
produced since, then WAL is only written to the operating system, not
2525+
flushed to disk.
25252526
The default value is 200 milliseconds (<literal>200ms</>). Note that
25262527
on many systems, the effective resolution of sleep delays is 10
25272528
milliseconds; setting <varname>wal_writer_delay</> to a value that is
@@ -2540,12 +2541,12 @@ include_dir 'conf.d'
25402541
</term>
25412542
<listitem>
25422543
<para>
2543-
Specifies how often the WAL writer flushes WAL.In case the last flush
2544+
Specifies how often the WAL writer flushes WAL.If the last flush
25442545
happened less than <varname>wal_writer_delay</> milliseconds ago and
25452546
less than <varname>wal_writer_flush_after</> bytes of WAL have been
2546-
produced since, WAL is only written to theOS, not flushed to disk.
2547-
If <varname>wal_writer_flush_after</> is set to <literal>0</> WAL is
2548-
flushed every time theWALwriter has written WAL. The default is
2547+
produced since,thenWAL is only written to theoperating system, not
2548+
flushed to disk.If <varname>wal_writer_flush_after</> is set
2549+
to <literal>0</> thenWALdata is flushed immediately. The default is
25492550
<literal>1MB</literal>. This parameter can only be set in the
25502551
<filename>postgresql.conf</> file or on the server command line.
25512552
</para>
@@ -2665,10 +2666,10 @@ include_dir 'conf.d'
26652666
that are bigger than <xref linkend="guc-shared-buffers">, but smaller
26662667
than the OS's page cache, where performance might degrade. This
26672668
setting may have no effect on some platforms. The valid range is
2668-
between <literal>0</literal>, which disablescontrolled writeback,
2669+
between <literal>0</literal>, which disablesforced writeback,
26692670
and <literal>2MB</literal>. The default is <literal>256kB</> on
2670-
Linux, <literal>0</> elsewhere. (Non-default values of
2671-
<symbol>BLCKSZ</symbol> changethe default and maximum.)
2671+
Linux, <literal>0</> elsewhere. (If <symbol>BLCKSZ</symbol> is not
2672+
8kB,the default and maximum values scale proportionally to it.)
26722673
This parameter can only be set in the <filename>postgresql.conf</>
26732674
file or on the server command line.
26742675
</para>

‎src/backend/access/transam/xlog.c

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

‎src/backend/utils/misc/guc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,6 @@ static struct config_int ConfigureNamesInt[] =
22812281
GUC_UNIT_BLOCKS
22822282
},
22832283
&checkpoint_flush_after,
2284-
/* see bufmgr.h: OS dependent default */
22852284
DEFAULT_CHECKPOINT_FLUSH_AFTER,0,WRITEBACK_MAX_PENDING_FLUSHES,
22862285
NULL,NULL,NULL
22872286
},
@@ -2310,12 +2309,12 @@ static struct config_int ConfigureNamesInt[] =
23102309

23112310
{
23122311
{"wal_writer_flush_after",PGC_SIGHUP,WAL_SETTINGS,
2313-
gettext_noop("Amount of WAL written out by WAL writertriggering a flush."),
2312+
gettext_noop("Amount of WAL written out by WAL writerthat triggers a flush."),
23142313
NULL,
23152314
GUC_UNIT_XBLOCKS
23162315
},
23172316
&WalWriterFlushAfter,
2318-
128,0,INT_MAX,
2317+
(1024*1024) /XLOG_BLCKSZ,0,INT_MAX,
23192318
NULL,NULL,NULL
23202319
},
23212320

@@ -2439,7 +2438,6 @@ static struct config_int ConfigureNamesInt[] =
24392438
GUC_UNIT_BLOCKS
24402439
},
24412440
&bgwriter_flush_after,
2442-
/* see bufmgr.h: OS dependent default */
24432441
DEFAULT_BGWRITER_FLUSH_AFTER,0,WRITEBACK_MAX_PENDING_FLUSHES,
24442442
NULL,NULL,NULL
24452443
},
@@ -2467,7 +2465,7 @@ static struct config_int ConfigureNamesInt[] =
24672465
GUC_UNIT_BLOCKS
24682466
},
24692467
&backend_flush_after,
2470-
0,0,WRITEBACK_MAX_PENDING_FLUSHES,
2468+
DEFAULT_BACKEND_FLUSH_AFTER,0,WRITEBACK_MAX_PENDING_FLUSHES,
24712469
NULL,NULL,NULL
24722470
},
24732471

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@
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

@@ -166,7 +165,7 @@
166165
#max_parallel_workers_per_gather = 2# taken from max_worker_processes
167166
#old_snapshot_threshold = -1# 1min-60d; -1 disables; 0 is immediate
168167
# (change requires restart)
169-
#backend_flush_after = 0#0 disables, default is 0
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: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
#include"common/file_utils.h"
6565
#include"common/restricted_token.h"
6666
#include"common/username.h"
67-
#include"mb/pg_wchar.h"
67+
#include"fe_utils/string_utils.h"
6868
#include"getaddrinfo.h"
6969
#include"getopt_long.h"
70+
#include"mb/pg_wchar.h"
7071
#include"miscadmin.h"
71-
#include"fe_utils/string_utils.h"
7272

7373

7474
/* Ideally this would be in a .h file, but it hardly seems worth the trouble */
@@ -1095,6 +1095,27 @@ setup_config(void)
10951095
conflines=replace_token(conflines,"#dynamic_shared_memory_type = posix",
10961096
repltok);
10971097

1098+
#ifDEFAULT_BACKEND_FLUSH_AFTER>0
1099+
snprintf(repltok,sizeof(repltok),"#backend_flush_after = %dkB",
1100+
DEFAULT_BACKEND_FLUSH_AFTER* (BLCKSZ /1024));
1101+
conflines=replace_token(conflines,"#backend_flush_after = 0",
1102+
repltok);
1103+
#endif
1104+
1105+
#ifDEFAULT_BGWRITER_FLUSH_AFTER>0
1106+
snprintf(repltok,sizeof(repltok),"#bgwriter_flush_after = %dkB",
1107+
DEFAULT_BGWRITER_FLUSH_AFTER* (BLCKSZ /1024));
1108+
conflines=replace_token(conflines,"#bgwriter_flush_after = 0",
1109+
repltok);
1110+
#endif
1111+
1112+
#ifDEFAULT_CHECKPOINT_FLUSH_AFTER>0
1113+
snprintf(repltok,sizeof(repltok),"#checkpoint_flush_after = %dkB",
1114+
DEFAULT_CHECKPOINT_FLUSH_AFTER* (BLCKSZ /1024));
1115+
conflines=replace_token(conflines,"#checkpoint_flush_after = 0",
1116+
repltok);
1117+
#endif
1118+
10981119
#ifndefUSE_PREFETCH
10991120
conflines=replace_token(conflines,
11001121
"#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
#defineUSE_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+
#ifdefHAVE_SYNC_FILE_RANGE
157+
#defineDEFAULT_BACKEND_FLUSH_AFTER 0/* never enabled by default */
158+
#defineDEFAULT_BGWRITER_FLUSH_AFTER 64
159+
#defineDEFAULT_CHECKPOINT_FLUSH_AFTER 32
160+
#else
161+
#defineDEFAULT_BACKEND_FLUSH_AFTER 0
162+
#defineDEFAULT_BGWRITER_FLUSH_AFTER 0
163+
#defineDEFAULT_CHECKPOINT_FLUSH_AFTER 0
164+
#endif
165+
/* upper limit for all three variables */
166+
#defineWRITEBACK_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
externPGDLLIMPORTintNBuffers;
5555

5656
/* in bufmgr.c */
57-
#defineWRITEBACK_MAX_PENDING_FLUSHES 256
58-
59-
/* FIXME: Also default to on for mmap && msync(MS_ASYNC)? */
60-
#ifdefHAVE_SYNC_FILE_RANGE
61-
#defineDEFAULT_CHECKPOINT_FLUSH_AFTER 32
62-
#defineDEFAULT_BGWRITER_FLUSH_AFTER 64
63-
#else
64-
#defineDEFAULT_CHECKPOINT_FLUSH_AFTER 0
65-
#defineDEFAULT_BGWRITER_FLUSH_AFTER 0
66-
#endif/* HAVE_SYNC_FILE_RANGE */
67-
6857
externboolzero_damaged_pages;
6958
externintbgwriter_lru_maxpages;
7059
externdoublebgwriter_lru_multiplier;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp