Skip to content

Commit 8b60db7

Browse files
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
1 parent 0e73327 commit 8b60db7

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

doc/src/sgml/ref/pg_receivewal.sgml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ PostgreSQL documentation
118118

119119
<para>
120120
In the absence of fatal errors, <application>pg_receivewal</application>
121-
will run until terminated by the <systemitem>SIGINT</systemitem> signal
122-
(<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>).
121+
will run until terminated by the <systemitem>SIGINT</systemitem>
122+
(<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>)
123+
or <systemitem>SIGTERM</systemitem> signal.
123124
</para>
124125
</refsect1>
125126

@@ -457,7 +458,8 @@ PostgreSQL documentation
457458

458459
<para>
459460
<application>pg_receivewal</application> will exit with status 0 when
460-
terminated by the <systemitem>SIGINT</systemitem> signal. (That is the
461+
terminated by the <systemitem>SIGINT</systemitem> or
462+
<systemitem>SIGTERM</systemitem> signal. (That is the
461463
normal way to end it. Hence it is not an error.) For fatal errors or
462464
other signals, the exit status will be nonzero.
463465
</para>

doc/src/sgml/ref/pg_recvlogical.sgml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ PostgreSQL documentation
4646
a slot without consuming it, use
4747
<link linkend="functions-replication"><function>pg_logical_slot_peek_changes</function></link>.
4848
</para>
49+
50+
<para>
51+
In the absence of fatal errors, <application>pg_recvlogical</application>
52+
will run until terminated by the <systemitem>SIGINT</systemitem>
53+
(<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>)
54+
or <systemitem>SIGTERM</systemitem> signal.
55+
</para>
4956
</refsect1>
5057

5158
<refsect1>
@@ -407,6 +414,17 @@ PostgreSQL documentation
407414
</para>
408415
</refsect1>
409416

417+
<refsect1>
418+
<title>Exit Status</title>
419+
<para>
420+
<application>pg_recvlogical</application> will exit with status 0 when
421+
terminated by the <systemitem>SIGINT</systemitem> or
422+
<systemitem>SIGTERM</systemitem> signal. (That is the
423+
normal way to end it. Hence it is not an error.) For fatal errors or
424+
other signals, the exit status will be nonzero.
425+
</para>
426+
</refsect1>
427+
410428
<refsect1>
411429
<title>Environment</title>
412430

src/bin/pg_basebackup/pg_receivewal.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int verbose = 0;
4545
static int compresslevel = 0;
4646
static int noloop = 0;
4747
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
48-
static volatile bool time_to_stop = false;
48+
static volatile sig_atomic_t time_to_stop = false;
4949
static bool do_create_slot = false;
5050
static bool slot_exists_ok = false;
5151
static bool do_drop_slot = false;
@@ -673,13 +673,13 @@ StreamLog(void)
673673
}
674674

675675
/*
676-
* When sigint is called, just tell the system to exit at the next possible
677-
* moment.
676+
* When SIGINT/SIGTERM are caught, just tell the system to exit at the next
677+
* possible moment.
678678
*/
679679
#ifndef WIN32
680680

681681
static void
682-
sigint_handler(int signum)
682+
sigexit_handler(int signum)
683683
{
684684
time_to_stop = true;
685685
}
@@ -905,7 +905,8 @@ main(int argc, char **argv)
905905
* if one is needed, in GetConnection.)
906906
*/
907907
#ifndef WIN32
908-
pqsignal(SIGINT, sigint_handler);
908+
pqsignal(SIGINT, sigexit_handler);
909+
pqsignal(SIGTERM, sigexit_handler);
909910
#endif
910911

911912
/*

src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,11 @@ StreamLogicalLog(void)
650650
#ifndef WIN32
651651

652652
/*
653-
* When sigint is called, just tell the system to exit at the next possible
654-
* moment.
653+
* When SIGINT/SIGTERM are caught, just tell the system to exit at the next
654+
* possible moment.
655655
*/
656656
static void
657-
sigint_handler(int signum)
657+
sigexit_handler(int signum)
658658
{
659659
time_to_abort = true;
660660
}
@@ -922,7 +922,8 @@ main(int argc, char **argv)
922922
* if one is needed, in GetConnection.)
923923
*/
924924
#ifndef WIN32
925-
pqsignal(SIGINT, sigint_handler);
925+
pqsignal(SIGINT, sigexit_handler);
926+
pqsignal(SIGTERM, sigexit_handler);
926927
pqsignal(SIGHUP, sighup_handler);
927928
#endif
928929

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