mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Handle SIGTERM in pg_receivewal and pg_recvlogical
In pg_receivewal, compressed output is only flushed on clean exits. The reason to support SIGTERM as well as SIGINT (which is currently handled) is that pg_receivewal might well be running as a daemon, and systemd's default KillSignal is SIGTERM. Since pg_recvlogical is also supposed to run as a daemon, teach it about SIGTERM as well and update the documentation to match. While in there, change pg_receivewal's time_to_stop to be sig_atomic_t like it is in pg_recvlogical. Author: Christoph Berg <myon@debian.org> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/Yvo/5No5S0c4EFMj@msg.df7cb.de
This commit is contained in:
@ -118,8 +118,9 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
In the absence of fatal errors, <application>pg_receivewal</application>
|
In the absence of fatal errors, <application>pg_receivewal</application>
|
||||||
will run until terminated by the <systemitem>SIGINT</systemitem> signal
|
will run until terminated by the <systemitem>SIGINT</systemitem>
|
||||||
(<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>).
|
(<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>)
|
||||||
|
or <systemitem>SIGTERM</systemitem> signal.
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
@ -457,7 +458,8 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
<application>pg_receivewal</application> will exit with status 0 when
|
<application>pg_receivewal</application> will exit with status 0 when
|
||||||
terminated by the <systemitem>SIGINT</systemitem> signal. (That is the
|
terminated by the <systemitem>SIGINT</systemitem> or
|
||||||
|
<systemitem>SIGTERM</systemitem> signal. (That is the
|
||||||
normal way to end it. Hence it is not an error.) For fatal errors or
|
normal way to end it. Hence it is not an error.) For fatal errors or
|
||||||
other signals, the exit status will be nonzero.
|
other signals, the exit status will be nonzero.
|
||||||
</para>
|
</para>
|
||||||
|
@ -46,6 +46,13 @@ PostgreSQL documentation
|
|||||||
a slot without consuming it, use
|
a slot without consuming it, use
|
||||||
<link linkend="functions-replication"><function>pg_logical_slot_peek_changes</function></link>.
|
<link linkend="functions-replication"><function>pg_logical_slot_peek_changes</function></link>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
In the absence of fatal errors, <application>pg_recvlogical</application>
|
||||||
|
will run until terminated by the <systemitem>SIGINT</systemitem>
|
||||||
|
(<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>)
|
||||||
|
or <systemitem>SIGTERM</systemitem> signal.
|
||||||
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
@ -407,6 +414,17 @@ PostgreSQL documentation
|
|||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Exit Status</title>
|
||||||
|
<para>
|
||||||
|
<application>pg_recvlogical</application> will exit with status 0 when
|
||||||
|
terminated by the <systemitem>SIGINT</systemitem> or
|
||||||
|
<systemitem>SIGTERM</systemitem> signal. (That is the
|
||||||
|
normal way to end it. Hence it is not an error.) For fatal errors or
|
||||||
|
other signals, the exit status will be nonzero.
|
||||||
|
</para>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Environment</title>
|
<title>Environment</title>
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ static int verbose = 0;
|
|||||||
static int compresslevel = 0;
|
static int compresslevel = 0;
|
||||||
static int noloop = 0;
|
static int noloop = 0;
|
||||||
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
|
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
|
||||||
static volatile bool time_to_stop = false;
|
static volatile sig_atomic_t time_to_stop = false;
|
||||||
static bool do_create_slot = false;
|
static bool do_create_slot = false;
|
||||||
static bool slot_exists_ok = false;
|
static bool slot_exists_ok = false;
|
||||||
static bool do_drop_slot = false;
|
static bool do_drop_slot = false;
|
||||||
@ -673,13 +673,13 @@ StreamLog(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When sigint is called, just tell the system to exit at the next possible
|
* When SIGINT/SIGTERM are caught, just tell the system to exit at the next
|
||||||
* moment.
|
* possible moment.
|
||||||
*/
|
*/
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sigint_handler(int signum)
|
sigexit_handler(int signum)
|
||||||
{
|
{
|
||||||
time_to_stop = true;
|
time_to_stop = true;
|
||||||
}
|
}
|
||||||
@ -905,7 +905,8 @@ main(int argc, char **argv)
|
|||||||
* if one is needed, in GetConnection.)
|
* if one is needed, in GetConnection.)
|
||||||
*/
|
*/
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
pqsignal(SIGINT, sigint_handler);
|
pqsignal(SIGINT, sigexit_handler);
|
||||||
|
pqsignal(SIGTERM, sigexit_handler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -650,11 +650,11 @@ error:
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When sigint is called, just tell the system to exit at the next possible
|
* When SIGINT/SIGTERM are caught, just tell the system to exit at the next
|
||||||
* moment.
|
* possible moment.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
sigint_handler(int signum)
|
sigexit_handler(int signum)
|
||||||
{
|
{
|
||||||
time_to_abort = true;
|
time_to_abort = true;
|
||||||
}
|
}
|
||||||
@ -922,7 +922,8 @@ main(int argc, char **argv)
|
|||||||
* if one is needed, in GetConnection.)
|
* if one is needed, in GetConnection.)
|
||||||
*/
|
*/
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
pqsignal(SIGINT, sigint_handler);
|
pqsignal(SIGINT, sigexit_handler);
|
||||||
|
pqsignal(SIGTERM, sigexit_handler);
|
||||||
pqsignal(SIGHUP, sighup_handler);
|
pqsignal(SIGHUP, sighup_handler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user