Skip to content

Commit cf73376

Browse files
committed
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.
1 parent 8507a5b commit cf73376

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ int Log_autovacuum_min_duration = -1;
129129

130130
/* the minimum allowed time between two awakenings of the launcher */
131131
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
132+
#define MAX_AUTOVAC_SLEEPTIME 300 /* seconds */
132133

133134
/* Flags to tell if we are in an autovacuum process */
134135
static bool am_autovacuum_launcher = false;
@@ -872,6 +873,15 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap)
872873
nap->tv_sec = 0;
873874
nap->tv_usec = MIN_AUTOVAC_SLEEPTIME * 1000;
874875
}
876+
877+
/*
878+
* If the sleep time is too large, clamp it to an arbitrary maximum (plus
879+
* any fractional seconds, for simplicity). This avoids an essentially
880+
* infinite sleep in strange cases like the system clock going backwards a
881+
* few years.
882+
*/
883+
if (nap->tv_sec > MAX_AUTOVAC_SLEEPTIME)
884+
nap->tv_sec = MAX_AUTOVAC_SLEEPTIME;
875885
}
876886

877887
/*

0 commit comments

Comments
 (0)