Skip to content

Commit 7ffe657

Browse files
committed
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.
1 parent b25433d commit 7ffe657

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/backend/commands/vacuumlazy.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.115 2009/01/01 17:23:40 momjian Exp $
32+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.116 2009/01/06 14:55:37 heikki Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -183,8 +183,9 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
183183
* number of pages. Otherwise, the time taken isn't worth it.
184184
*/
185185
possibly_freeable = vacrelstats->rel_pages - vacrelstats->nonempty_pages;
186-
if (possibly_freeable >= REL_TRUNCATE_MINIMUM ||
187-
possibly_freeable >= vacrelstats->rel_pages / REL_TRUNCATE_FRACTION)
186+
if (possibly_freeable > 0 &&
187+
(possibly_freeable >= REL_TRUNCATE_MINIMUM ||
188+
possibly_freeable >= vacrelstats->rel_pages / REL_TRUNCATE_FRACTION))
188189
lazy_truncate_heap(onerel, vacrelstats);
189190

190191
/* Vacuum the Free Space Map */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy