From: Christoph Berg <myon@debian.org>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Daniel Gustafsson <daniel@yesql.se>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: pg_receivewal and SIGTERM
Date: Tue, 16 Aug 2022 15:56:45 +0200
Message-ID: <YvuiHaqzde5FJEIC@msg.df7cb.de> (raw)
In-Reply-To: <CALj2ACVTxZg_B5KTFbDYNKbP2=SXhxBWvopvK04eT0UvDsDckg@mail.gmail.com>
References: <Yvo/5No5S0c4EFMj@msg.df7cb.de>
<EC39E60E-C8B6-4CDF-8BFA-E4D140446B41@yesql.se>
<YvuBL1tvlSNiFQUB@msg.df7cb.de>
<15338147-16C0-4D4D-8CAD-460102857BF6@yesql.se>
<CALj2ACVTxZg_B5KTFbDYNKbP2=SXhxBWvopvK04eT0UvDsDckg@mail.gmail.com>
Re: Bharath Rupireddy
> Don't we need a similar explanation [1] for pg_recvlogical docs?
>
> [1]
> <para>
> In the absence of fatal errors, <application>pg_receivewal</application>
> - will run until terminated by the <systemitem>SIGINT</systemitem> signal
> - (<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>).
> + will run until terminated by the <systemitem>SIGINT</systemitem>
> + (<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>)
> + or <systemitem>SIGTERM</systemitem> signal.
Coped that from pg_receivewal(1) now.
Christoph
Attachments:0001-pg_receivewal-pg_recvlogical-Exit-cleanly-on-SIGTERM.patch (text/x-diff, 4.2K) download
From 6c51c559a86754623cd33fe4cef3563c18fccea3 Mon Sep 17 00:00:00 2001
From: Christoph Berg <myon@debian.org>
Date: Mon, 15 Aug 2022 14:29:43 +0200
Subject: [PATCH] pg_receivewal, pg_recvlogical: Exit cleanly on SIGTERM
In pg_receivewal, compressed output is only flushed on clean exits. The
reason to support SIGTERM here as well 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.
---
doc/src/sgml/ref/pg_receivewal.sgml | 8 +++++---
doc/src/sgml/ref/pg_recvlogical.sgml | 7 +++++++
src/bin/pg_basebackup/pg_receivewal.c | 7 ++++---
src/bin/pg_basebackup/pg_recvlogical.c | 7 ++++---
4 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/doc/src/sgml/ref/pg_receivewal.sgml b/doc/src/sgml/ref/pg_receivewal.sgmlindex 4fe9e1a874..5f83ba1893 100644--- a/doc/src/sgml/ref/pg_receivewal.sgml+++ b/doc/src/sgml/ref/pg_receivewal.sgml@@ -118,8 +118,9 @@ PostgreSQL documentation
<para>
In the absence of fatal errors, <application>pg_receivewal</application>
- will run until terminated by the <systemitem>SIGINT</systemitem> signal- (<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>).+ 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>
@@ -457,7 +458,8 @@ PostgreSQL documentation
<para>
<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
other signals, the exit status will be nonzero.
</para>
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgmlindex 1a88225409..012ee4468b 100644--- a/doc/src/sgml/ref/pg_recvlogical.sgml+++ b/doc/src/sgml/ref/pg_recvlogical.sgml@@ -46,6 +46,13 @@ PostgreSQL documentation
a slot without consuming it, use
<link linkend="functions-replication"><function>pg_logical_slot_peek_changes</function></link>.
</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>
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.cindex f064cff4ab..e2cf924017 100644--- a/src/bin/pg_basebackup/pg_receivewal.c+++ b/src/bin/pg_basebackup/pg_receivewal.c@@ -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 possible
* moment.
*/
#ifndef WIN32
static void
-sigint_handler(int signum)+sigexit_handler(int signum)
{
time_to_stop = true;
}
@@ -932,7 +932,8 @@ main(int argc, char **argv)
* if one is needed, in GetConnection.)
*/
#ifndef WIN32
- pqsignal(SIGINT, sigint_handler);+ pqsignal(SIGINT, sigexit_handler);+ pqsignal(SIGTERM, sigexit_handler);
#endif
/*
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.cindex 2a4c8b130a..363102cf85 100644--- a/src/bin/pg_basebackup/pg_recvlogical.c+++ b/src/bin/pg_basebackup/pg_recvlogical.c@@ -650,11 +650,11 @@ error:
#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 possible
* moment.
*/
static void
-sigint_handler(int signum)+sigexit_handler(int signum)
{
time_to_abort = true;
}
@@ -922,7 +922,8 @@ main(int argc, char **argv)
* if one is needed, in GetConnection.)
*/
#ifndef WIN32
- pqsignal(SIGINT, sigint_handler);+ pqsignal(SIGINT, sigexit_handler);+ pqsignal(SIGTERM, sigexit_handler);
pqsignal(SIGHUP, sighup_handler);
#endif
--
2.35.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: myon@debian.org, bharath.rupireddyforpostgres@gmail.com, daniel@yesql.se, pgsql-hackers@lists.postgresql.org
Subject: Re: pg_receivewal and SIGTERM
In-Reply-To: <YvuiHaqzde5FJEIC@msg.df7cb.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox