aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-04-08 13:19:49 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-04-08 13:19:49 -0300
commit5df64f298d2863c9fb39437abb3ae6f988aedc0a (patch)
treedb5d59b85707b8d4b04b43f0a7ed934b0a1824ca
parente4f1e0d842fa8e52d5972b19677ede5c36f44e98 (diff)
downloadpostgresql-5df64f298d2863c9fb39437abb3ae6f988aedc0a.tar.gz
postgresql-5df64f298d2863c9fb39437abb3ae6f988aedc0a.zip
Fix autovacuum launcher shutdown sequence
It was previously possible to have the launcher re-execute its main loop before shutting down if some other signal was received or an error occurred after getting SIGTERM, as reported by Qingqing Zhou. While investigating, Tom Lane further noticed that if autovacuum had been disabled in the config file, it would misbehave by trying to start a new worker instead of bailing out immediately -- it would consider itself as invoked in emergency mode. Fix both problems by checking the shutdown flag in a few more places. These problems have existed since autovacuum was introduced, so backpatch all the way back.
-rw-r--r--src/backend/postmaster/autovacuum.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index db46134979e..be4cd1d9f17 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -507,6 +507,10 @@ AutoVacLauncherMain(int argc, char *argv[])
/* Now we can allow interrupts again */
RESUME_INTERRUPTS();
+ /* if in shutdown mode, no need for anything further; just go away */
+ if (got_SIGTERM)
+ goto shutdown;
+
/*
* Sleep at least 1 second after any error. We don't want to be
* filling the error logs as fast as we can.
@@ -542,10 +546,14 @@ AutoVacLauncherMain(int argc, char *argv[])
SetConfigOption("default_transaction_isolation", "read committed",
PGC_SUSET, PGC_S_OVERRIDE);
- /* in emergency mode, just start a worker and go away */
+ /*
+ * In emergency mode, just start a worker (unless shutdown was requested)
+ * and go away.
+ */
if (!AutoVacuumingActive())
{
- do_start_worker();
+ if (!got_SIGTERM)
+ do_start_worker();
proc_exit(0); /* done */
}
@@ -560,7 +568,8 @@ AutoVacLauncherMain(int argc, char *argv[])
*/
rebuild_database_list(InvalidOid);
- for (;;)
+ /* loop until shutdown request */
+ while (!got_SIGTERM)
{
struct timeval nap;
TimestampTz current_time = 0;
@@ -758,6 +767,7 @@ AutoVacLauncherMain(int argc, char *argv[])
}
/* Normal exit from the autovac launcher is here */
+shutdown:
ereport(LOG,
(errmsg("autovacuum launcher shutting down")));
AutoVacuumShmem->av_launcherpid = 0;