Skip to content

Commit 45f9b46

Browse files
committed
Avoid calling kill() in a postmaster signal handler.
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.
1 parent 9b708f1 commit 45f9b46

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.101 2009/08/12 20:53:30 tgl Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.102 2009/08/24 17:23:02 alvherre Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -653,7 +653,7 @@ AutoVacLauncherMain(int argc, char *argv[])
653653
* of a worker will continue to fail in the same way.
654654
*/
655655
AutoVacuumShmem->av_signal[AutoVacForkFailed] = false;
656-
pg_usleep(100000L); /* 100ms */
656+
pg_usleep(1000000L); /* 1s */
657657
SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER);
658658
continue;
659659
}

src/backend/postmaster/postmaster.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.587 2009/08/07 05:58:55 heikki Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.588 2009/08/24 17:23:02 alvherre Exp $
4141
*
4242
* NOTES
4343
*
@@ -290,6 +290,8 @@ bool redirection_done = false; /* stderr redirected for syslogger? */
290290

291291
/* received START_AUTOVAC_LAUNCHER signal */
292292
static volatile sig_atomic_t start_autovac_launcher = false;
293+
/* the launcher needs to be signalled to communicate some condition */
294+
static volatile bool avlauncher_needs_signal = false;
293295

294296
/*
295297
* State for assigning random salts and cancel keys.
@@ -1391,6 +1393,14 @@ ServerLoop(void)
13911393
if (PgStatPID == 0 && pmState == PM_RUN)
13921394
PgStatPID = pgstat_start();
13931395

1396+
/* If we need to signal the autovacuum launcher, do so now */
1397+
if (avlauncher_needs_signal)
1398+
{
1399+
avlauncher_needs_signal = false;
1400+
if (AutoVacPID != 0)
1401+
kill(AutoVacPID, SIGUSR1);
1402+
}
1403+
13941404
/*
13951405
* Touch the socket and lock file every 58 minutes, to ensure that
13961406
* they are not removed by overzealous /tmp-cleaning tasks. We assume
@@ -3014,6 +3024,7 @@ BackendStartup(Port *port)
30143024
/* in parent, fork failed */
30153025
int save_errno = errno;
30163026

3027+
(void) ReleasePostmasterChildSlot(bn->child_slot);
30173028
free(bn);
30183029
errno = save_errno;
30193030
ereport(LOG,
@@ -4343,6 +4354,7 @@ StartAutovacuumWorker(void)
43434354
* fork failed, fall through to report -- actual error message was
43444355
* logged by StartAutoVacWorker
43454356
*/
4357+
(void) ReleasePostmasterChildSlot(bn->child_slot);
43464358
free(bn);
43474359
}
43484360
else
@@ -4354,12 +4366,16 @@ StartAutovacuumWorker(void)
43544366
/*
43554367
* Report the failure to the launcher, if it's running. (If it's not, we
43564368
* might not even be connected to shared memory, so don't try to call
4357-
* AutoVacWorkerFailed.)
4369+
* AutoVacWorkerFailed.) Note that we also need to signal it so that it
4370+
* responds to the condition, but we don't do that here, instead waiting
4371+
* for ServerLoop to do it. This way we avoid a ping-pong signalling in
4372+
* quick succession between the autovac launcher and postmaster in case
4373+
* things get ugly.
43584374
*/
43594375
if (AutoVacPID != 0)
43604376
{
43614377
AutoVacWorkerFailed();
4362-
kill(AutoVacPID, SIGUSR1);
4378+
avlauncher_needs_signal = true;
43634379
}
43644380
}
43654381

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy