From fcae61d773822d2d08316d06255ff628e372533a Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Wed, 20 Aug 2025 17:40:52 +0900 Subject: [PATCH v1-PG17] Make parallel apply worker accept lock timeout When a lock timeout happens, the process sends SIGINT to itself. Processes that access tables typically use StatementCancelHandler as the signal handler for SIGINT; thus, the timeout can control them. In terms of parallel apply worker, however, they used the signal for the sign for graceful shutdown. This made it difficult for users to recognize whether the timeout happened. This patch makes parallel apply workers use the same signal handler as other backends. SIGUSR2 is now used as the stop signal. --- src/backend/postmaster/interrupt.c | 5 ++--- src/backend/replication/logical/applyparallelworker.c | 8 ++++---- src/backend/replication/logical/launcher.c | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backend/postmaster/interrupt.c b/src/backend/postmaster/interrupt.c index eedc0980cf1..1c18fe10228 100644 --- a/src/backend/postmaster/interrupt.c +++ b/src/backend/postmaster/interrupt.c @@ -94,9 +94,8 @@ SignalHandlerForCrashExit(SIGNAL_ARGS) * shut down and exit. * * Typically, this handler would be used for SIGTERM, but some processes use - * other signals. In particular, the checkpointer exits on SIGUSR2, and the WAL - * writer and the logical replication parallel apply worker exits on either - * SIGINT or SIGTERM. + * other signals. In particular, the checkpointer and parallel apply worker + * exits on SIGUSR2, and the WAL writer exits on either SIGINT or SIGTERM. * * ShutdownRequestPending should be checked at a convenient place within the * main loop, or else the main loop should call HandleMainLoopInterrupts. diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index e7f7d4c5e4b..aea34a27cb3 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -871,8 +871,8 @@ ParallelApplyWorkerMain(Datum main_arg) /* Setup signal handling. */ pqsignal(SIGHUP, SignalHandlerForConfigReload); - pqsignal(SIGINT, SignalHandlerForShutdownRequest); pqsignal(SIGTERM, die); + pqsignal(SIGUSR2, SignalHandlerForShutdownRequest); BackgroundWorkerUnblockSignals(); /* @@ -971,9 +971,9 @@ ParallelApplyWorkerMain(Datum main_arg) /* * The parallel apply worker must not get here because the parallel apply - * worker will only stop when it receives a SIGTERM or SIGINT from the - * leader, or when there is an error. None of these cases will allow the - * code to reach here. + * worker will only stop when it receives a SIGTERM or SINUSR2 from the + * leader, SIGINT from myself, or when there is an error. None of these + * cases will allow the code to reach here. */ Assert(false); } diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c index 294d0d74d8c..2ffa5cb91f7 100644 --- a/src/backend/replication/logical/launcher.c +++ b/src/backend/replication/logical/launcher.c @@ -639,7 +639,7 @@ logicalrep_worker_stop(Oid subid, Oid relid) /* * Stop the given logical replication parallel apply worker. * - * Node that the function sends SIGINT instead of SIGTERM to the parallel apply + * Node that the function sends SIGUSR2 instead of SIGTERM to the parallel apply * worker so that the worker exits cleanly. */ void @@ -677,7 +677,7 @@ logicalrep_pa_worker_stop(ParallelApplyWorkerInfo *winfo) * Only stop the worker if the generation matches and the worker is alive. */ if (worker->generation == generation && worker->proc) - logicalrep_worker_stop_internal(worker, SIGINT); + logicalrep_worker_stop_internal(worker, SIGUSR2); LWLockRelease(LogicalRepWorkerLock); } -- 2.47.1