From 4347cc2392a75dec1d5e83f8b60911597fc602d9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 17 Oct 2004 22:01:51 +0000 Subject: [PATCH] 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. --- doc/src/sgml/runtime.sgml | 6 ++++-- src/backend/storage/buffer/bufmgr.c | 12 +++++++++--- src/backend/utils/misc/guc.c | 8 ++++---- src/backend/utils/misc/postgresql.conf.sample | 6 +++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index f82fbc877d..b4a84616f5 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -1,5 +1,5 @@ @@ -1305,7 +1305,9 @@ SET ENABLE_SEQSCAN TO OFF; bgwriter_maxpages reduce the extra I/O load caused by the background writer, but leave more work to be done at checkpoint time. To reduce load spikes at checkpoints, - increase the values. + increase the values. To disable background writing entirely, + set bgwriter_percent and/or + bgwriter_maxpages to zero. diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index b9d8fc3ad5..c96c635d0a 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.180 2004/10/16 18:57:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.181 2004/10/17 22:01:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -671,8 +671,10 @@ UnpinBuffer(BufferDesc *buf, bool fixOwner) * * This is called at checkpoint time to write out all dirty shared buffers, * and by the background writer process to write out some of the dirty blocks. - * percent/maxpages should be zero in the former case, and nonzero limit - * values in the latter. + * percent/maxpages should be -1 in the former case, and limit values (>= 0) + * in the latter. + * + * Returns the number of buffers written. */ int BufferSync(int percent, int maxpages) @@ -682,6 +684,10 @@ BufferSync(int percent, int maxpages) int num_buffer_dirty; int i; + /* If either limit is zero then we are disabled from doing anything... */ + if (percent == 0 || maxpages == 0) + return 0; + /* * Get a list of all currently dirty buffers and how many there are. * We do not flush buffers that get dirtied after we started. They diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 5f3ac94bd5..5b5a2a309f 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut . * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.244 2004/10/16 19:08:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.245 2004/10/17 22:01:51 tgl Exp $ * *-------------------------------------------------------------------- */ @@ -1248,7 +1248,7 @@ static struct config_int ConfigureNamesInt[] = NULL }, &BgWriterDelay, - 200, 10, 5000, NULL, NULL + 200, 10, 10000, NULL, NULL }, { @@ -1257,7 +1257,7 @@ static struct config_int ConfigureNamesInt[] = NULL }, &BgWriterPercent, - 1, 1, 100, NULL, NULL + 1, 0, 100, NULL, NULL }, { @@ -1266,7 +1266,7 @@ static struct config_int ConfigureNamesInt[] = NULL }, &BgWriterMaxPages, - 100, 1, 1000, NULL, NULL + 100, 0, 1000, NULL, NULL }, { diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 59004a73c0..3aed76a411 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -98,9 +98,9 @@ # - Background writer - -#bgwriter_delay = 200 # 10-5000 milliseconds -#bgwriter_percent = 1 # 1-100% of dirty buffers -#bgwriter_maxpages = 100 # 1-1000 buffers max at once +#bgwriter_delay = 200 # 10-10000 milliseconds between rounds +#bgwriter_percent = 1 # 0-100% of dirty buffers in each round +#bgwriter_maxpages = 100 # 0-1000 buffers max per round #---------------------------------------------------------------------------