Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Avoid holding vmbuffer pin after VACUUM.
authorSimon Riggs <simon@2ndQuadrant.com>
Mon, 3 Dec 2012 18:55:42 +0000 (18:55 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Mon, 3 Dec 2012 18:55:42 +0000 (18:55 +0000)
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

src/backend/commands/vacuumlazy.c

index 0e559720dce2a8401fbb6a756bcd61b47e909f74..0bba48582f95ad0664d1982225bd0e07aaae4644 100644 (file)
@@ -831,6 +831,15 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
                                                  vacrelstats->scanned_pages,
                                                         num_tuples);
 
+   /*
+    * Release any remaining pin on visibility map page.
+    */
+   if (BufferIsValid(vmbuffer))
+   {
+       ReleaseBuffer(vmbuffer);
+       vmbuffer = InvalidBuffer;
+   }
+
    /* If any tuples need to be deleted, perform final vacuum cycle */
    /* XXX put a threshold on min number of tuples here? */
    if (vacrelstats->num_dead_tuples > 0)
@@ -848,13 +857,6 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
        vacrelstats->num_index_scans++;
    }
 
-   /* Release the pin on the visibility map page */
-   if (BufferIsValid(vmbuffer))
-   {
-       ReleaseBuffer(vmbuffer);
-       vmbuffer = InvalidBuffer;
-   }
-
    /* Do post-vacuum cleanup and statistics update for each index */
    for (i = 0; i < nindexes; i++)
        lazy_cleanup_index(Irel[i], indstats[i], vacrelstats);