Skip to content

Commit a4f0551

Browse files
melanieplagemanCommitfest Bot
authored andcommitted
Eliminate XLOG_HEAP2_VISIBLE from empty-page vacuum
As part of removing XLOG_HEAP2_VISIBLE records, phase I of VACUUM now marks empty pages all-visible in a XLOG_HEAP2_PRUNE_VACUUM_SCAN record. Author: Melanie Plageman <[email protected]> Reviewed-by: Robert Haas <[email protected]>
1 parent 9ca3100 commit a4f0551

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,9 +1878,12 @@ lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno,
18781878
*/
18791879
if (!PageIsAllVisible(page))
18801880
{
1881+
/* Lock vmbuffer before entering critical section */
1882+
LockBuffer(vmbuffer, BUFFER_LOCK_EXCLUSIVE);
1883+
18811884
START_CRIT_SECTION();
18821885

1883-
/* mark buffer dirty before writing a WAL record */
1886+
/* Mark buffer dirty before writing any WAL records */
18841887
MarkBufferDirty(buf);
18851888

18861889
/*
@@ -1897,13 +1900,34 @@ lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno,
18971900
log_newpage_buffer(buf, true);
18981901

18991902
PageSetAllVisible(page);
1900-
visibilitymap_set(vacrel->rel, blkno, buf,
1901-
InvalidXLogRecPtr,
1902-
vmbuffer, InvalidTransactionId,
1903-
VISIBILITYMAP_ALL_VISIBLE |
1904-
VISIBILITYMAP_ALL_FROZEN);
1903+
visibilitymap_set_vmbits(blkno,
1904+
vmbuffer,
1905+
VISIBILITYMAP_ALL_VISIBLE |
1906+
VISIBILITYMAP_ALL_FROZEN,
1907+
vacrel->rel->rd_locator);
1908+
1909+
/*
1910+
* Emit WAL for setting PD_ALL_VISIBLE on the heap page and
1911+
* setting the VM.
1912+
*/
1913+
if (RelationNeedsWAL(vacrel->rel))
1914+
log_heap_prune_and_freeze(vacrel->rel, buf,
1915+
vmbuffer,
1916+
VISIBILITYMAP_ALL_VISIBLE |
1917+
VISIBILITYMAP_ALL_FROZEN,
1918+
InvalidTransactionId, /* conflict xid */
1919+
false, /* cleanup lock */
1920+
true, /* set_pd_all_vis */
1921+
PRUNE_VACUUM_SCAN, /* reason */
1922+
NULL, 0,
1923+
NULL, 0,
1924+
NULL, 0,
1925+
NULL, 0);
1926+
19051927
END_CRIT_SECTION();
19061928

1929+
LockBuffer(vmbuffer, BUFFER_LOCK_UNLOCK);
1930+
19071931
/* Count the newly all-frozen pages for logging */
19081932
vacrel->vm_new_visible_pages++;
19091933
vacrel->vm_new_visible_frozen_pages++;

0 commit comments

Comments
 (0)