Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4347cc2

Browse files
committed
Allow background writing to be shut down by setting limit values to zero.
This does not disable the bgwriter process: it still has to wake up often enough to collect fsync requests from backends in a timely fashion. But it responds to the recent gripe about not being able to prevent the disk from being spun up constantly.
1 parent bdbe9c9 commit 4347cc2

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

doc/src/sgml/runtime.sgml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.288 2004/10/15 16:50:29 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.289 2004/10/17 22:01:49 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1305,7 +1305,9 @@ SET ENABLE_SEQSCAN TO OFF;
13051305
<varname>bgwriter_maxpages</varname> reduce the extra I/O load
13061306
caused by the background writer, but leave more work to be done
13071307
at checkpoint time. To reduce load spikes at checkpoints,
1308-
increase the values.
1308+
increase the values. To disable background writing entirely,
1309+
set <varname>bgwriter_percent</varname> and/or
1310+
<varname>bgwriter_maxpages</varname> to zero.
13091311
</para>
13101312
</sect3>
13111313

src/backend/storage/buffer/bufmgr.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.180 2004/10/16 18:57:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.181 2004/10/17 22:01:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -671,8 +671,10 @@ UnpinBuffer(BufferDesc *buf, bool fixOwner)
671671
*
672672
* This is called at checkpoint time to write out all dirty shared buffers,
673673
* and by the background writer process to write out some of the dirty blocks.
674-
* percent/maxpages should be zero in the former case, and nonzero limit
675-
* values in the latter.
674+
* percent/maxpages should be -1 in the former case, and limit values (>= 0)
675+
* in the latter.
676+
*
677+
* Returns the number of buffers written.
676678
*/
677679
int
678680
BufferSync(int percent, int maxpages)
@@ -682,6 +684,10 @@ BufferSync(int percent, int maxpages)
682684
int num_buffer_dirty;
683685
int i;
684686

687+
/* If either limit is zero then we are disabled from doing anything... */
688+
if (percent == 0 || maxpages == 0)
689+
return 0;
690+
685691
/*
686692
* Get a list of all currently dirty buffers and how many there are.
687693
* We do not flush buffers that get dirtied after we started. They

src/backend/utils/misc/guc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.244 2004/10/16 19:08:38 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.245 2004/10/17 22:01:51 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -1248,7 +1248,7 @@ static struct config_int ConfigureNamesInt[] =
12481248
NULL
12491249
},
12501250
&BgWriterDelay,
1251-
200, 10, 5000, NULL, NULL
1251+
200, 10, 10000, NULL, NULL
12521252
},
12531253

12541254
{
@@ -1257,7 +1257,7 @@ static struct config_int ConfigureNamesInt[] =
12571257
NULL
12581258
},
12591259
&BgWriterPercent,
1260-
1, 1, 100, NULL, NULL
1260+
1, 0, 100, NULL, NULL
12611261
},
12621262

12631263
{
@@ -1266,7 +1266,7 @@ static struct config_int ConfigureNamesInt[] =
12661266
NULL
12671267
},
12681268
&BgWriterMaxPages,
1269-
100, 1, 1000, NULL, NULL
1269+
100, 0, 1000, NULL, NULL
12701270
},
12711271

12721272
{

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@
9898

9999
# - Background writer -
100100

101-
#bgwriter_delay = 200 # 10-5000 milliseconds
102-
#bgwriter_percent = 1 # 1-100% of dirty buffers
103-
#bgwriter_maxpages = 100 # 1-1000 buffers max at once
101+
#bgwriter_delay = 200 # 10-10000 milliseconds between rounds
102+
#bgwriter_percent = 1 # 0-100% of dirty buffers in each round
103+
#bgwriter_maxpages = 100 # 0-1000 buffers max per round
104104

105105

106106
#---------------------------------------------------------------------------

0 commit comments

Comments
 (0)