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

Commit 326a7a0

Browse files
committed
Add GUC full_page_writes to control writing full pages to WAL.
1 parent c19aa70 commit 326a7a0

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

doc/src/sgml/runtime.sgml

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.335 2005/07/02 19:16:36 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.336 2005/07/05 23:18:09 momjian Exp $
33
-->
44

55
<chapter Id="runtime">
@@ -1660,7 +1660,9 @@ SET ENABLE_SEQSCAN TO OFF;
16601660

16611661
<para>
16621662
This option can only be set at server start or in the
1663-
<filename>postgresql.conf</filename> file.
1663+
<filename>postgresql.conf</filename> file. If this option
1664+
is <literal>off</>, consider also turning off
1665+
<varname>guc-full-page-writes</>.
16641666
</para>
16651667
</listitem>
16661668
</varlistentry>
@@ -1687,6 +1689,37 @@ SET ENABLE_SEQSCAN TO OFF;
16871689
</listitem>
16881690
</varlistentry>
16891691

1692+
<varlistentry id="guc-full-page-writes" xreflabel="full_page_writes">
1693+
<indexterm>
1694+
<primary><varname>full_page_writes</> configuration parameter</primary>
1695+
</indexterm>
1696+
<term><varname>full_page_writes</varname> (<type>boolean</type>)</term>
1697+
<listitem>
1698+
<para>
1699+
A page write in process during an operating system crash might
1700+
be only partially written to disk, leading to an on-disk page
1701+
that contains a mix of old and new data. During recovery, the
1702+
row changes stored in WAL are not enough to completely restore
1703+
the page.
1704+
</para>
1705+
1706+
<para>
1707+
When this option is on, the <productname>PostgreSQL</> server
1708+
writes full pages to WAL when they first modified after a checkpoint
1709+
so full recovery is possible. Turning this option off might lead
1710+
to a corrupt system after an operating system crash because
1711+
uncorrected partial pages might contain inconsistent or corrupt
1712+
data. The risks are less but similar to <varname>fsync</>.
1713+
</para>
1714+
1715+
<para>
1716+
This option can only be set at server start or in the
1717+
<filename>postgresql.conf</filename> file. The default is
1718+
<literal>on</>.
1719+
</para>
1720+
</listitem>
1721+
</varlistentry>
1722+
16901723
<varlistentry id="guc-wal-buffers" xreflabel="wal_buffers">
16911724
<term><varname>wal_buffers</varname> (<type>integer</type>)</term>
16921725
<indexterm>

src/backend/access/transam/xlog.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.206 2005/07/04 04:51:44 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.207 2005/07/05 23:18:09 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -103,6 +103,7 @@ int XLOGbuffers = 8;
103103
char *XLogArchiveCommand = NULL;
104104
char *XLOG_sync_method = NULL;
105105
const char XLOG_sync_method_default[] = DEFAULT_SYNC_METHOD_STR;
106+
bool fullPageWrites = true;
106107

107108
#ifdef WAL_DEBUG
108109
bool XLOG_DEBUG = false;
@@ -594,7 +595,9 @@ begin:;
594595
{
595596
/* OK, put it in this slot */
596597
dtbuf[i] = rdt->buffer;
597-
if (XLogCheckBuffer(rdt, &(dtbuf_lsn[i]), &(dtbuf_xlg[i])))
598+
/* If fsync is off, no need to backup pages. */
599+
if (fullPageWrites &&
600+
XLogCheckBuffer(rdt, &(dtbuf_lsn[i]), &(dtbuf_xlg[i])))
598601
{
599602
dtbuf_bkp[i] = true;
600603
rdt->data = NULL;

src/backend/utils/misc/guc.c

+14-1
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.272 2005/07/04 04:51:51 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.273 2005/07/05 23:18:10 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -83,6 +83,7 @@ extern DLLIMPORT bool check_function_bodies;
8383
extern int CommitDelay;
8484
extern int CommitSiblings;
8585
extern char *default_tablespace;
86+
extern bool fullPageWrites;
8687

8788
static const char *assign_log_destination(const char *value,
8889
bool doit, GucSource source);
@@ -482,6 +483,18 @@ static struct config_bool ConfigureNamesBool[] =
482483
&zero_damaged_pages,
483484
false, NULL, NULL
484485
},
486+
{
487+
{"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
488+
gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
489+
gettext_noop("A page write in process during an operating system crash might be "
490+
"only partially written to disk. During recovery, the row changes"
491+
"stored in WAL are not enough to recover. This option writes "
492+
"pages when first modified after a checkpoint to WAL so full recovery "
493+
"is possible.")
494+
},
495+
&fullPageWrites,
496+
true, NULL, NULL
497+
},
485498
{
486499
{"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
487500
gettext_noop("Runs the server silently."),

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

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
#wal_sync_method = fsync # the default varies across platforms:
122122
# fsync, fdatasync, fsync_writethrough,
123123
# open_sync, open_datasync
124+
#full_page_writes = on # recover from partial page writes
124125
#wal_buffers = 8 # min 4, 8KB each
125126
#commit_delay = 0 # range 0-100000, in microseconds
126127
#commit_siblings = 5 # range 1-1000

0 commit comments

Comments
 (0)