Rearrange order of pre-commit operations: must close cursors before doing
authorTom Lane <[email protected]>
Fri, 29 Oct 2004 22:20:03 +0000 (22:20 +0000)
committerTom Lane <[email protected]>
Fri, 29 Oct 2004 22:20:03 +0000 (22:20 +0000)
ON COMMIT actions.  Per bug report from Michael Guerin.

src/backend/access/transam/xact.c

index 3409de03a5642482a7ba019f187105ce6731b877..266b31e0b3e3df12c99abd3d6608392210c20708 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.156.2.1 2004/08/11 04:08:00 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.156.2.2 2004/10/29 22:20:03 tgl Exp $
  *
  * NOTES
  *     Transaction aborts can now occur two ways:
@@ -916,6 +916,11 @@ CommitTransaction(void)
    if (s->state != TRANS_INPROGRESS)
        elog(WARNING, "CommitTransaction and not in in-progress state");
 
+   /*
+    * Do pre-commit processing (most of this stuff requires database
+    * access, and in fact could still cause an error...)
+    */
+
    /*
     * Tell the trigger manager that this transaction is about to be
     * committed. He'll invoke all trigger deferred until XACT before we
@@ -923,27 +928,14 @@ CommitTransaction(void)
     */
    DeferredTriggerEndXact();
 
-   /*
-    * Similarly, let ON COMMIT management do its thing before we start to
-    * commit.
-    */
-   PreCommit_on_commit_actions();
-
-   /* Prevent cancel/die interrupt while cleaning up */
-   HOLD_INTERRUPTS();
-
-   /*
-    * set the current transaction state information appropriately during
-    * the abort processing
-    */
-   s->state = TRANS_COMMIT;
+   /* Close open cursors */
+   AtCommit_Portals();
 
    /*
-    * Do pre-commit processing (most of this stuff requires database
-    * access, and in fact could still cause an error...)
+    * Let ON COMMIT management do its thing (must happen after closing
+    * cursors, to avoid dangling-reference problems)
     */
-
-   AtCommit_Portals();
+   PreCommit_on_commit_actions();
 
    /* handle commit for large objects [ PA, 7/17/98 ] */
    /* XXX probably this does not belong here */
@@ -955,6 +947,15 @@ CommitTransaction(void)
    /* Update the flat password file if we changed pg_shadow or pg_group */
    AtEOXact_UpdatePasswordFile(true);
 
+   /* Prevent cancel/die interrupt while cleaning up */
+   HOLD_INTERRUPTS();
+
+   /*
+    * set the current transaction state information appropriately during
+    * the abort processing
+    */
+   s->state = TRANS_COMMIT;
+
    /*
     * Here is where we really truly commit.
     */