]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Avoid calling kill() in a postmaster signal handler.
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 24 Aug 2009 17:23:28 +0000 (17:23 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 24 Aug 2009 17:23:28 +0000 (17:23 +0000)
This causes problems when the system load is high, per report from Zdenek
Kotala in <1250860954.1239.114.camel@localhost>; instead of calling kill
directly, have the signal handler set a flag which is checked in ServerLoop.
This way, the handler can return before being called again by a subsequent
signal sent from the autovacuum launcher.  Also, increase the sleep in the
launcher in this failure path to 1 second.

Backpatch to 8.3, which is when the signalling between autovacuum
launcher/postmaster was introduced.

Also, add a couple of ReleasePostmasterChildSlot calls in error paths; this
part backpatched to 8.4 which is when the child slot stuff was introduced.

src/backend/postmaster/autovacuum.c
src/backend/postmaster/postmaster.c

index eea76fb6a2d7f67e8a64771a8d1c3cd7b9f0947f..8c4b3dcc9f3539d476c7fa3f8074918ad09ed46d 100644 (file)
@@ -55,7 +55,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.71.2.9 2009/06/09 19:36:42 alvherre Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.71.2.10 2009/08/24 17:23:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -646,7 +646,7 @@ AutoVacLauncherMain(int argc, char *argv[])
                                 * of a worker will continue to fail in the same way.
                                 */
                                AutoVacuumShmem->av_signal[AutoVacForkFailed] = false;
-                               pg_usleep(100000L);             /* 100ms */
+                               pg_usleep(1000000L);            /* 1s */
                                SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER);
                                continue;
                        }
index 8c6fb05a257a88631e5ca07dc3474affb325df0e..ebac2299fed89844ddcb590d35f4af8f20295f95 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.551.2.3 2009/08/11 11:51:20 mha Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.551.2.4 2009/08/24 17:23:28 alvherre Exp $
  *
  * NOTES
  *
@@ -269,6 +269,8 @@ bool                redirection_done = false;       /* stderr redirected for syslogger? */
 
 /* received START_AUTOVAC_LAUNCHER signal */
 static volatile sig_atomic_t start_autovac_launcher = false;
+/* the launcher needs to be signalled to communicate some condition */
+static volatile bool           avlauncher_needs_signal = false;
 
 /*
  * State for assigning random salts and cancel keys.
@@ -1321,6 +1323,14 @@ ServerLoop(void)
                if (PgStatPID == 0 && pmState == PM_RUN)
                        PgStatPID = pgstat_start();
 
+               /* If we need to signal the autovacuum launcher, do so now */
+               if (avlauncher_needs_signal)
+               {
+                       avlauncher_needs_signal = false;
+                       if (AutoVacPID != 0)
+                               kill(AutoVacPID, SIGUSR1);
+               }
+
                /*
                 * Touch the socket and lock file every 58 minutes, to ensure that
                 * they are not removed by overzealous /tmp-cleaning tasks.  We assume
@@ -4155,12 +4165,16 @@ StartAutovacuumWorker(void)
        /*
         * Report the failure to the launcher, if it's running.  (If it's not, we
         * might not even be connected to shared memory, so don't try to call
-        * AutoVacWorkerFailed.)
+        * AutoVacWorkerFailed.)  Note that we also need to signal it so that it
+        * responds to the condition, but we don't do that here, instead waiting
+        * for ServerLoop to do it.  This way we avoid a ping-pong signalling in
+        * quick succession between the autovac launcher and postmaster in case
+        * things get ugly.
         */
        if (AutoVacPID != 0)
        {
                AutoVacWorkerFailed();
-               kill(AutoVacPID, SIGUSR1);
+               avlauncher_needs_signal = true;
        }
 }