From 65decfdcb7f73ef9354c55949767cdbeb56f24ab Mon Sep 17 00:00:00 2001
From: Euler Taveira <euler@eulerto.com>
Date: Tue, 26 May 2026 11:49:28 -0300
Subject: [PATCH] syslogger: try to write messages only after setup

Since commit 0c8e082fba8d there is no guarantee that syslogger finishes
its setup before any process can use it. Add an extra check that is only
set after the setup is done.

Discussion: https://postgr.es/m/ahP-JT4ZRPyobnLb@paquier.xyz
---
 src/backend/utils/error/elog.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 50c53b571a0..8e1796ce5ff 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -3884,8 +3884,11 @@ send_message_to_server_log(ErrorData *edata)
 			write_console(buf.data, buf.len);
 	}
 
-	/* If in the syslogger process, try to write messages direct to file */
-	if (MyBackendType == B_LOGGER)
+	/*
+	 * If in the syslogger process (and its setup is done), try to write
+	 * messages direct to file.
+	 */
+	if (redirection_done && MyBackendType == B_LOGGER)
 		write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);
 
 	/* No more need of the message formatted for stderr */
-- 
2.39.5

