aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer/bufmgr.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-03-22 09:26:23 -0700
committerAndres Freund <andres@anarazel.de>2023-03-22 09:26:23 -0700
commit560bb56c6eba5da7917e67783d46f0d5ca30e89a (patch)
tree1636c19449a402440e31ffb111a116395a5c44fd /src/backend/storage/buffer/bufmgr.c
parenta70e6e430628fe5ee802f47f4b043d33a0d41dda (diff)
downloadpostgresql-560bb56c6eba5da7917e67783d46f0d5ca30e89a.tar.gz
postgresql-560bb56c6eba5da7917e67783d46f0d5ca30e89a.zip
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
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r--src/backend/storage/buffer/bufmgr.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 8727a50d949..9fcb3d6e194 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -3756,11 +3756,9 @@ RelationCopyStorageUsingBuffer(RelFileNode srcnode,
LockBuffer(srcBuf, BUFFER_LOCK_SHARE);
srcPage = BufferGetPage(srcBuf);
- /* Use P_NEW to extend the destination relation. */
dstBuf = ReadBufferWithoutRelcache(dstnode, forkNum, blkno,
- RBM_NORMAL, bstrategy_dst,
+ RBM_ZERO_AND_LOCK, bstrategy_dst,
permanent);
- LockBuffer(dstBuf, BUFFER_LOCK_EXCLUSIVE);
dstPage = BufferGetPage(dstBuf);
START_CRIT_SECTION();
@@ -3778,6 +3776,9 @@ RelationCopyStorageUsingBuffer(RelFileNode srcnode,
UnlockReleaseBuffer(dstBuf);
UnlockReleaseBuffer(srcBuf);
}
+
+ FreeAccessStrategy(bstrategy_src);
+ FreeAccessStrategy(bstrategy_dst);
}
/* ---------------------------------------------------------------------