Skip to content

Commit 3e63e84

Browse files
committed
When using the WAL-logged CREATE DATABASE strategy, bulk extend.
This should improve performance, and was suggested by Andres Freund. Back-patch to v15 to keep the code consistent across branches. Dilip Kumar Discussion: http://postgr.es/m/C3458199-FEDD-4356-865A-08DFAA5D4065@anarazel.de Discussion: http://postgr.es/m/CAFiTN-sJ0vVpJrZ=R5M+g7Tr8=NN4wKOtrqOcDEsfFfnZgivVA@mail.gmail.com
1 parent 27f1774 commit 3e63e84

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3712,6 +3712,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
37123712
bool use_wal;
37133713
BlockNumber nblocks;
37143714
BlockNumber blkno;
3715+
PGAlignedBlock buf;
37153716
BufferAccessStrategy bstrategy_src;
37163717
BufferAccessStrategy bstrategy_dst;
37173718

@@ -3730,6 +3731,14 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
37303731
if (nblocks == 0)
37313732
return;
37323733

3734+
/*
3735+
* Bulk extend the destination relation of the same size as the source
3736+
* relation before starting to copy block by block.
3737+
*/
3738+
memset(buf.data, 0, BLCKSZ);
3739+
smgrextend(smgropen(dstlocator, InvalidBackendId), forkNum, nblocks - 1,
3740+
buf.data, true);
3741+
37333742
/* This is a bulk operation, so use buffer access strategies. */
37343743
bstrategy_src = GetAccessStrategy(BAS_BULKREAD);
37353744
bstrategy_dst = GetAccessStrategy(BAS_BULKWRITE);
@@ -3747,7 +3756,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
37473756
srcPage = BufferGetPage(srcBuf);
37483757

37493758
/* Use P_NEW to extend the destination relation. */
3750-
dstBuf = ReadBufferWithoutRelcache(dstlocator, forkNum, P_NEW,
3759+
dstBuf = ReadBufferWithoutRelcache(dstlocator, forkNum, blkno,
37513760
RBM_NORMAL, bstrategy_dst,
37523761
permanent);
37533762
LockBuffer(dstBuf, BUFFER_LOCK_EXCLUSIVE);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy