aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2010-01-29 18:39:05 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2010-01-29 18:39:05 +0000
commit6d2bc0a6cf5c8d9a3241a0d7afaf5ca8bf1f11ec (patch)
treea99f7e3490d28b3546b909796ad76c8b6322cf72
parentd0cfc018233b4cdcab28d460ee0e14dbf87ac4ce (diff)
downloadpostgresql-6d2bc0a6cf5c8d9a3241a0d7afaf5ca8bf1f11ec.tar.gz
postgresql-6d2bc0a6cf5c8d9a3241a0d7afaf5ca8bf1f11ec.zip
Augment WAL records for btree delete with GetOldestXmin() to reduce
false positives during Hot Standby conflict processing. Simple patch to enhance conflict processing, following previous discussions. Controlled by parameter minimize_standby_conflicts = on | off, with default off allows measurement of performance impact to see whether it should be set on all the time.
-rw-r--r--doc/src/sgml/config.sgml18
-rw-r--r--src/backend/access/nbtree/nbtpage.c20
-rw-r--r--src/backend/access/transam/xlog.c3
-rw-r--r--src/backend/utils/misc/guc.c13
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample3
-rw-r--r--src/include/access/xlog.h3
6 files changed, 48 insertions, 12 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 71097ee21c8..c8c30c98415 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.246 2010/01/26 16:33:40 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.247 2010/01/29 18:39:05 sriggs Exp $ -->
<chapter Id="runtime-config">
<title>Server Configuration</title>
@@ -1840,6 +1840,22 @@ archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
</listitem>
</varlistentry>
+ <varlistentry id="minimize-standby-conflicts" xreflabel="minimize_standby_conflicts">
+ <term><varname>minimize_standby_conflicts</varname> (<type>boolean</type>)</term>
+ <indexterm>
+ <primary><varname>minimize_standby_conflicts</> configuration parameter</primary>
+ </indexterm>
+ <listitem>
+ <para>
+ Generates additional information to the transaction log (WAL) to minimize
+ the number of false positive cancelations caused by recovery conflicts on
+ a standby server that consumes WAL data from this server.
+ There is additional performance cost to enabling this parameter.
+ Parameter has no effect during recovery, only in normal running.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect2>
</sect1>
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 7cd76e10cf3..5fa4724602f 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.115 2010/01/02 16:57:35 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.116 2010/01/29 18:39:05 sriggs Exp $
*
* NOTES
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -29,6 +29,7 @@
#include "storage/freespace.h"
#include "storage/indexfsm.h"
#include "storage/lmgr.h"
+#include "storage/procarray.h"
#include "utils/inval.h"
#include "utils/snapmgr.h"
@@ -671,9 +672,18 @@ _bt_delitems(Relation rel, Buffer buf,
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
+ TransactionId latestRemovedXid = InvalidTransactionId;
Assert(isVacuum || lastBlockVacuumed == 0);
+ /*
+ * If allowed, calculate an accurate latestRemovedXid, otherwise
+ * pass InvalidTransactionId which can cause false positive
+ * conflicts to be assessed when we replay this WAL record.
+ */
+ if (!isVacuum && XLogStandbyInfoActive() && MinimizeStandbyConflicts)
+ latestRemovedXid = GetOldestXmin(false, true);
+
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
@@ -721,13 +731,7 @@ _bt_delitems(Relation rel, Buffer buf,
xlrec_delete.node = rel->rd_node;
xlrec_delete.block = BufferGetBlockNumber(buf);
- /*
- * XXX: We would like to set an accurate latestRemovedXid, but
- * there is no easy way of obtaining a useful value. So we punt
- * and store InvalidTransactionId, which forces the standby to
- * wait for/cancel all currently running transactions.
- */
- xlrec_delete.latestRemovedXid = InvalidTransactionId;
+ xlrec_delete.latestRemovedXid = latestRemovedXid;
rdata[0].data = (char *) &xlrec_delete;
rdata[0].len = SizeOfBtreeDelete;
}
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 5bee1d8837d..8aa7976e3e3 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.364 2010/01/28 19:17:22 heikki Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.365 2010/01/29 18:39:05 sriggs Exp $
*
*-------------------------------------------------------------------------
*/
@@ -71,6 +71,7 @@ bool XLogArchiveMode = false;
char *XLogArchiveCommand = NULL;
bool XLogRequestRecoveryConnections = true;
int MaxStandbyDelay = 30;
+bool MinimizeStandbyConflicts = false;
bool fullPageWrites = true;
bool log_checkpoints = false;
int sync_method = DEFAULT_SYNC_METHOD;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 00ea55d5979..adf9f72b359 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.536 2010/01/26 16:33:40 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.537 2010/01/29 18:39:05 sriggs Exp $
*
*--------------------------------------------------------------------
*/
@@ -1223,6 +1223,17 @@ static struct config_bool ConfigureNamesBool[] =
},
{
+ {"minimize_standby_conflicts", PGC_POSTMASTER, WAL_SETTINGS,
+ gettext_noop("Additional information is added to WAL records to"
+ " minimize the number of false positive cancelations"
+ " caused by recovery conflicts on WAL standby nodes."),
+ NULL
+ },
+ &MinimizeStandbyConflicts,
+ false, NULL, NULL
+ },
+
+ {
{"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
gettext_noop("Allows modifications of the structure of system tables."),
NULL,
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 95cab4d64fd..928ccc76edf 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -181,7 +181,10 @@
#archive_timeout = 0 # force a logfile segment switch after this
# number of seconds; 0 disables
+# - Hot Standby -
+
#recovery_connections = on # allows connections during recovery
+#minimize_standby_conflicts = on # additional WAL info to avoid conflicts
#max_standby_delay = 30 # max acceptable standby lag (s) to help queries
# complete without conflict; -1 disables
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index d7aeb2fe06b..546452f282f 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.99 2010/01/28 07:31:42 heikki Exp $
+ * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.100 2010/01/29 18:39:05 sriggs Exp $
*/
#ifndef XLOG_H
#define XLOG_H
@@ -183,6 +183,7 @@ extern int XLogArchiveTimeout;
extern bool log_checkpoints;
extern bool XLogRequestRecoveryConnections;
extern int MaxStandbyDelay;
+extern bool MinimizeStandbyConflicts;
#define XLogArchivingActive() (XLogArchiveMode)
#define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')