Added GUC variable bgwriter_flush_method controlling the action
authorJan Wieck
Sat, 24 Jan 2004 20:00:46 +0000 (20:00 +0000)
committerJan Wieck
Sat, 24 Jan 2004 20:00:46 +0000 (20:00 +0000)
done by the background writer between writing dirty blocks and
napping.

    none (default)   no action
sync             bgwriter calls smgrsync() causing a sync(2)

A global sync() is only good on dedicated database servers, so
more flush methods should be added in the future.

Jan

src/backend/storage/buffer/bufmgr.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/include/storage/bufmgr.h

index 64c5800dc494ecb9c0a309c63f68c357ada9cf89..5eee0c5bbc74e06a8e2219a5346e4152b818d7e9 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.152 2004/01/09 21:08:49 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.153 2004/01/24 20:00:45 wieck Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -55,6 +55,7 @@
 #include "storage/proc.h"
 #include "storage/smgr.h"
 #include "utils/relcache.h"
+#include "utils/guc.h"
 
 #include "pgstat.h"
 
 /* GUC variable */
 bool       zero_damaged_pages = false;
 
+#define    BGWRITER_FLUSH_NONE         0
+#define    BGWRITER_FLUSH_NONE_STR     "none"
+#define    BGWRITER_FLUSH_SYNC         1
+#define    BGWRITER_FLUSH_SYNC_STR     "sync"
+
+#define    BGWRITER_FLUSH_DEFAULT      BGWRITER_FLUSH_NONE
+#define    BGWRITER_FLUSH_DEFAULT_STR  BGWRITER_FLUSH_NONE_STR
+
 int            BgWriterDelay = 200;
 int            BgWriterPercent = 1;
 int            BgWriterMaxpages = 100;
+int            BgWriterFlushMethod = BGWRITER_FLUSH_NONE;
+char      *BgWriterFlushMethod_str = NULL;
+const char BgWriterFlushMethod_default[] = BGWRITER_FLUSH_DEFAULT_STR;
+
+const char *BgWriterAssignSyncMethod(const char *method,
+            bool doit, GucSource source);
 
 static void WaitIO(BufferDesc *buf);
 static void StartBufferIO(BufferDesc *buf, bool forInput);
@@ -1026,6 +1041,19 @@ BufferBackgroundWriter(void)
        if (InterruptPending)
            return;
 
+       /*
+        * Perform the configured buffer flush method
+        */
+       switch (BgWriterFlushMethod)
+       {
+           case BGWRITER_FLUSH_NONE:
+               break;
+
+           case BGWRITER_FLUSH_SYNC:
+               smgrsync();
+               break;
+       }
+
        /*
         * Nap for the configured time or sleep for 10 seconds if
         * there was nothing to do at all.
@@ -1037,6 +1065,27 @@ BufferBackgroundWriter(void)
    }
 }
 
+const char *
+BgWriterAssignSyncMethod(const char *method, bool doit, GucSource source)
+{
+   int     new_flush_method;
+
+   if (strcasecmp(method, BGWRITER_FLUSH_NONE_STR) == 0)
+       new_flush_method = BGWRITER_FLUSH_NONE;
+   else 
+   if (strcasecmp(method, BGWRITER_FLUSH_SYNC_STR) == 0)
+       new_flush_method = BGWRITER_FLUSH_SYNC;
+   else
+       return NULL;
+   
+   if (!doit)
+       return method;
+
+   BgWriterFlushMethod = new_flush_method;
+   return method;
+}
+            
+
 /*
  * Do whatever is needed to prepare for commit at the bufmgr and smgr levels
  */
index 04a7e7287b1b625ad1c275d743bd16e1a856e30e..7b3bde2d0c2121b97bc998562a8d3bcbe1a81f0e 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut .
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.179 2004/01/23 23:54:21 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.180 2004/01/24 20:00:45 wieck Exp $
  *
  *--------------------------------------------------------------------
  */
@@ -95,6 +95,8 @@ static const char *assign_msglvl(int *var, const char *newval,
 static const char *assign_log_error_verbosity(const char *newval, bool doit,
                           GucSource source);
 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
+extern const char *BgWriterAssignSyncMethod(const char *method,
+                          bool doit, GucSource source);
 
 
 /*
@@ -1689,6 +1691,15 @@ static struct config_string ConfigureNamesString[] =
        XLOG_sync_method_default, assign_xlog_sync_method, NULL
    },
 
+   {
+       {"bgwriter_flush_method", PGC_SIGHUP, RESOURCES,
+           gettext_noop("Selects the method used by the bgwriter for forcing writes out to disk."),
+           NULL
+       },
+       &BgWriterFlushMethod_str,
+       BgWriterFlushMethod_default, BgWriterAssignSyncMethod, NULL
+   },
+
    /* End-of-list marker */
    {
        {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
index 30e7ebe1670d1b8f8d168402cbdbcfdb32438cd7..530e8c7952ba5f43e759a83e7317212f5a6917ac 100644 (file)
 #debug_shared_buffers = 0  # 0-600 seconds
 
 # - Background writer -
+#debug_shared_buffers = 0  # 0-600 seconds interval (0 = off)
 #bgwriter_delay = 200      # 10-5000 milliseconds
 #bgwriter_percent = 1      # 0-100% of dirty buffers
 #bgwriter_maxpages = 100   # 1-1000 buffers max at once
+#bgwriter_flush_method = none # how the bgwriter flushes kernel buffers
+                           # one of: none or sync
 
 # - Free Space Map -
 
index 7f955ceef3a39ac595b32e90594dbc02502967be..adb45b307f6d503ed1a03d4c9a6dd3deda755257 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.73 2003/12/14 00:34:47 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.74 2004/01/24 20:00:46 wieck Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,6 +31,8 @@ extern bool zero_damaged_pages;
 extern int BgWriterDelay;
 extern int BgWriterPercent;
 extern int BgWriterMaxpages;
+extern char *BgWriterFlushMethod_str;
+extern const char BgWriterFlushMethod_default[];
 
 
 /* in buf_init.c */
@@ -180,8 +182,6 @@ extern void AbortBufferIO(void);
 extern void BufmgrCommit(void);
 extern int BufferSync(int percent, int maxpages);
 extern void BufferBackgroundWriter(void);
-extern const char *BgWriterAssignSyncMethod(const char *method,
-           bool doid, bool interactive);
 
 extern void InitLocalBuffer(void);