diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index a3c240f..4fe6b7f 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -2805,7 +2805,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) /* * Disable the current subscription, after error recovery processing. */ -static void +static bool DisableSubscriptionOnError(void) { Relation rel; @@ -2815,14 +2815,8 @@ DisableSubscriptionOnError(void) HeapTuple tup; Form_pg_subscription subform; - /* Emit the error */ - EmitErrorReport(); - /* Abort any active transaction */ - AbortOutOfAnyTransaction(); - /* Reset the ErrorContext */ - FlushErrorState(); - /* Disable the subscription in a fresh transaction */ + AbortOutOfAnyTransaction(); StartTransactionCommand(); /* Look up our subscription in the catalogs */ @@ -2847,9 +2841,12 @@ DisableSubscriptionOnError(void) heap_freetuple(tup); table_close(rel, RowExclusiveLock); CommitTransactionCommand(); - return; + return false; } + EmitErrorReport(); + FlushErrorState(); + /* Notify the subscription will be no longer valid */ ereport(LOG, errmsg("logical replication subscription \"%s\" will be disabled due to an error", @@ -2875,6 +2872,8 @@ DisableSubscriptionOnError(void) table_close(rel, RowExclusiveLock); CommitTransactionCommand(); + + return true; } /* @@ -3481,9 +3480,8 @@ SyncTableStartWrapper(XLogRecPtr *origin_startpos, InvalidTransactionId, errdata->message); - if (MySubscription->disableonerr) + if (MySubscription->disableonerr && DisableSubscriptionOnError()) { - DisableSubscriptionOnError(); proc_exit(0); } @@ -3527,10 +3525,8 @@ ApplyLoopWrapper(XLogRecPtr origin_startpos, MemoryContext cctx) errdata->message); } - if (MySubscription->disableonerr) + if (MySubscription->disableonerr && DisableSubscriptionOnError()) { - /* Disable the subscription */ - DisableSubscriptionOnError(); return; }