pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Berg <myon@debian.org>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: pg_receivewal and SIGTERM
Date: Mon, 15 Aug 2022 14:45:24 +0200
Message-ID: <Yvo/5No5S0c4EFMj@msg.df7cb.de> (raw)

There's a smallish backup tool called pg_backupcluster in Debian's
postgresql-common which also ships a systemd service that runs
pg_receivewal for wal archiving, and supplies a pg_getwal script for
reading the files back on restore, including support for .partial
files.

So far the machinery was using plain files and relied on compressing
the WALs from time to time, but now I wanted to compress the files
directly from pg_receivewal --compress=5. Unfortunately this broke the
regression tests that include a test for the .partial files where
pg_receivewal.service is shut down before the segment is full.

The problem was that systemd's default KillSignal is SIGTERM, while
pg_receivewal flushes the output compression buffers on SIGINT only.
The attached patch makes it do the same for SIGTERM as well. (Most
places in PG that install a SIGINT handler also install a SIGTERM
handler already.)

Christoph

Attachments:

0001-pg_receivewal-Exit-cleanly-on-SIGTERM.patch (text/x-diff, 2.1K) download From 8e42bf5458ae00050327da07c09a77649f24e36d 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: Exit cleanly on SIGTERM 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. --- doc/src/sgml/ref/pg_receivewal.sgml | 8 +++++--- src/bin/pg_basebackup/pg_receivewal.c | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/ref/pg_receivewal.sgml b/doc/src/sgml/ref/pg_receivewal.sgml index 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/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index f064cff4ab..4acd0654b9 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -933,6 +933,7 @@ main(int argc, char **argv) */ #ifndef WIN32 pqsignal(SIGINT, sigint_handler); + pqsignal(SIGTERM, sigint_handler); #endif /* -- 2.35.1

view thread (24+ messages)  latest in thread

Message-ID: <Yvo/5No5S0c4EFMj@msg.df7cb.de>
Permalink:  ../Yvo%2F5No5S0c4EFMj@msg.df7cb.de/
Also on:    postgresql.org/message-id/Yvo/5No5S0c4EFMj@msg.df7cb.de

 ·  · 

reply

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, pgsql-hackers@lists.postgresql.org
  Subject: Re: pg_receivewal and SIGTERM
  In-Reply-To: <Yvo/5No5S0c4EFMj@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