Skip to content

Commit 17ee02e

Browse files
Avoid holding vmbuffer pin after VACUUM.
During VACUUM if we pause to perform a cycle of index cleanup we drop the vmbuffer pin, so we should do the same thing when heap scan completes. This avoids holding vmbuffer pin across the main index cleanup in VACUUM, which could be minutes or hours longer than necessary for correctness. Bug report and suggested fix from Pavan Deolasee
1 parent 6a8b998 commit 17ee02e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/backend/commands/vacuumlazy.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,15 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
947947
vacrelstats->scanned_pages,
948948
num_tuples);
949949

950+
/*
951+
* Release any remaining pin on visibility map page.
952+
*/
953+
if (BufferIsValid(vmbuffer))
954+
{
955+
ReleaseBuffer(vmbuffer);
956+
vmbuffer = InvalidBuffer;
957+
}
958+
950959
/* If any tuples need to be deleted, perform final vacuum cycle */
951960
/* XXX put a threshold on min number of tuples here? */
952961
if (vacrelstats->num_dead_tuples > 0)
@@ -964,13 +973,6 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
964973
vacrelstats->num_index_scans++;
965974
}
966975

967-
/* Release the pin on the visibility map page */
968-
if (BufferIsValid(vmbuffer))
969-
{
970-
ReleaseBuffer(vmbuffer);
971-
vmbuffer = InvalidBuffer;
972-
}
973-
974976
/* Do post-vacuum cleanup and statistics update for each index */
975977
for (i = 0; i < nindexes; i++)
976978
lazy_cleanup_index(Irel[i], indstats[i], vacrelstats);

0 commit comments

Comments
 (0)