From 8d4f2ecd41312e57422901952cbad234d293060b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 23 Apr 2009 00:23:46 +0000 Subject: Change the default value of max_prepared_transactions to zero, and add documentation warnings against setting it nonzero unless active use of prepared transactions is intended and a suitable transaction manager has been installed. This should help to prevent the type of scenario we've seen several times now where a prepared transaction is forgotten and eventually causes severe maintenance problems (or even anti-wraparound shutdown). The only real reason we had the default be nonzero in the first place was to support regression testing of the feature. To still be able to do that, tweak pg_regress to force a nonzero value during "make check". Since we cannot force a nonzero value in "make installcheck", add a variant regression test "expected" file that shows the results that will be obtained when max_prepared_transactions is zero. Also, extend the HINT messages for transaction wraparound warnings to mention the possibility that old prepared transactions are causing the problem. All per today's discussion. --- src/backend/access/transam/twophase.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/backend/access/transam/twophase.c') diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index b738a4cef46..4685ccdf10b 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.51 2009/01/01 17:23:36 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.52 2009/04/23 00:23:45 tgl Exp $ * * NOTES * Each global transaction is associated with a global transaction @@ -68,7 +68,7 @@ #define TWOPHASE_DIR "pg_twophase" /* GUC variable, can't be changed after startup */ -int max_prepared_xacts = 5; +int max_prepared_xacts = 0; /* * This struct describes one global transaction that is in prepared state @@ -228,6 +228,13 @@ MarkAsPreparing(TransactionId xid, const char *gid, errmsg("transaction identifier \"%s\" is too long", gid))); + /* fail immediately if feature is disabled */ + if (max_prepared_xacts == 0) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("prepared transactions are disabled"), + errhint("Set max_prepared_transactions to a nonzero value."))); + LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE); /* -- cgit v1.2.3