summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2009-01-06 14:55:37 +0000
committerHeikki Linnakangas2009-01-06 14:55:37 +0000
commit39c4f9ac22db51ead2be750924967467bdfa49d6 (patch)
treef3ab04442a90fe6b862d24d8cc54c5a92c82d2f5
parent1b826c270f2710b0da968a9a33d30fb5907565a6 (diff)
Fix logic in lazy vacuum to decide if it's worth trying to truncate the heap.
If the table was smaller than REL_TRUNCATE_FRACTION (= 16) pages, we always tried to acquire AccessExclusiveLock on it even if there was no empty pages at the end. Report by Simon Riggs. Back-patch all the way to 7.4.
-rw-r--r--src/backend/commands/vacuumlazy.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index c1ee1c0d13..28ac57e419 100644
--- a/src/backend/commands/vacuumlazy.c
+++ b/src/backend/commands/vacuumlazy.c
@@ -183,8 +183,9 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
* number of pages. Otherwise, the time taken isn't worth it.
*/
possibly_freeable = vacrelstats->rel_pages - vacrelstats->nonempty_pages;
- if (possibly_freeable >= REL_TRUNCATE_MINIMUM ||
- possibly_freeable >= vacrelstats->rel_pages / REL_TRUNCATE_FRACTION)
+ if (possibly_freeable > 0 &&
+ (possibly_freeable >= REL_TRUNCATE_MINIMUM ||
+ possibly_freeable >= vacrelstats->rel_pages / REL_TRUNCATE_FRACTION))
lazy_truncate_heap(onerel, vacrelstats);
/* Vacuum the Free Space Map */