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
Reviewed-by: Bharath Rupireddy
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/Yvo/[email protected]
In the absence of fatal errors,
pg_receivewal
- will run until terminated by the SIGINT signal
- (Control C ).
+ will run until terminated by the SIGINT
+ (Control C )
+ or SIGTERM signal.
pg_receivewal will exit with status 0 when
- terminated by the SIGINT signal. (That is the
+ terminated by the SIGINT or
+ SIGTERM 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.
a slot without consuming it, use
pg_logical_slot_peek_changes .
+
+ In the absence of fatal errors,
pg_recvlogical
+ will run until terminated by the SIGINT
+ (Control C )
+ or SIGTERM signal.
+
+
+
Exit Status
+
pg_recvlogical will exit with status 0 when
+ terminated by the SIGINT or
+ SIGTERM 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.
+
+
+
Environment
static int compresslevel = 0;
static int noloop = 0;
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 slot_exists_ok = false;
static bool do_drop_slot = false;
}
/*
- * When sigint is called, just tell the system to exit at the next possible
- * moment.
+ * When SIGINT/SIGTERM are caught, just tell the system to exit at the next
+ * possible moment.
*/
#ifndef WIN32
static void
-sigin t_handler(int signum)
+sigexi t_handler(int signum)
{
time_to_stop = true;
}
* if one is needed, in GetConnection.)
*/
#ifndef WIN32
- pqsignal(SIGINT, sigint_handler);
+ pqsignal(SIGINT, sigexit_handler);
+ pqsignal(SIGTERM, sigexit_handler);
#endif
/*
#ifndef WIN32
/*
- * When sigint is called, just tell the system to exit at the next possible
- * moment.
+ * When SIGINT/SIGTERM are caught, just tell the system to exit at the next
+ * possible moment.
*/
static void
-sigin t_handler(int signum)
+sigexi t_handler(int signum)
{
time_to_abort = true;
}
* 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