From 7faf95ec97cf1228674338db9cf1565d8ca236ed Mon Sep 17 00:00:00 2001 From: Bryan Green Date: Sun, 28 Jun 2026 13:24:28 -0500 Subject: [PATCH v1 4/4] pg_dump: allow more than 64 parallel jobs on Windows The Windows worker join passed every running worker's handle to one WaitForMultipleObjects() call, which waits on at most MAXIMUM_WAIT_OBJECTS (64). That capped PG_MAX_JOBS at 64 on Windows. With dispatch no longer using select()/FD_SETSIZE, this was the last thing forcing the limit. Wait on at most MAXIMUM_WAIT_OBJECTS handles per iteration. One worker is reaped per iteration and the handle set is rebuilt from those still running, so workers past the first batch are caught on later passes; this is safe because every worker has been told to exit before the wait begins. Raise PG_MAX_JOBS to INT_MAX on all platforms. --- src/bin/pg_dump/parallel.c | 12 +++++++++--- src/bin/pg_dump/parallel.h | 8 -------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c index 552a8c149e..d98ae70883 100644 --- a/src/bin/pg_dump/parallel.c +++ b/src/bin/pg_dump/parallel.c @@ -461,13 +461,19 @@ WaitForTerminatingWorkers(ParallelState *pstate) } } #else /* WIN32 */ - /* On Windows, we must use WaitForMultipleObjects() */ - HANDLE *lpHandles = pg_malloc_array(HANDLE, pstate->numWorkers); + + /* + * WaitForMultipleObjects() waits on at most MAXIMUM_WAIT_OBJECTS + * handles. Watch the first batch; we reap one per iteration and + * rescan, so any beyond it are caught on later passes. Safe because + * every worker has already been told to exit. + */ + HANDLE *lpHandles = pg_malloc_array(HANDLE, MAXIMUM_WAIT_OBJECTS); int nrun = 0; DWORD ret; uintptr_t hThread; - for (j = 0; j < pstate->numWorkers; j++) + for (j = 0; j < pstate->numWorkers && nrun < MAXIMUM_WAIT_OBJECTS; j++) { if (WORKER_IS_RUNNING(pstate->parallelSlot[j].workerStatus)) { diff --git a/src/bin/pg_dump/parallel.h b/src/bin/pg_dump/parallel.h index f7557cd089..5754e13eaa 100644 --- a/src/bin/pg_dump/parallel.h +++ b/src/bin/pg_dump/parallel.h @@ -37,16 +37,8 @@ typedef enum /* * Maximum number of parallel jobs allowed. - * - * On Windows we can only have at most MAXIMUM_WAIT_OBJECTS (= 64 usually) - * parallel jobs because that's the maximum limit for the - * WaitForMultipleObjects() call. */ -#ifdef WIN32 -#define PG_MAX_JOBS MAXIMUM_WAIT_OBJECTS -#else #define PG_MAX_JOBS INT_MAX -#endif /* ParallelSlot is an opaque struct known only within parallel.c */ typedef struct ParallelSlot ParallelSlot; -- 2.54.0.windows.1