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

Commit0f73aae

Browse files
committed
Allow the wal_buffers setting to be auto-tuned to a reasonable value.
If wal_buffers is initially set to -1 (which is now the default), it'sreplaced by 1/32nd of shared_buffers, with a minimum of 8 (the old default)and a maximum of the XLOG segment size. The allowed range for manualsettings is still from 4 up to whatever will fit in shared memory.Greg Smith, with implementation correction by me.
1 parent518b1e9 commit0f73aae

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,12 +1638,25 @@ SET ENABLE_SEQSCAN TO OFF;
16381638
</indexterm>
16391639
<listitem>
16401640
<para>
1641-
The amount of memory used in shared memory for WAL data. The
1642-
default is 64 kilobytes (<literal>64kB</>). The setting need only
1643-
be large enough to hold the amount of WAL data generated by one
1644-
typical transaction, since the data is written out to disk at
1645-
every transaction commit. This parameter can only be set at server
1646-
start.
1641+
The amount of shared memory used for WAL data that has not yet been
1642+
written to disk. The default setting of -1 selects a size equal to
1643+
1/32nd (about 3%) of <xref linkend="guc-shared-buffers">, but not less
1644+
than <literal>64kB</literal> nor more than the size of one WAL
1645+
segment, typically <literal>16MB</literal>. This value can be set
1646+
manually if the automatic choice is too large or too small,
1647+
but any positive value less than <literal>32kB</literal> will be
1648+
treated as <literal>32kB</literal>.
1649+
This parameter can only be set at server start.
1650+
</para>
1651+
1652+
<para>
1653+
The contents of the WAL buffers are written out to disk at every
1654+
transaction commit, so extremely large values are unlikely to
1655+
provide a significant benefit. However, setting this value to at
1656+
least a few megabytes can improve write performance on a busy
1657+
server where many clients are committing at once. The auto-tuning
1658+
selected by the default setting of -1 should give reasonable
1659+
results in most cases.
16471660
</para>
16481661

16491662
<para>

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
/* User-settable parameters */
7070
intCheckPointSegments=3;
7171
intwal_keep_segments=0;
72-
intXLOGbuffers=8;
72+
intXLOGbuffers=-1;
7373
intXLogArchiveTimeout=0;
7474
boolXLogArchiveMode= false;
7575
char*XLogArchiveCommand=NULL;
@@ -4777,6 +4777,41 @@ GetSystemIdentifier(void)
47774777
returnControlFile->system_identifier;
47784778
}
47794779

4780+
/*
4781+
* Auto-tune the number of XLOG buffers.
4782+
*
4783+
* If the user-set value of wal_buffers is -1, we auto-tune to about 3% of
4784+
* shared_buffers, with a maximum of one XLOG segment and a minimum of 8
4785+
* blocks (8 was the default value prior to PostgreSQL 9.1, when auto-tuning
4786+
* was added). We also clamp manually-set values to at least 4 blocks; prior
4787+
* to PostgreSQL 9.1, a minimum of 4 was enforced by guc.c, but since that
4788+
* is no longer possible, we just silently treat such values as a request for
4789+
* the minimum.
4790+
*/
4791+
staticvoid
4792+
XLOGTuneNumBuffers(void)
4793+
{
4794+
intxbuffers=XLOGbuffers;
4795+
charbuf[32];
4796+
4797+
if (xbuffers==-1)
4798+
{
4799+
xbuffers=NBuffers /32;
4800+
if (xbuffers>XLOG_SEG_SIZE /XLOG_BLCKSZ)
4801+
xbuffers=XLOG_SEG_SIZE /XLOG_BLCKSZ;
4802+
if (xbuffers<8)
4803+
xbuffers=8;
4804+
}
4805+
elseif (xbuffers<4)
4806+
xbuffers=4;
4807+
4808+
if (xbuffers!=XLOGbuffers)
4809+
{
4810+
snprintf(buf,sizeof(buf),"%d",xbuffers);
4811+
SetConfigOption("wal_buffers",buf,PGC_POSTMASTER,PGC_S_OVERRIDE);
4812+
}
4813+
}
4814+
47804815
/*
47814816
* Initialization of shared memory for XLOG
47824817
*/
@@ -4785,6 +4820,10 @@ XLOGShmemSize(void)
47854820
{
47864821
Sizesize;
47874822

4823+
/* Figure out how many XLOG buffers we need. */
4824+
XLOGTuneNumBuffers();
4825+
Assert(XLOGbuffers>0);
4826+
47884827
/* XLogCtl */
47894828
size=sizeof(XLogCtlData);
47904829
/* xlblocks array */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ static struct config_int ConfigureNamesInt[] =
17651765
GUC_UNIT_XBLOCKS
17661766
},
17671767
&XLOGbuffers,
1768-
8,4,INT_MAX,NULL,NULL
1768+
-1,-1,INT_MAX,NULL,NULL
17691769
},
17701770

17711771
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
# fsync_writethrough
163163
# open_sync
164164
#full_page_writes = on# recover from partial page writes
165-
#wal_buffers =64kB# min 32kB
165+
#wal_buffers =-1# min 32kB, -1 sets based on shared_buffers
166166
# (change requires restart)
167167
#wal_writer_delay = 200ms# 1-10000 milliseconds
168168

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp