Disallow committing a prepared transaction unless we are in the same database
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Feb 2007 19:39:55 +0000 (19:39 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Feb 2007 19:39:55 +0000 (19:39 +0000)
it was executed in.  Someday it might be nice to allow cross-DB commits, but
work would be needed in NOTIFY and perhaps other places.  Per Heikki.

src/backend/access/transam/twophase.c

index 79a321d38b428cce77d81174be0c2afea0a4b87c..6fe57e0e0642f3917f448037b896c70cea7e0ab2 100644 (file)
@@ -390,6 +390,18 @@ LockGXact(const char *gid, Oid user)
                                  errmsg("permission denied to finish prepared transaction"),
                                         errhint("Must be superuser or the user that prepared the transaction.")));
 
+               /*
+                * Note: it probably would be possible to allow committing from another
+                * database; but at the moment NOTIFY is known not to work and there
+                * may be some other issues as well.  Hence disallow until someone
+                * gets motivated to make it work.
+                */
+               if (MyDatabaseId != gxact->proc.databaseId)
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                        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();