On Tue, May 26, 2026, at 8:09 AM, Alvaro Herrera wrote:
> On 2026-May-26, Michael Paquier wrote:
>
>> This issue is different, it is a Postgres logic bug, so adding an
>> exception like the one you are suggesting is just a shortcut hiding
>> the real issue: the log file is not ready yet, but the syslogger is
>> invoked at a point when it thinks the log file exists.
>
> I think we can solve this easily by flipping a new Boolean value at the
> same point were MyBackendType was previously set.  The attached POC
> fixes the scenario you described; can you confirm?  It needs some
> additional comments, of course.
>

It fixes the issue for me. However, I'm wondering if we can avoid adding a new
boolean for it. We already have redirection_done that guarantees the syslogger
is working properly. Couldn't we use it? (SysLogger_Start() opens the file --
logfile_open -- and a few lines below it sets the redirection_done. If we adopt
this approach, a comment should be added to avoid breaking it in the future.)

> (There is one more place in elog.c where we check that MyBackendType is
> _not_ B_LOGGER, but I think that one is correct as-is; and I'm wondering
> if that would behave correctly before 0c8e082fba8d.)
>

Yes. The redirection_done guarantees that the file is open.


PS> this patch does not allow writes to syslogger as soon as possible like your
patch but it seems acceptable to me.


-- 
Euler Taveira
EDB   https://www.enterprisedb.com/
From 65decfdcb7f73ef9354c55949767cdbeb56f24ab Mon Sep 17 00:00:00 2001
From: Euler Taveira <[email protected]>
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/[email protected]
---
 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

Reply via email to