diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index fa11fa0..3d8d9cd 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -304,10 +304,38 @@ SysLoggerMain(int argc, char *argv[]) */ if (got_SIGHUP) { + int old_log_destination; + got_SIGHUP = false; + old_log_destination = Log_destination; ProcessConfigFile(PGC_SIGHUP); /* + * Ensure that additions to log_destination do not result in + * writing out-of-date data to LOG_METAINFO_DATAFILE. + */ + if (!(old_log_destination && LOG_DESTINATION_STDERR) && + (Log_destination && LOG_DESTINATION_STDERR)) + { + last_file_name = NULL; + } + + if (!(old_log_destination && LOG_DESTINATION_CSVLOG) && + (Log_destination && LOG_DESTINATION_CSVLOG)) + { + last_csv_file_name = NULL; + } + + /* + * When log_destination changes and stops writing to a logfile + * immediately remove the logfile from the LOG_METAINFO_DATAFILE + * file. (Or delete the LOG_METAINFO_DATAFILE entirely.) Do not + * wait until the next logfile rotation, which could be some while + * in the future. + */ + logfile_writename(last_file_name, last_csv_file_name); + + /* * Check if the log directory or filename pattern changed in * postgresql.conf. If so, force rotation to make sure we're * writing the logfiles in the right place. @@ -349,13 +377,6 @@ SysLoggerMain(int argc, char *argv[]) rotation_disabled = false; rotation_requested = true; } - - /* - * Force rewriting last log filename when reloading configuration, - * even if rotation_requested is false, log_destination may have - * been changed and we don't want to wait the next file rotation. - */ - logfile_writename(last_file_name, last_csv_file_name); } if (Log_RotationAge > 0 && !rotation_disabled)