Skip to content

Commit c52e0e2

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 17164cc commit c52e0e2

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
@@ -831,6 +831,15 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
831831
vacrelstats->scanned_pages,
832832
num_tuples);
833833

834+
/*
835+
* Release any remaining pin on visibility map page.
836+
*/
837+
if (BufferIsValid(vmbuffer))
838+
{
839+
ReleaseBuffer(vmbuffer);
840+
vmbuffer = InvalidBuffer;
841+
}
842+
834843
/* If any tuples need to be deleted, perform final vacuum cycle */
835844
/* XXX put a threshold on min number of tuples here? */
836845
if (vacrelstats->num_dead_tuples > 0)
@@ -848,13 +857,6 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
848857
vacrelstats->num_index_scans++;
849858
}
850859

851-
/* Release the pin on the visibility map page */
852-
if (BufferIsValid(vmbuffer))
853-
{
854-
ReleaseBuffer(vmbuffer);
855-
vmbuffer = InvalidBuffer;
856-
}
857-
858860
/* Do post-vacuum cleanup and statistics update for each index */
859861
for (i = 0; i < nindexes; i++)
860862
lazy_cleanup_index(Irel[i], indstats[i], vacrelstats);

0 commit comments

Comments
 (0)