agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix REPACK worker startup and shutdown sequences
Date: Thu, 17 Sep 2026 09:47:14 +0000
Message-ID: <E1x78i2-000000005ge-3L0c@gemulon.postgresql.org> (raw)

Fix REPACK worker startup and shutdown sequences

A REPACK background worker can fail to start for various reasons, but
the REPACK steering process was not handling them correctly.  For
instance, the steering process waits on a condition variable, but it
would simply hang if the worker doesn't send the signal.  (A signal
would be sent by postmaster, but it would wake up the process only to be
ignored and continue sleeping.)  Fix this by splitting the wait in two:
first wait for the worker to attach to the error queue, and then wait on
the condition variable as before.

The shutdown sequence can also get stuck, if the message queue gets full
while trying to shut down (this can apparently happen if the log level
is set to very noisy).  Previously the worker would send a signal and
then detach; but the steering process can receive that signal, act on
it, then fail to wake up to handle the detach, sleeping indefinitely.
Fix this by having the worker send a Terminate message, which the
steering process can react to.

Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Antonin Houska <ah@cybertec.at>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Shihao Zhong <zhong950419@gmail.com>
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Reported-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reported-by: Nikolay Samokhvalov <nik@postgres.ai>
Backpatch-through: 19
Discussion: https://postgr.es/m/CALj2ACVAxA9HxvFe8HSspTJ-UO4Aoz%3DkuQdZBeLrod0gqUxH3g%40mail.gmail.com
Discussion: https://postgr.es/m/apBpOVZOyqrakEr_@nathan

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/47b5b23a7800e000adebfd8f718e1302df12a7cb

Modified Files
--------------
src/backend/commands/repack.c        | 204 +++++++++++++++++++++++++++--------
src/backend/commands/repack_worker.c |  41 ++++---
src/include/libpq/protocol.h         |   3 +
3 files changed, 192 insertions(+), 56 deletions(-)



view thread (2+ messages)

Message-ID: <E1x78i2-000000005ge-3L0c@gemulon.postgresql.org>
Permalink:  ../E1x78i2-000000005ge-3L0c@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x78i2-000000005ge-3L0c@gemulon.postgresql.org

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-committers@postgresql.org
  Cc: alvherre@kurilemu.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix REPACK worker startup and shutdown sequences
  In-Reply-To: <E1x78i2-000000005ge-3L0c@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox