Skip to content

Commit e8f28cb

Browse files
committed
Dynamically set a lower bound on autovacuum nap time so that we don't rebuild
the database list too often. Per bug report from Łukasz Jagiełło and ensuing discussion on pgsql-performance.
1 parent e5de601 commit e8f28cb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.95 2009/05/15 15:56:39 tgl Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.96 2009/06/09 16:41:02 alvherre Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -123,6 +123,8 @@ int Log_autovacuum_min_duration = -1;
123123
/* how long to keep pgstat data in the launcher, in milliseconds */
124124
#define STATS_READ_DELAY 1000
125125

126+
/* the minimum allowed time between two awakening of the launcher */
127+
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
126128

127129
/* Flags to tell if we are in an autovacuum process */
128130
static bool am_autovacuum_launcher = false;
@@ -822,11 +824,11 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap)
822824
return;
823825
}
824826

825-
/* 100ms is the smallest time we'll allow the launcher to sleep */
826-
if (nap->tv_sec <= 0 && nap->tv_usec <= 100000)
827+
/* The smallest time we'll allow the launcher to sleep. */
828+
if (nap->tv_sec <= 0 && nap->tv_usec <= MIN_AUTOVAC_SLEEPTIME * 1000)
827829
{
828830
nap->tv_sec = 0;
829-
nap->tv_usec = 100000; /* 100 ms */
831+
nap->tv_usec = MIN_AUTOVAC_SLEEPTIME * 1000;
830832
}
831833
}
832834

@@ -997,8 +999,17 @@ rebuild_database_list(Oid newdb)
997999
/* sort the array */
9981000
qsort(dbary, nelems, sizeof(avl_dbase), db_comparator);
9991001

1000-
/* this is the time interval between databases in the schedule */
1002+
/*
1003+
* Determine the time interval between databases in the schedule.
1004+
* If we see that the configured naptime would take us to sleep times
1005+
* lower than our min sleep time (which launcher_determine_sleep is
1006+
* coded not to allow), silently use a larger naptime (but don't touch
1007+
* the GUC variable).
1008+
*/
10011009
millis_increment = 1000.0 * autovacuum_naptime / nelems;
1010+
if (millis_increment <= MIN_AUTOVAC_SLEEPTIME)
1011+
millis_increment = MIN_AUTOVAC_SLEEPTIME * 1.1;
1012+
10021013
current_time = GetCurrentTimestamp();
10031014

10041015
/*

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