Content-Length: 280645 | pFad | http://github.com/postgrespro/postgres/commit/5df319f3d55d09fadb4f7e4b58c5b476a3aeceb4

EC Fix memory leak and inefficiency in CREATE DATABASE ... STRATEGY WAL_LOG · postgrespro/postgres@5df319f · GitHub
Skip to content

Commit 5df319f

Browse files
committed
Fix memory leak and inefficiency in CREATE DATABASE ... STRATEGY WAL_LOG
RelationCopyStorageUsingBuffer() did not free the strategies used to access the source / target relation. They memory was released at the end of the transaction, but when using a template database with a lot of relations, the temporary leak can become big prohibitively big. RelationCopyStorageUsingBuffer() acquired the buffer for the target relation with RBM_NORMAL, therefore requiring a read of a block guaranteed to be zero. Use RBM_ZERO_AND_LOCK instead. Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/20230321070113.o2vqqxogjykwgfrr@awork3.anarazel.de Backpatch: 15-, where STRATEGY WAL_LOG was introduced
1 parent bbc1376 commit 5df319f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,11 +3833,9 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
38333833
LockBuffer(srcBuf, BUFFER_LOCK_SHARE);
38343834
srcPage = BufferGetPage(srcBuf);
38353835

3836-
/* Use P_NEW to extend the destination relation. */
38373836
dstBuf = ReadBufferWithoutRelcache(dstlocator, forkNum, blkno,
3838-
RBM_NORMAL, bstrategy_dst,
3837+
RBM_ZERO_AND_LOCK, bstrategy_dst,
38393838
permanent);
3840-
LockBuffer(dstBuf, BUFFER_LOCK_EXCLUSIVE);
38413839
dstPage = BufferGetPage(dstBuf);
38423840

38433841
START_CRIT_SECTION();
@@ -3855,6 +3853,9 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
38553853
UnlockReleaseBuffer(dstBuf);
38563854
UnlockReleaseBuffer(srcBuf);
38573855
}
3856+
3857+
FreeAccessStrategy(bstrategy_src);
3858+
FreeAccessStrategy(bstrategy_dst);
38583859
}
38593860

38603861
/* ---------------------------------------------------------------------

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/5df319f3d55d09fadb4f7e4b58c5b476a3aeceb4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy