Skip to content

Commit d68df5e

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 d278ff3 commit d68df5e

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
@@ -120,6 +120,7 @@ int Log_autovacuum_min_duration = -1;
120120

121121
/* the minimum allowed time between two awakenings of the launcher */
122122
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
123+
#define MAX_AUTOVAC_SLEEPTIME 300 /* seconds */
123124

124125
/* Flags to tell if we are in an autovacuum process */
125126
static bool am_autovacuum_launcher = false;
@@ -842,6 +843,15 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap)
842843
nap->tv_sec = 0;
843844
nap->tv_usec = MIN_AUTOVAC_SLEEPTIME * 1000;
844845
}
846+
847+
/*
848+
* If the sleep time is too large, clamp it to an arbitrary maximum (plus
849+
* any fractional seconds, for simplicity). This avoids an essentially
850+
* infinite sleep in strange cases like the system clock going backwards a
851+
* few years.
852+
*/
853+
if (nap->tv_sec > MAX_AUTOVAC_SLEEPTIME)
854+
nap->tv_sec = MAX_AUTOVAC_SLEEPTIME;
845855
}
846856

847857
/*

0 commit comments

Comments
 (0)