Thread: Forbid finishing a prepared transaction from another database

Forbid finishing a prepared transaction from another database

From
Heikki Linnakangas
Date:
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();


Re: Forbid finishing a prepared transaction from another database

From
Tom Lane
Date:
Heikki Linnakangas <heikki@enterprisedb.com> writes:
> Throw an error if you try to COMMIT/ROLLBACK PREPARED from a database
> other than the one where the transaction was originally prepared.

Committed, but I made it ERRCODE_FEATURE_NOT_SUPPORTED, since this seems
to me to be in the nature of something we might fix someday (if anyone
gets motivated enough), not a that's-nonsensical error.

            regards, tom lane