@@ -135,14 +135,39 @@ mtm_commit_cleanup(int status, Datum arg)
135135/* there was no precommit, we can abort */
136136PG_TRY ();
137137{
138- AbortOutOfAnyTransaction ();
139- StartTransactionCommand ();
138+ #ifdef PGPRO_EE
139+ int atxLevel = DatumGetInt32 (arg );
140+
141+ /*
142+ * If we are inside ATX transaction, we can not call
143+ * AbortOutOfAnyTransaction() because this call will abort
144+ * ALL transactions and we will have problems if the
145+ * calling code is not designed for this case.
146+ */
147+ if (atxLevel )
148+ {
149+ /* Abort (current ATX transaction only): */
150+ AbortCurrentTransaction ();
151+ /* Restart ATX transaction if it was resumed: */
152+ if (atxLevel > getNestLevelATX ())
153+ SuspendTransaction ();
154+ }
155+ else
156+ #endif
157+ {
158+ AbortOutOfAnyTransaction ();
159+ StartTransactionCommand ();
160+ }
140161FinishPreparedTransaction (mtm_commit_state .gid , false, false);
141162mtm_commit_state .gtx -> state .status = GTXAborted ;
142163mtm_log (MtmTxFinish ,"%s aborted as own orphaned not precomitted" ,
143164mtm_commit_state .gid );
144165CommitTransactionCommand ();
145-
166+ #ifdef PGPRO_EE
167+ /* Restart ATX transaction if it was resumed: */
168+ if (atxLevel > getNestLevelATX ())
169+ SuspendTransaction ();
170+ #endif
146171}
147172/*
148173 * this should be extremely unlikely, but if we fail, don't
@@ -218,7 +243,7 @@ MtmBeginTransaction()
218243 * register gtx hook first (it will be called last)
219244 */
220245GlobalTxEnsureBeforeShmemExitHook ();
221- before_shmem_exit (mtm_commit_cleanup ,Int32GetDatum (1 ));
246+ before_shmem_exit (mtm_commit_cleanup ,Int32GetDatum (0 ));
222247mtm_commit_state .mctx = AllocSetContextCreate (TopMemoryContext ,
223248"MtmCommitContext" ,
224249ALLOCSET_DEFAULT_SIZES );
@@ -373,6 +398,9 @@ MtmTwoPhaseCommit(void)
373398MtmGeneration xact_gen ;
374399char dmq_stream_name [DMQ_STREAM_NAME_MAXLEN ];
375400GTxState gtx_state ;
401+ #ifdef PGPRO_EE
402+ int atxLevel = getNestLevelATX ();
403+ #endif
376404
377405if (MtmNo3PC )
378406{
@@ -714,7 +742,7 @@ MtmTwoPhaseCommit(void)
714742}
715743PG_CATCH ();
716744{
717- mtm_commit_cleanup (0 ,Int32GetDatum (0 ));
745+ mtm_commit_cleanup (0 ,Int32GetDatum (atxLevel ));
718746
719747PG_RE_THROW ();
720748}