Forbid finishing a prepared transaction from another database - Mailing list pgsql-patches

From Heikki Linnakangas
Subject Forbid finishing a prepared transaction from another database
Date
Msg-id 45D20728.1090302@enterprisedb.com
Whole thread Raw
Responses Re: Forbid finishing a prepared transaction from another database
List pgsql-patches
Here's a patch to:

Throw an error if you try to COMMIT/ROLLBACK PREPARED from a database
other than the one where the transaction was originally prepared.

This needs to be fixed because at least NOTIFY/LISTEN gets confused, and
sends the notification to the database where the commit is done, not the
database where the transaction ran originally. And there might be other
places that get confused as well.

It turned out to be even simpler than I imagined. :)

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
Index: src/backend/access/transam/twophase.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/backend/access/transam/twophase.c,v
retrieving revision 1.27
diff -c -r1.27 twophase.c
*** src/backend/access/transam/twophase.c    16 Jan 2007 13:28:56 -0000    1.27
--- src/backend/access/transam/twophase.c    13 Feb 2007 18:39:04 -0000
***************
*** 393,398 ****
--- 393,404 ----
                    errmsg("permission denied to finish prepared transaction"),
                       errhint("Must be superuser or the user that prepared the transaction.")));

+         if (MyProc->databaseId != gxact->proc.databaseId)
+             ereport(ERROR,
+                     (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+                   errmsg("prepared transaction belongs to another database"),
+                      errhint("Connect to the database where the transaction was prepared to finish it.")));
+
          /* OK for me to lock it */
          gxact->locking_xid = GetTopTransactionId();


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] contrib/levenshtein() has a bug?
Next
From: Tom Dunstan
Date:
Subject: Re: Enums patch v2