diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index 691e6eb..5434826 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -86,6 +86,7 @@ static FILE *csvlogFile = NULL; NON_EXEC_STATIC pg_time_t first_syslogger_file_time = 0; static char *last_file_name = NULL; static char *last_csv_file_name = NULL; +static bool log_metainfo_stale = false; /* * Buffers for saving partial messages from different backends. @@ -299,6 +300,15 @@ SysLoggerMain(int argc, char *argv[]) /* Clear any already-pending wakeups */ ResetLatch(MyLatch); + /* On a busy system the logfile meta information may not have been + * written so retry. (The cost of this is doing extra I/O on an + * already busy system.) Write the info before SIGHUP config file + * re-read in an attempt to not ever "skip" writing a logfile + * filename. + */ + if (log_metainfo_stale) + logfile_writename(); + /* * Process any requests or signals received recently. */ @@ -1431,6 +1441,11 @@ logfile_writename(void) if ((fh = logfile_open(tempfn, "w", true) ) == NULL) { + if (errno == ENFILE || errno == EMFILE) + /* The system is too busy to write logfile meta info. + * This is not too suprising on a busy system. + * Try again when logs are next written. */ + log_metainfo_stale = true; return; } @@ -1469,4 +1484,6 @@ logfile_writename(void) tempfn))); return; } + + log_metainfo_stale = false; }