*** src/backend/postmaster/autovacuum.c	12 Nov 2008 10:10:43 -0000	1.71.2.7
--- src/backend/postmaster/autovacuum.c	8 Jun 2009 19:28:12 -0000
***************
*** 991,998 ****
  		/* sort the array */
  		qsort(dbary, nelems, sizeof(avl_dbase), db_comparator);
  
! 		/* this is the time interval between databases in the schedule */
  		millis_increment = 1000.0 * autovacuum_naptime / nelems;
  		current_time = GetCurrentTimestamp();
  
  		/*
--- 991,1013 ----
  		/* sort the array */
  		qsort(dbary, nelems, sizeof(avl_dbase), db_comparator);
  
! 		/*
! 		 * Determine the time interval between databases in the schedule.
! 		 * Here we can determine an minimum for the naptime; if we see that
! 		 * the configured naptime would take us to sleep times lower than 100ms
! 		 * (which launcher_determine_sleep is hardcoded not to allow), set
! 		 * the naptime to the required naptime plus some headroom.
! 		 */
  		millis_increment = 1000.0 * autovacuum_naptime / nelems;
+ 		if (millis_increment < 100.0)
+ 		{
+ 			autovacuum_naptime = nelems * 0.11;
+ 			millis_increment = 1000.0 * autovacuum_naptime / nelems;
+ 			ereport(WARNING,
+ 					(errmsg("autovacuum_naptime has been raised to %d due to high number of databases",
+ 							autovacuum_naptime)));
+ 		}
+ 
  		current_time = GetCurrentTimestamp();
  
  		/*
