mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Improve client error messages for immediate-stop situations.
Up to now, if the DBA issued "pg_ctl stop -m immediate", the message sent to clients was the same as for a crash-and-restart situation. This is confusing, not least because the message claims that the database will soon be up again, something we have no business predicting. Improve things so that we can generate distinct messages for the two cases (and also recognize an ad-hoc SIGQUIT, should somebody try that). To do that, add a field to pmsignal.c's shared memory data structure that the postmaster sets just before broadcasting SIGQUIT to its children. No interlocking seems to be necessary; the intervening signal-sending and signal-receipt should sufficiently serialize accesses to the field. Hence, this isn't any riskier than the existing usages of pmsignal.c. We might in future extend this idea to improve other postmaster-to-children signal scenarios, although none of them currently seem to be as badly overloaded as SIGQUIT. Discussion: https://postgr.es/m/559291.1608587013@sss.pgh.pa.us
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pmsignal.c
|
||||
* routines for signaling the postmaster from its child processes
|
||||
* routines for signaling between the postmaster and its child processes
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
||||
@@ -55,6 +55,10 @@
|
||||
* but carries the extra information that the child is a WAL sender.
|
||||
* WAL senders too start in ACTIVE state, but switch to WALSENDER once they
|
||||
* start streaming the WAL (and they never go back to ACTIVE after that).
|
||||
*
|
||||
* We also have a shared-memory field that is used for communication in
|
||||
* the opposite direction, from postmaster to children: it tells why the
|
||||
* postmaster has broadcasted SIGQUIT signals, if indeed it has done so.
|
||||
*/
|
||||
|
||||
#define PM_CHILD_UNUSED 0 /* these values must fit in sig_atomic_t */
|
||||
@@ -65,8 +69,10 @@
|
||||
/* "typedef struct PMSignalData PMSignalData" appears in pmsignal.h */
|
||||
struct PMSignalData
|
||||
{
|
||||
/* per-reason flags */
|
||||
/* per-reason flags for signaling the postmaster */
|
||||
sig_atomic_t PMSignalFlags[NUM_PMSIGNALS];
|
||||
/* global flags for signals from postmaster to children */
|
||||
QuitSignalReason sigquit_reason; /* why SIGQUIT was sent */
|
||||
/* per-child-process flags */
|
||||
int num_child_flags; /* # of entries in PMChildFlags[] */
|
||||
int next_child_flag; /* next slot to try to assign */
|
||||
@@ -134,6 +140,7 @@ PMSignalShmemInit(void)
|
||||
|
||||
if (!found)
|
||||
{
|
||||
/* initialize all flags to zeroes */
|
||||
MemSet(unvolatize(PMSignalData *, PMSignalState), 0, PMSignalShmemSize());
|
||||
PMSignalState->num_child_flags = MaxLivePostmasterChildren();
|
||||
}
|
||||
@@ -171,6 +178,34 @@ CheckPostmasterSignal(PMSignalReason reason)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* SetQuitSignalReason - broadcast the reason for a system shutdown.
|
||||
* Should be called by postmaster before sending SIGQUIT to children.
|
||||
*
|
||||
* Note: in a crash-and-restart scenario, the "reason" field gets cleared
|
||||
* as a part of rebuilding shared memory; the postmaster need not do it
|
||||
* explicitly.
|
||||
*/
|
||||
void
|
||||
SetQuitSignalReason(QuitSignalReason reason)
|
||||
{
|
||||
PMSignalState->sigquit_reason = reason;
|
||||
}
|
||||
|
||||
/*
|
||||
* GetQuitSignalReason - obtain the reason for a system shutdown.
|
||||
* Called by child processes when they receive SIGQUIT.
|
||||
* If the postmaster hasn't actually sent SIGQUIT, will return PMQUIT_NOT_SENT.
|
||||
*/
|
||||
QuitSignalReason
|
||||
GetQuitSignalReason(void)
|
||||
{
|
||||
/* This is called in signal handlers, so be extra paranoid. */
|
||||
if (!IsUnderPostmaster || PMSignalState == NULL)
|
||||
return PMQUIT_NOT_SENT;
|
||||
return PMSignalState->sigquit_reason;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* AssignPostmasterChildSlot - select an unused slot for a new postmaster
|
||||
|
Reference in New Issue
Block a user