diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-11-13 19:47:44 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-11-13 20:02:37 +0200 |
commit | 81c45081960f39351c38cd53554bb3788af54023 (patch) | |
tree | ebb3af10b826276e1a74ef38a4487aea0a0ef78e /src/backend/access/heap/heapam.c | |
parent | 35fed51626328a3ff54adae4749bef956e1e1099 (diff) | |
download | postgresql-81c45081960f39351c38cd53554bb3788af54023.tar.gz postgresql-81c45081960f39351c38cd53554bb3788af54023.zip |
Fix race condition between hot standby and restoring a full-page image.
There was a window in RestoreBackupBlock where a page would be zeroed out,
but not yet locked. If a backend pinned and locked the page in that window,
it saw the zeroed page instead of the old page or new page contents, which
could lead to missing rows in a result set, or errors.
To fix, replace RBM_ZERO with RBM_ZERO_AND_LOCK, which atomically pins,
zeroes, and locks the page, if it's not in the buffer cache already.
In stable branches, the old RBM_ZERO constant is renamed to RBM_DO_NOT_USE,
to avoid breaking any 3rd party extensions that might use RBM_ZERO. More
importantly, this avoids renumbering the other enum values, which would
cause even bigger confusion in extensions that use ReadBufferExtended, but
haven't been recompiled.
Backpatch to all supported versions; this has been racy since hot standby
was introduced.
Diffstat (limited to 'src/backend/access/heap/heapam.c')
-rw-r--r-- | src/backend/access/heap/heapam.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 43098f44422..1763b70631d 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -7556,7 +7556,7 @@ heap_xlog_insert(XLogRecPtr lsn, XLogRecord *record) { XLogReadBufferForRedoExtended(lsn, record, 0, target_node, MAIN_FORKNUM, blkno, - RBM_ZERO, false, &buffer); + RBM_ZERO_AND_LOCK, false, &buffer); page = BufferGetPage(buffer); PageInit(page, BufferGetPageSize(buffer), 0); action = BLK_NEEDS_REDO; @@ -7683,7 +7683,7 @@ heap_xlog_multi_insert(XLogRecPtr lsn, XLogRecord *record) { XLogReadBufferForRedoExtended(lsn, record, 0, rnode, MAIN_FORKNUM, blkno, - RBM_ZERO, false, &buffer); + RBM_ZERO_AND_LOCK, false, &buffer); page = BufferGetPage(buffer); PageInit(page, BufferGetPageSize(buffer), 0); action = BLK_NEEDS_REDO; @@ -7876,7 +7876,7 @@ heap_xlog_update(XLogRecPtr lsn, XLogRecord *record, bool hot_update) { XLogReadBufferForRedoExtended(lsn, record, 1, rnode, MAIN_FORKNUM, newblk, - RBM_ZERO, false, &nbuffer); + RBM_ZERO_AND_LOCK, false, &nbuffer); page = (Page) BufferGetPage(nbuffer); PageInit(page, BufferGetPageSize(nbuffer), 0); newaction = BLK_NEEDS_REDO; |