From 3aa37600aa383ba6769084fe7e21063ee633ee77 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Wed, 21 Feb 2007 22:15:21 +0000
Subject: [PATCH] Move increase FSM warning to after lazy_truncate_heap()
 because the function might reduce the number of free pages in the table. 
 Recommend VACUUM FULL only if 20% free.

Simon Riggs.
---
 src/backend/commands/vacuumlazy.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index 676d5687893..b892ea19ab3 100644
--- a/src/backend/commands/vacuumlazy.c
+++ b/src/backend/commands/vacuumlazy.c
@@ -36,7 +36,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.83 2007/02/04 03:10:55 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.84 2007/02/21 22:15:21 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -180,6 +180,16 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
 	/* Update shared free space map with final free space info */
 	lazy_update_fsm(onerel, vacrelstats);
 
+	if (vacrelstats->tot_free_pages > MaxFSMPages)
+		ereport(WARNING,
+				(errmsg("relation \"%s.%s\" contains more than \"max_fsm_pages\" pages with useful free space",
+						get_namespace_name(RelationGetNamespace(onerel)),
+						RelationGetRelationName(onerel)),
+				 errhint("Consider%sincreasing the configuration parameter \"max_fsm_pages\".",
+						/* Only suggest VACUUM FULL if 20% free */
+						(vacrelstats->tot_free_pages > vacrelstats->rel_pages * 0.20
+							? " using VACUUM FULL on this relation or ": " "))));
+
 	/* Update statistics in pg_class */
 	vac_update_relstats(RelationGetRelid(onerel),
 						vacrelstats->rel_pages,
@@ -507,13 +517,6 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
 					   vacrelstats->tot_free_pages,
 					   empty_pages,
 					   pg_rusage_show(&ru0))));
-
-	if (vacrelstats->tot_free_pages > MaxFSMPages)
-		ereport(WARNING,
-				(errmsg("relation \"%s.%s\" contains more than \"max_fsm_pages\" pages with useful free space",
-						get_namespace_name(RelationGetNamespace(onerel)),
-						relname),
-				 errhint("Consider using VACUUM FULL on this relation or increasing the configuration parameter \"max_fsm_pages\".")));
 }
 
 
-- 
GitLab