Disallow the cost balancing code from resulting in a zero cost limit, which
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 8 Jun 2007 21:21:28 +0000 (21:21 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 8 Jun 2007 21:21:28 +0000 (21:21 +0000)
causes a division-by-zero error in the vacuum code.  This can happen when there
are more workers than cost limit units.

Per report from Galy Lee in
<200705310914.l4V9E6JA094603@wwwmaster.postgresql.org>.

src/backend/postmaster/autovacuum.c

index 07bf40707e398f8ec49fc717ea35e6217993118c..82a2bc71a0c6e7fb3b386c0cdbf0412c7a474668 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.48 2007/06/08 21:09:49 alvherre Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.49 2007/06/08 21:21:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1599,7 +1599,11 @@ autovac_balance_cost(void)
                        int     limit = (int)
                                (cost_avail * worker->wi_cost_limit_base / cost_total);
 
-                       worker->wi_cost_limit = Min(limit, worker->wi_cost_limit_base);
+                       /*
+                        * We put a lower bound of 1 to the cost_limit, to avoid division-
+                        * by-zero in the vacuum code.
+                        */
+                       worker->wi_cost_limit = Max(Min(limit, worker->wi_cost_limit_base), 1);
 
                        elog(DEBUG2, "autovac_balance_cost(pid=%u db=%u, rel=%u, cost_limit=%d, cost_delay=%d)",
                                 worker->wi_workerpid, worker->wi_dboid,