public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tatsuo Ishii <[email protected]>
To: [email protected]
Subject: pgpool: Fix pcp main process to remember child pids upon restarting.
Date: Mon, 27 Apr 2026 06:44:59 +0000
Message-ID: <[email protected]> (raw)

Fix pcp main process to remember child pids upon restarting.

Upon failove/failback, pgpool main process sends a signal to pcp main
process to request restarting, and pcp main restarts. Problem is, when
pcp main restarts, it forgets the list of pids of its child pcp worker
process. As a result, when pgpool main sends SIGUSR2 to pcp main to
wake up pcp worker process, it cannot find the pid to send the signal
to, which causes the infinite loop in pcp worker process.

Below is a reproducer script. pcp_promote_node hangs.
------------------------------------------------
pgpool_setup -n 3 --no-stop
pg_ctl -D data2 stop
while true
do
    psql -p 11000 -c "show pool_nodes" test
    if [ $? = 0 ];then
        break;
    fi
    sleep 1
done
psql -p 11000 -c "show pool_nodes" test
pcp_recovery_node -p 11001 -n 2;pcp_promote_node -p 11001 -n 2 -s -g
------------------------------------------------

To fix the problem, we could delay the restarting of pcp main until it
delivers the signal. Unfortunately this does not work, since pgpool
main waits for pcp main process to exit. Thus processing failover does
not proceed in pgpool main.

So I decided to add a new shared memory area
(Req_info->pcp_worker_pids) to remember the pcp workers pids across
pcp main restarting. The array size is MAX_REQUEST_QUEUE_SIZE + some
room (currently 10). If all the slots in the area is used, a warning
will emitted. However, this should not happen in normal
circumstances.

When a child process is forked from pcp main, its pid is added to the
shared memory array. When child process exits, its pid in the array is
cleared to 0, representing an empty slot.

Author: Tatsuo Ishii <[email protected]>
Reported-by: Taiki Koshino <[email protected]>
Discussion: https://www.postgresql.org/message-id/20260425.223051.1207744844622514060.ishii%40postgresql.org
Backpatch-through: v4.3

Branch
------
V4_7_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=4b4df1365688b779d519421d39c923ab38c13...

Modified Files
--------------
src/include/pool.h      | 13 +++++++++++++
src/main/pgpool_main.c  |  2 ++
src/pcp_con/pcp_child.c | 38 +++++++++++++++++++++++++++++++++++++-
3 files changed, 52 insertions(+), 1 deletion(-)



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: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgpool: Fix pcp main process to remember child pids upon restarting.
  In-Reply-To: <[email protected]>

* 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