mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Set the all-visible flag on heap page before writing WAL record, not after.
If we set the all-visible flag after writing WAL record, and XLogInsert takes a full-page image of the page, the image would not include the flag. We will then proceed to set the VM bit, which would then be set without the corresponding all-visible flag on the heap page. Found by comparing page images on master and standby, after writing/replaying each WAL record. (There is still a discrepancy: the all-visible flag won't be set after replaying the HEAP_CLEAN record, even though it is set in the master. However, it will be set when replaying the HEAP2_VISIBLE record and setting the VM bit, so the all-visible flag and VM bit are always consistent on the standby, even though they are momentarily out-of-sync with master) Backpatch to 9.3 where this code was introduced.
This commit is contained in:
parent
5f86cbd714
commit
2a8e1ac598
@ -1213,6 +1213,13 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
|
|||||||
|
|
||||||
PageRepairFragmentation(page);
|
PageRepairFragmentation(page);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now that we have removed the dead tuples from the page, once again
|
||||||
|
* check if the page has become all-visible.
|
||||||
|
*/
|
||||||
|
if (heap_page_is_all_visible(onerel, buffer, &visibility_cutoff_xid))
|
||||||
|
PageSetAllVisible(page);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mark buffer dirty before we write WAL.
|
* Mark buffer dirty before we write WAL.
|
||||||
*/
|
*/
|
||||||
@ -1231,14 +1238,13 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now that we have removed the dead tuples from the page, once again
|
* All the changes to the heap page have been done. If the all-visible
|
||||||
* check if the page has become all-visible.
|
* flag is now set, also set the VM bit.
|
||||||
*/
|
*/
|
||||||
if (!visibilitymap_test(onerel, blkno, vmbuffer) &&
|
if (PageIsAllVisible(page) &&
|
||||||
heap_page_is_all_visible(onerel, buffer, &visibility_cutoff_xid))
|
!visibilitymap_test(onerel, blkno, vmbuffer))
|
||||||
{
|
{
|
||||||
Assert(BufferIsValid(*vmbuffer));
|
Assert(BufferIsValid(*vmbuffer));
|
||||||
PageSetAllVisible(page);
|
|
||||||
visibilitymap_set(onerel, blkno, buffer, InvalidXLogRecPtr, *vmbuffer,
|
visibilitymap_set(onerel, blkno, buffer, InvalidXLogRecPtr, *vmbuffer,
|
||||||
visibility_cutoff_xid);
|
visibility_cutoff_xid);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user