diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 8f00186..8e4a455 100644 *** a/src/backend/access/transam/xact.c --- b/src/backend/access/transam/xact.c *************** *** 1944,1957 **** CommitTransaction(void) */ AtEOXact_Inval(true); - /* - * Likewise, dropping of files deleted during the transaction is best done - * after releasing relcache and buffer pins. (This is not strictly - * necessary during commit, since such pins should have been released - * already, but this ordering is definitely critical during abort.) - */ - smgrDoPendingDeletes(true); - AtEOXact_MultiXact(); ResourceOwnerRelease(TopTransactionResourceOwner, --- 1944,1949 ---- *************** *** 1961,1966 **** CommitTransaction(void) --- 1953,1969 ---- RESOURCE_RELEASE_AFTER_LOCKS, true, true); + /* + * Likewise, dropping of files deleted during the transaction is best done + * after releasing relcache and buffer pins. (This is not strictly + * necessary during commit, since such pins should have been released + * already, but this ordering is definitely critical during abort.) Since + * this may take many seconds, also delay until after releasing locks. + * Other backends will observe the attendant catalog changes and not + * attempt to access affected files. + */ + smgrDoPendingDeletes(true); + /* Check we've released all catcache entries */ AtEOXact_CatCache(true); *************** *** 2354,2360 **** AbortTransaction(void) AtEOXact_Buffers(false); AtEOXact_RelationCache(false); AtEOXact_Inval(false); - smgrDoPendingDeletes(false); AtEOXact_MultiXact(); ResourceOwnerRelease(TopTransactionResourceOwner, RESOURCE_RELEASE_LOCKS, --- 2357,2362 ---- *************** *** 2362,2367 **** AbortTransaction(void) --- 2364,2370 ---- ResourceOwnerRelease(TopTransactionResourceOwner, RESOURCE_RELEASE_AFTER_LOCKS, false, true); + smgrDoPendingDeletes(false); AtEOXact_CatCache(false); AtEOXact_GUC(false, 1); *************** *** 4238,4250 **** AbortSubTransaction(void) AtEOSubXact_RelationCache(false, s->subTransactionId, s->parent->subTransactionId); AtEOSubXact_Inval(false); - AtSubAbort_smgr(); ResourceOwnerRelease(s->curTransactionOwner, RESOURCE_RELEASE_LOCKS, false, false); ResourceOwnerRelease(s->curTransactionOwner, RESOURCE_RELEASE_AFTER_LOCKS, false, false); AtEOXact_GUC(false, s->gucNestLevel); AtEOSubXact_SPI(false, s->subTransactionId); --- 4241,4253 ---- AtEOSubXact_RelationCache(false, s->subTransactionId, s->parent->subTransactionId); AtEOSubXact_Inval(false); ResourceOwnerRelease(s->curTransactionOwner, RESOURCE_RELEASE_LOCKS, false, false); ResourceOwnerRelease(s->curTransactionOwner, RESOURCE_RELEASE_AFTER_LOCKS, false, false); + AtSubAbort_smgr(); AtEOXact_GUC(false, s->gucNestLevel); AtEOSubXact_SPI(false, s->subTransactionId);