Skip to content

Commit 576bb0f

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 9c4c22f commit 576bb0f

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
@@ -3713,6 +3713,7 @@ RelationCopyStorageUsingBuffer(RelFileNode srcnode,
37133713
bool use_wal;
37143714
BlockNumber nblocks;
37153715
BlockNumber blkno;
3716+
PGAlignedBlock buf;
37163717
BufferAccessStrategy bstrategy_src;
37173718
BufferAccessStrategy bstrategy_dst;
37183719

@@ -3731,6 +3732,14 @@ RelationCopyStorageUsingBuffer(RelFileNode srcnode,
37313732
if (nblocks == 0)
37323733
return;
37333734

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

37503759
/* Use P_NEW to extend the destination relation. */
3751-
dstBuf = ReadBufferWithoutRelcache(dstnode, forkNum, P_NEW,
3760+
dstBuf = ReadBufferWithoutRelcache(dstnode, forkNum, blkno,
37523761
RBM_NORMAL, bstrategy_dst,
37533762
permanent);
37543763
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