diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 6e7bdce..8569cea 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -1171,6 +1171,8 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
char *csvfilename = NULL;
pg_time_t fntime;
FILE *fh;
+ bool rotate_csvlog;
+ bool rotate_stderr;
rotation_requested = false;
@@ -1195,7 +1197,9 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
*
* Note: last_file_name should never be NULL here, but if it is, append.
*/
- if (time_based_rotation || (size_rotation_for & LOG_DESTINATION_STDERR))
+ rotate_stderr = time_based_rotation ||
+ (size_rotation_for & LOG_DESTINATION_STDERR);
+ if (rotate_stderr)
{
if (Log_truncate_on_rotation && time_based_rotation &&
last_file_name != NULL &&
@@ -1226,9 +1230,6 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
return;
}
- if (csvlogFile == NULL)
- logfile_writename(filename, csvfilename);
-
fclose(syslogFile);
syslogFile = fh;
@@ -1240,8 +1241,10 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
}
/* Same as above, but for csv file. */
- if (csvlogFile != NULL &&
- (time_based_rotation || (size_rotation_for & LOG_DESTINATION_CSVLOG)))
+ rotate_csvlog = csvlogFile != NULL &&
+ (time_based_rotation ||
+ (size_rotation_for & LOG_DESTINATION_CSVLOG));
+ if (rotate_csvlog)
{
if (Log_truncate_on_rotation && time_based_rotation &&
last_csv_file_name != NULL &&
@@ -1280,11 +1283,11 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
pfree(last_csv_file_name);
last_csv_file_name = csvfilename;
csvfilename = NULL;
+ }
+ if (rotate_stderr || rotate_csvlog)
logfile_writename(last_file_name, last_csv_file_name);
- }
-
if (filename)
pfree(filename);
if (csvfilename)