1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-25 12:03:53 +03:00

Use signals for postmaster death on Linux.

Linux provides a way to ask for a signal when your parent process dies.
Use that to make PostmasterIsAlive() very cheap.

Based on a suggestion from Andres Freund.

Author: Thomas Munro, Heikki Linnakangas
Reviewed-By: Michael Paquier
Discussion: https://postgr.es/m/7261eb39-0369-f2f4-1bb5-62f3b6083b5e%40iki.fi
Discussion: https://postgr.es/m/20180411002643.6buofht4ranhei7k%40alap3.anarazel.de
This commit is contained in:
Thomas Munro
2018-07-11 12:40:58 +12:00
parent 56a7147213
commit 9f09529952
8 changed files with 160 additions and 20 deletions

View File

@@ -14,6 +14,10 @@
#ifndef PMSIGNAL_H
#define PMSIGNAL_H
#ifdef HAVE_SYS_PRCTL_H
#include "sys/prctl.h"
#endif
/*
* Reasons for signaling the postmaster. We can cope with simultaneous
* signals for different reasons. If the same reason is signaled multiple
@@ -51,6 +55,33 @@ extern bool IsPostmasterChildWalSender(int slot);
extern void MarkPostmasterChildActive(void);
extern void MarkPostmasterChildInactive(void);
extern void MarkPostmasterChildWalSender(void);
extern bool PostmasterIsAlive(void);
extern bool PostmasterIsAliveInternal(void);
extern void PostmasterDeathSignalInit(void);
/*
* Do we have a way to ask for a signal on parent death?
*
* If we do, pmsignal.c will set up a signal handler, that sets a flag when
* the parent dies. Checking the flag first makes PostmasterIsAlive() a lot
* cheaper in usual case that the postmaster is alive.
*/
#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)
#define USE_POSTMASTER_DEATH_SIGNAL
#endif
#ifdef USE_POSTMASTER_DEATH_SIGNAL
extern volatile sig_atomic_t postmaster_possibly_dead;
static inline bool
PostmasterIsAlive(void)
{
if (likely(!postmaster_possibly_dead))
return true;
return PostmasterIsAliveInternal();
}
#else
#define PostmasterIsAlive() PostmasterIsAliveInternal()
#endif
#endif /* PMSIGNAL_H */