From 16b6b1c181b1a49eef098fc65f4c928358f9d7b9 Mon Sep 17 00:00:00 2001
From: Zsolt Parragi <zsolt.parragi@percona.com>
Date: Thu, 12 Nov 2026 00:00:22 +0000
Subject: [PATCH v1] Reset SIGCHLD in standalone backends too

Commit 2e2751e6976 moved resetting SIGCHLD from PostgresMain() to
InitPostmasterChild(). But the reset in PostgresMain() also ran in
single-user mode, which doesn't call InitPostmasterChild(). If the
standalone backend was started with SIGCHLD ignored, children are now
reaped automatically, and e.g. COPY TO PROGRAM fails with "could not
close pipe to external command: No child processes".

To fix, reset it in InitStandaloneProcess() as well.

Discussion: https://www.postgresql.org/message-id/b88a764a-b2e4-4dac-9d25-7249215db2b7@iki.fi
---
 src/backend/utils/init/miscinit.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 27bafafcd86..e9c923df861 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -210,6 +210,12 @@ InitStandaloneProcess(const char *argv0)
 	pqinitmask();
 	sigprocmask(SIG_SETMASK, &BlockSig, NULL);
 
+	/*
+	 * Reset SIGCHLD, in case we were started with it ignored.  See
+	 * InitPostmasterChild.
+	 */
+	pqsignal(SIGCHLD, PG_SIG_DFL);
+
 	/* Compute paths, no postmaster to inherit from */
 	if (my_exec_path[0] == '\0')
 	{
-- 
2.56.0

