Subject: [PATCH v7 3/3] Fixup: assign backend type earlier

From: Álvaro Herrera <[email-masked]>
Date: Tue, 9 Dec 2025 09:53:01 +0100

---
 src/backend/postmaster/launch_backend.c | 3 +++
 src/backend/utils/error/elog.c          | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c
index 35420b8c9fb..96624e08b5a 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -588,6 +588,8 @@ SubPostmasterMain(int argc, char *argv[])
 	IsPostmasterEnvironment = true;
 	whereToSendOutput = DestNone;
 
+	MyBackendType = B_BACKEND;
+
 	/*
 	 * Capture the end of process creation for logging. We don't include the
 	 * time spent copying data from shared memory and setting up the backend.
@@ -611,6 +613,7 @@ SubPostmasterMain(int argc, char *argv[])
 		if (strcmp(child_process_kinds[idx].name, child_kind) == 0)
 		{
 			child_type = (BackendType) idx;
+			MyBackendType = child_type;
 			found = true;
 			break;
 		}
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 15d771a16c9..d7f4a44c5a7 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -2779,7 +2779,12 @@ get_backend_type_for_log(void)
 	if (MyProcPid == PostmasterPid)
 		backend_type_str = "postmaster";
 	else if (MyBackendType == B_BG_WORKER)
-		backend_type_str = MyBgworkerEntry->bgw_type;
+	{
+		if (MyBgworkerEntry && MyBgworkerEntry->bgw_type[0] != '\0')
+			backend_type_str = MyBgworkerEntry->bgw_type;
+		else
+			backend_type_str = "early bgworker";
+	}
 	else
 		backend_type_str = GetBackendTypeDesc(MyBackendType);
 
-- 
2.47.3

--grg2fqqi6tkdt5me--