unlink-after-lockrel-v1.patch

text/plain

Filename: unlink-after-lockrel-v1.patch
Type: text/plain
Part: 0
Message: unlink for DROPs after releasing locks (was Re: Should I implement DROP INDEX CONCURRENTLY?)

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
Series: patch v1
File+
src/backend/access/transam/xact.c 0 0
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);