Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit811203d

Browse files
committed
Fix data-corruption hazard in WAL-logged CREATE DATABASE.
RelationCopyStorageUsingBuffer thought it could skip copyingempty pages, but of course that does not work at all, becausesubsequent blocks will be out of place.Also fix it to acquire share lock on the source buffer. It *might*be safe to not do that, but it's not very certain, and I don't thinkthis code deserves any benefit of the doubt.Dilip Kumar, per complaint from meDiscussion:https://postgr.es/m/3679800.1659654066@sss.pgh.pa.us
1 parent6390bc7 commit811203d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,23 +3742,19 @@ RelationCopyStorageUsingBuffer(Relation src, Relation dst, ForkNumber forkNum,
37423742
srcBuf=ReadBufferWithoutRelcache(src->rd_node,forkNum,blkno,
37433743
RBM_NORMAL,bstrategy_src,
37443744
permanent);
3745+
LockBuffer(srcBuf,BUFFER_LOCK_SHARE);
37453746
srcPage=BufferGetPage(srcBuf);
3746-
if (PageIsNew(srcPage)||PageIsEmpty(srcPage))
3747-
{
3748-
ReleaseBuffer(srcBuf);
3749-
continue;
3750-
}
37513747

37523748
/* Use P_NEW to extend the destination relation. */
37533749
dstBuf=ReadBufferWithoutRelcache(dst->rd_node,forkNum,P_NEW,
37543750
RBM_NORMAL,bstrategy_dst,
37553751
permanent);
37563752
LockBuffer(dstBuf,BUFFER_LOCK_EXCLUSIVE);
3753+
dstPage=BufferGetPage(dstBuf);
37573754

37583755
START_CRIT_SECTION();
37593756

37603757
/* Copy page data from the source to the destination. */
3761-
dstPage=BufferGetPage(dstBuf);
37623758
memcpy(dstPage,srcPage,BLCKSZ);
37633759
MarkBufferDirty(dstBuf);
37643760

@@ -3769,7 +3765,7 @@ RelationCopyStorageUsingBuffer(Relation src, Relation dst, ForkNumber forkNum,
37693765
END_CRIT_SECTION();
37703766

37713767
UnlockReleaseBuffer(dstBuf);
3772-
ReleaseBuffer(srcBuf);
3768+
UnlockReleaseBuffer(srcBuf);
37733769
}
37743770
}
37753771

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp