From a283180ad3b3bffe8ae04d59f61212ff95ccbee6 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 4 Jul 2026 11:11:09 +0200
Subject: [PATCH v2 1/2] Use exit_nicely in die_on_query_failure

We want a query failure to kill the worker not the whole process. On
Unix that's currently the same thing, but on Windows workers are
threads.
---
 src/bin/pg_dump/pg_backup_db.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 5c349279beb..f6bca7dc508 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -210,7 +210,13 @@ die_on_query_failure(ArchiveHandle *AH, const char *query)
 	pg_log_error("query failed: %s",
 				 PQerrorMessage(AH->connection));
 	pg_log_error_detail("Query was: %s", query);
-	exit(1);
+
+	/*
+	 * Use exit_nicely() rather than exit(): on Windows the workers are
+	 * threads, and a failed worker's query must only end its own thread, not
+	 * bring down the whole process.
+	 */
+	exit_nicely(1);
 }
 
 void

base-commit: e42d4a1f3dc59420be796883404020cb41ddd05e
-- 
2.54.0

