Skip to content

Commit d77b63b

Browse files
Jan WieckJan Wieck
authored andcommitted
Added GUC variable bgwriter_flush_method controlling the action
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
1 parent 610d33c commit d77b63b

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 50 additions & 1 deletion
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.152 2004/01/09 21:08:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.153 2004/01/24 20:00:45 wieck Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -55,6 +55,7 @@
5555
#include "storage/proc.h"
5656
#include "storage/smgr.h"
5757
#include "utils/relcache.h"
58+
#include "utils/guc.h"
5859

5960
#include "pgstat.h"
6061

@@ -65,9 +66,23 @@
6566
/* GUC variable */
6667
bool zero_damaged_pages = false;
6768

69+
#define BGWRITER_FLUSH_NONE 0
70+
#define BGWRITER_FLUSH_NONE_STR "none"
71+
#define BGWRITER_FLUSH_SYNC 1
72+
#define BGWRITER_FLUSH_SYNC_STR "sync"
73+
74+
#define BGWRITER_FLUSH_DEFAULT BGWRITER_FLUSH_NONE
75+
#define BGWRITER_FLUSH_DEFAULT_STR BGWRITER_FLUSH_NONE_STR
76+
6877
int BgWriterDelay = 200;
6978
int BgWriterPercent = 1;
7079
int BgWriterMaxpages = 100;
80+
int BgWriterFlushMethod = BGWRITER_FLUSH_NONE;
81+
char *BgWriterFlushMethod_str = NULL;
82+
const char BgWriterFlushMethod_default[] = BGWRITER_FLUSH_DEFAULT_STR;
83+
84+
const char *BgWriterAssignSyncMethod(const char *method,
85+
bool doit, GucSource source);
7186

7287
static void WaitIO(BufferDesc *buf);
7388
static void StartBufferIO(BufferDesc *buf, bool forInput);
@@ -1026,6 +1041,19 @@ BufferBackgroundWriter(void)
10261041
if (InterruptPending)
10271042
return;
10281043

1044+
/*
1045+
* Perform the configured buffer flush method
1046+
*/
1047+
switch (BgWriterFlushMethod)
1048+
{
1049+
case BGWRITER_FLUSH_NONE:
1050+
break;
1051+
1052+
case BGWRITER_FLUSH_SYNC:
1053+
smgrsync();
1054+
break;
1055+
}
1056+
10291057
/*
10301058
* Nap for the configured time or sleep for 10 seconds if
10311059
* there was nothing to do at all.
@@ -1037,6 +1065,27 @@ BufferBackgroundWriter(void)
10371065
}
10381066
}
10391067

1068+
const char *
1069+
BgWriterAssignSyncMethod(const char *method, bool doit, GucSource source)
1070+
{
1071+
int new_flush_method;
1072+
1073+
if (strcasecmp(method, BGWRITER_FLUSH_NONE_STR) == 0)
1074+
new_flush_method = BGWRITER_FLUSH_NONE;
1075+
else
1076+
if (strcasecmp(method, BGWRITER_FLUSH_SYNC_STR) == 0)
1077+
new_flush_method = BGWRITER_FLUSH_SYNC;
1078+
else
1079+
return NULL;
1080+
1081+
if (!doit)
1082+
return method;
1083+
1084+
BgWriterFlushMethod = new_flush_method;
1085+
return method;
1086+
}
1087+
1088+
10401089
/*
10411090
* Do whatever is needed to prepare for commit at the bufmgr and smgr levels
10421091
*/

src/backend/utils/misc/guc.c

Lines changed: 12 additions & 1 deletion
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.179 2004/01/23 23:54:21 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.180 2004/01/24 20:00:45 wieck Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -95,6 +95,8 @@ static const char *assign_msglvl(int *var, const char *newval,
9595
static const char *assign_log_error_verbosity(const char *newval, bool doit,
9696
GucSource source);
9797
static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
98+
extern const char *BgWriterAssignSyncMethod(const char *method,
99+
bool doit, GucSource source);
98100

99101

100102
/*
@@ -1689,6 +1691,15 @@ static struct config_string ConfigureNamesString[] =
16891691
XLOG_sync_method_default, assign_xlog_sync_method, NULL
16901692
},
16911693

1694+
{
1695+
{"bgwriter_flush_method", PGC_SIGHUP, RESOURCES,
1696+
gettext_noop("Selects the method used by the bgwriter for forcing writes out to disk."),
1697+
NULL
1698+
},
1699+
&BgWriterFlushMethod_str,
1700+
BgWriterFlushMethod_default, BgWriterAssignSyncMethod, NULL
1701+
},
1702+
16921703
/* End-of-list marker */
16931704
{
16941705
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@
6161
#debug_shared_buffers = 0 # 0-600 seconds
6262

6363
# - Background writer -
64+
#debug_shared_buffers = 0 # 0-600 seconds interval (0 = off)
6465
#bgwriter_delay = 200 # 10-5000 milliseconds
6566
#bgwriter_percent = 1 # 0-100% of dirty buffers
6667
#bgwriter_maxpages = 100 # 1-1000 buffers max at once
68+
#bgwriter_flush_method = none # how the bgwriter flushes kernel buffers
69+
# one of: none or sync
6770

6871
# - Free Space Map -
6972

src/include/storage/bufmgr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.73 2003/12/14 00:34:47 neilc Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.74 2004/01/24 20:00:46 wieck Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,6 +31,8 @@ extern bool zero_damaged_pages;
3131
extern int BgWriterDelay;
3232
extern int BgWriterPercent;
3333
extern int BgWriterMaxpages;
34+
extern char *BgWriterFlushMethod_str;
35+
extern const char BgWriterFlushMethod_default[];
3436

3537

3638
/* in buf_init.c */
@@ -180,8 +182,6 @@ extern void AbortBufferIO(void);
180182
extern void BufmgrCommit(void);
181183
extern int BufferSync(int percent, int maxpages);
182184
extern void BufferBackgroundWriter(void);
183-
extern const char *BgWriterAssignSyncMethod(const char *method,
184-
bool doid, bool interactive);
185185

186186
extern void InitLocalBuffer(void);
187187

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy