From bd0fc1ee65e81fc614215895448ef7840cf6d6ba Mon Sep 17 00:00:00 2001
From: Harrison Booth <harrisontbooth@gmail.com>
Date: Mon, 12 Oct 2026 20:51:37 -0500
Subject: [PATCH 2/2] Use an unnamed job for PostgreSQL orphan cleanup

Keep the cleanup job private to the postmaster's handle. A predictable
name allows CreateJobObject to open an existing object, or another
process to open the configured job. Either can keep the last handle
alive after postmaster exit and delay KILL_ON_JOB_CLOSE cleanup.

An unnamed, non-inherited job avoids that named-object dependency while
preserving automatic child membership and compatible nested-job use.
Update diagnostics that formerly displayed the unused job name.

This supplements Bryan Green's CF6201 v2 proposal. Source-extracted
ARM64 and emulated x64 tests verify suspended-child cleanup and show
the named-collision delay disappears with the anonymous candidate.
---
 src/backend/storage/ipc/pg_job_object.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/backend/storage/ipc/pg_job_object.c b/src/backend/storage/ipc/pg_job_object.c
index 4c9bd90f3b3c1515e9e217f31f88d50a94e3e577..c67edc338e6b91e372e42153d8e4b30da90b466e 100644
--- a/src/backend/storage/ipc/pg_job_object.c
+++ b/src/backend/storage/ipc/pg_job_object.c
@@ -50,25 +50,21 @@ void
 pg_create_job_object(void)
 {
 	JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info;
-	char		job_name[128];
 	DWORD		error;
 
-	snprintf(job_name, sizeof(job_name), "PostgreSQL_Port_%d_PID_%lu",
-			 PostPortNumber, GetCurrentProcessId());
-
-	pg_job_object = CreateJobObjectA(NULL, job_name);
+	/* Keep cleanup independent of other processes opening a named job. */
+	pg_job_object = CreateJobObjectA(NULL, NULL);
 
 	if (pg_job_object == NULL)
 	{
 		error = GetLastError();
 		ereport(LOG,
-				(errmsg("could not create job object \"%s\": error code %lu",
-						job_name, error),
+				(errmsg("could not create job object: error code %lu", error),
 				 errdetail("Orphaned process cleanup will not be available.")));
 		return;
 	}
 
-	elog(DEBUG1, "created job object \"%s\"", job_name);
+	elog(DEBUG1, "created job object");
 
 	/*
 	 * Set KILL_ON_JOB_CLOSE. When the job handle closes (either explicit
-- 
2.53.0.windows.2

