Commit 9d645fd8 authored by Tom Lane's avatar Tom Lane

Support syncing WAL log to disk using either fsync(), fdatasync(),

O_SYNC, or O_DSYNC (as available on a given platform).  Add GUC parameter
to control sync method.
Also, add defense to XLogWrite to prevent it from going nuts if passed
a target write position that's past the end of the buffers so far filled
by XLogInsert.
parent 4eb5e27a
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.56 2001/03/13 01:17:05 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.57 2001/03/16 05:44:33 tgl Exp $
--> -->
<Chapter Id="runtime"> <Chapter Id="runtime">
...@@ -1224,8 +1224,8 @@ env PGOPTIONS='-c geqo=off' psql ...@@ -1224,8 +1224,8 @@ env PGOPTIONS='-c geqo=off' psql
<term>WAL_BUFFERS (<type>integer</type>)</term> <term>WAL_BUFFERS (<type>integer</type>)</term>
<listitem> <listitem>
<para> <para>
Number of disk-page buffers for WAL log. This option can only be set Number of disk-page buffers in shared memory for WAL log.
at server start. This option can only be set at server start.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1250,6 +1250,23 @@ env PGOPTIONS='-c geqo=off' psql ...@@ -1250,6 +1250,23 @@ env PGOPTIONS='-c geqo=off' psql
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>WAL_SYNC_METHOD (<type>string</type>)</term>
<listitem>
<para>
Method used for forcing WAL updates out to disk. Possible
values are
<literal>FSYNC</> (call fsync() at each commit),
<literal>FDATASYNC</> (call fdatasync() at each commit),
<literal>OPEN_SYNC</> (write WAL files with open() option O_SYNC), or
<literal>OPEN_DATASYNC</> (write WAL files with open() option O_DSYNC).
Not all of these choices are available on all platforms.
This option can only be set at server start or in the
<filename>postgresql.conf</filename> file.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
</sect2> </sect2>
......
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/wal.sgml,v 1.4 2001/03/13 01:17:05 tgl Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/wal.sgml,v 1.5 2001/03/16 05:44:33 tgl Exp $ -->
<chapter id="wal"> <chapter id="wal">
<title>Write-Ahead Logging (<acronym>WAL</acronym>)</title> <title>Write-Ahead Logging (<acronym>WAL</acronym>)</title>
...@@ -281,15 +281,6 @@ ...@@ -281,15 +281,6 @@
<command>CHECKPOINT</command>. <command>CHECKPOINT</command>.
</para> </para>
<para>
Setting the <varname>WAL_DEBUG</varname> parameter to any non-zero
value will result in each <function>LogInsert</function> and
<function>LogFlush</function> <acronym>WAL</acronym> call being
logged to standard error. At present, it makes no difference what
the non-zero value is. This option may be replaced by a more
general mechanism in the future.
</para>
<para> <para>
The <varname>COMMIT_DELAY</varname> parameter defines for how many The <varname>COMMIT_DELAY</varname> parameter defines for how many
microseconds the backend will sleep after writing a commit microseconds the backend will sleep after writing a commit
...@@ -304,6 +295,24 @@ ...@@ -304,6 +295,24 @@
ten milliseconds, so that any nonzero <varname>COMMIT_DELAY</varname> ten milliseconds, so that any nonzero <varname>COMMIT_DELAY</varname>
setting between 1 and 10000 microseconds will have the same effect. setting between 1 and 10000 microseconds will have the same effect.
</para> </para>
<para>
The <varname>WAL_SYNC_METHOD</varname> parameter determines how
Postgres will ask the kernel to force WAL updates out to disk.
All the options should be the same as far as reliability goes,
but it's quite platform-specific which one will be the fastest.
Note that this parameter is irrelevant if <varname>FSYNC</varname>
has been turned off.
</para>
<para>
Setting the <varname>WAL_DEBUG</varname> parameter to any non-zero
value will result in each <function>LogInsert</function> and
<function>LogFlush</function> <acronym>WAL</acronym> call being
logged to standard error. At present, it makes no difference what
the non-zero value is. This option may be replaced by a more
general mechanism in the future.
</para>
</sect1> </sect1>
</chapter> </chapter>
......
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET * Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options. * command, configuration file, and command line options.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.32 2001/03/13 01:17:06 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.33 2001/03/16 05:44:33 tgl Exp $
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "utils/guc.h" #include "utils/guc.h"
#include "access/xlog.h"
#include "commands/async.h" #include "commands/async.h"
#include "libpq/auth.h" #include "libpq/auth.h"
#include "libpq/pqcomm.h" #include "libpq/pqcomm.h"
...@@ -33,23 +34,17 @@ ...@@ -33,23 +34,17 @@
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
/* XXX should be in a header file */ /* XXX these should be in other modules' header files */
extern bool Log_connections; extern bool Log_connections;
extern int CheckPointSegments;
extern int CheckPointTimeout; extern int CheckPointTimeout;
extern int XLOGbuffers;
extern int XLOGfiles;
extern int XLOG_DEBUG;
extern int CommitDelay; extern int CommitDelay;
extern int CommitSiblings; extern int CommitSiblings;
extern bool FixBTree; extern bool FixBTree;
#ifdef ENABLE_SYSLOG #ifdef ENABLE_SYSLOG
extern char *Syslog_facility; extern char *Syslog_facility;
extern char *Syslog_ident; extern char *Syslog_ident;
bool check_facility(const char *facility); static bool check_facility(const char *facility);
#endif #endif
/* /*
...@@ -138,7 +133,8 @@ struct config_string ...@@ -138,7 +133,8 @@ struct config_string
GucContext context; GucContext context;
char **variable; char **variable;
const char *default_val; const char *default_val;
bool (*parse_hook)(const char *); bool (*parse_hook)(const char *proposed);
void (*assign_hook)(const char *newval);
}; };
...@@ -330,25 +326,29 @@ static struct config_string ...@@ -330,25 +326,29 @@ static struct config_string
ConfigureNamesString[] = ConfigureNamesString[] =
{ {
{"krb_server_keyfile", PGC_POSTMASTER, &pg_krb_server_keyfile, {"krb_server_keyfile", PGC_POSTMASTER, &pg_krb_server_keyfile,
PG_KRB_SRVTAB, NULL}, PG_KRB_SRVTAB, NULL, NULL},
{"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group,
"", NULL},
#ifdef ENABLE_SYSLOG #ifdef ENABLE_SYSLOG
{"syslog_facility", PGC_POSTMASTER, &Syslog_facility, {"syslog_facility", PGC_POSTMASTER, &Syslog_facility,
"LOCAL0", check_facility}, "LOCAL0", check_facility, NULL},
{"syslog_ident", PGC_POSTMASTER, &Syslog_ident, {"syslog_ident", PGC_POSTMASTER, &Syslog_ident,
"postgres", NULL}, "postgres", NULL, NULL},
#endif #endif
{"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group,
"", NULL, NULL},
{"unix_socket_directory", PGC_POSTMASTER, &UnixSocketDir, {"unix_socket_directory", PGC_POSTMASTER, &UnixSocketDir,
"", NULL}, "", NULL, NULL},
{"virtual_host", PGC_POSTMASTER, &VirtualHost, {"virtual_host", PGC_POSTMASTER, &VirtualHost,
"", NULL}, "", NULL, NULL},
{NULL, 0, NULL, NULL, NULL} {"wal_sync_method", PGC_SIGHUP, &XLOG_sync_method,
XLOG_sync_method_default,
check_xlog_sync_method, assign_xlog_sync_method},
{NULL, 0, NULL, NULL, NULL, NULL}
}; };
/******** end of options list ********/ /******** end of options list ********/
...@@ -723,7 +723,10 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -723,7 +723,10 @@ set_config_option(const char * name, const char * value, GucContext
elog(elevel, "out of memory"); elog(elevel, "out of memory");
return false; return false;
} }
free(*conf->variable); if (conf->assign_hook)
(conf->assign_hook)(str);
if (*conf->variable)
free(*conf->variable);
*conf->variable = str; *conf->variable = str;
} }
} }
...@@ -737,7 +740,10 @@ set_config_option(const char * name, const char * value, GucContext ...@@ -737,7 +740,10 @@ set_config_option(const char * name, const char * value, GucContext
elog(elevel, "out of memory"); elog(elevel, "out of memory");
return false; return false;
} }
free(*conf->variable); if (conf->assign_hook)
(conf->assign_hook)(str);
if (*conf->variable)
free(*conf->variable);
*conf->variable = str; *conf->variable = str;
} }
break; break;
...@@ -855,7 +861,7 @@ ParseLongOption(const char * string, char ** name, char ** value) ...@@ -855,7 +861,7 @@ ParseLongOption(const char * string, char ** name, char ** value)
#ifdef ENABLE_SYSLOG #ifdef ENABLE_SYSLOG
bool static bool
check_facility(const char *facility) check_facility(const char *facility)
{ {
if (strcasecmp(facility,"LOCAL0") == 0) return true; if (strcasecmp(facility,"LOCAL0") == 0) return true;
......
...@@ -107,6 +107,8 @@ ...@@ -107,6 +107,8 @@
# #
#wal_buffers = 8 # min 4 #wal_buffers = 8 # min 4
#wal_files = 0 # range 0-64 #wal_files = 0 # range 0-64
#wal_sync_method = fsync # fsync or fdatasync or open_sync or open_datasync
# Note: default wal_sync_method varies across platforms
#wal_debug = 0 # range 0-16 #wal_debug = 0 # range 0-16
#commit_delay = 0 # range 0-100000 #commit_delay = 0 # range 0-100000
#commit_siblings = 5 # range 1-1000 #commit_siblings = 5 # range 1-1000
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: xlog.h,v 1.20 2001/03/13 20:32:37 tgl Exp $ * $Id: xlog.h,v 1.21 2001/03/16 05:44:33 tgl Exp $
*/ */
#ifndef XLOG_H #ifndef XLOG_H
#define XLOG_H #define XLOG_H
...@@ -176,6 +176,15 @@ extern StartUpID ThisStartUpID; /* current SUI */ ...@@ -176,6 +176,15 @@ extern StartUpID ThisStartUpID; /* current SUI */
extern bool InRecovery; extern bool InRecovery;
extern XLogRecPtr MyLastRecPtr; extern XLogRecPtr MyLastRecPtr;
/* these variables are GUC parameters related to XLOG */
extern int CheckPointSegments;
extern int XLOGbuffers;
extern int XLOGfiles;
extern int XLOG_DEBUG;
extern char *XLOG_sync_method;
extern const char XLOG_sync_method_default[];
extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata); extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
extern void XLogFlush(XLogRecPtr RecPtr); extern void XLogFlush(XLogRecPtr RecPtr);
...@@ -202,4 +211,7 @@ extern void GetRedoRecPtr(void); ...@@ -202,4 +211,7 @@ extern void GetRedoRecPtr(void);
*/ */
extern XLogRecPtr GetUndoRecPtr(void); extern XLogRecPtr GetUndoRecPtr(void);
extern bool check_xlog_sync_method(const char *method);
extern void assign_xlog_sync_method(const char *method);
#endif /* XLOG_H */ #endif /* XLOG_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment