aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-06-19 12:44:35 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-06-19 12:44:35 -0300
commitcf733760eae1523022b652d4e673d336ef81b235 (patch)
tree7e47b93da27fc120cdecbc1c9e0ce04612fc01d4 /src
parent8507a5b37bd95717572c5fd1863758f478fe7b10 (diff)
downloadpostgresql-cf733760eae1523022b652d4e673d336ef81b235.tar.gz
postgresql-cf733760eae1523022b652d4e673d336ef81b235.zip
Clamp autovacuum launcher sleep time to 5 minutes
This avoids the problem that it might go to sleep for an unreasonable amount of time in unusual conditions like the server clock moving backwards an unreasonable amount of time. (Simply moving the server clock forward again doesn't solve the problem unless you wake up the autovacuum launcher manually, say by sending it SIGHUP). Per trouble report from Prakash Itnal in https://www.postgresql.org/message-id/CAHC5u79-UqbapAABH2t4Rh2eYdyge0Zid-X=Xz-ZWZCBK42S0Q@mail.gmail.com Analyzed independently by Haribabu Kommi and Tom Lane.
Diffstat (limited to 'src')
-rw-r--r--src/backend/postmaster/autovacuum.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 3a60d7e7f5a..90dff4b0162 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -129,6 +129,7 @@ int Log_autovacuum_min_duration = -1;
/* the minimum allowed time between two awakenings of the launcher */
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
+#define MAX_AUTOVAC_SLEEPTIME 300 /* seconds */
/* Flags to tell if we are in an autovacuum process */
static bool am_autovacuum_launcher = false;
@@ -872,6 +873,15 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap)
nap->tv_sec = 0;
nap->tv_usec = MIN_AUTOVAC_SLEEPTIME * 1000;
}
+
+ /*
+ * If the sleep time is too large, clamp it to an arbitrary maximum (plus
+ * any fractional seconds, for simplicity). This avoids an essentially
+ * infinite sleep in strange cases like the system clock going backwards a
+ * few years.
+ */
+ if (nap->tv_sec > MAX_AUTOVAC_SLEEPTIME)
+ nap->tv_sec = MAX_AUTOVAC_SLEEPTIME;
}
/*