8000 Fix syslogger's rotation disable/re-enable logic. · jcsston/postgres@a6708e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a6708e2

Browse files
committed
Fix syslogger's rotation disable/re-enable logic.
If it fails to open a new log file, the syslogger assumes there's something wrong with its parameters (such as log_directory), and stops attempting automatic time-based or size-based log file rotations. Sending it SIGHUP is supposed to start that up again. However, the original coding for that was really bogus, involving clobbering a couple of GUC variables and hoping that SIGHUP processing would restore them. Get rid of that technique in favor of maintaining a separate flag showing we've turned rotation off. Per report from Mark Kirkwood. Also, the syslogger will automatically attempt to create the log_directory directory if it doesn't exist, but that was only happening at startup. For consistency and ease of use, it should do the same whenever the value of log_directory is changed by SIGHUP. Back-patch to all supported branches.
1 parent b0f24b5 commit a6708e2

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/backend/postmaster/syslogger.c

Lines changed: 20 additions & 6 deletions
< 8000 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extern bool redirection_done;
8787
*/
8888
static pg_time_t next_rotation_time;
8989
static bool pipe_eof_seen = false;
90+
static bool rotation_disabled = false;
9091
static FILE *syslogFile = NULL;
9192
static FILE *csvlogFile = NULL;
9293
static char *last_file_name = NULL;
@@ -315,6 +316,11 @@ SysLoggerMain(int argc, char *argv[])
315316
pfree(currentLogDir);
316317
currentLogDir = pstrdup(Log_directory);
317318
rotation_requested = true;
319+
320+
/*
321+
* Also, create new directory if not present; ignore errors
322+
*/
323+
mkdir(Log_directory, S_IRWXU);
318324
}
319325
if (strcmp(Log_filename, currentLogFilename) != 0)
320326
{
@@ -332,9 +338,19 @@ SysLoggerMain(int argc, char *argv[])
332338
currentLogRotationAge = Log_RotationAge;
333339
set_next_rotation_time();
334340
}
341+
342+
/*
343+
* If we had a rotation-disabling failure, re-enable rotation
344+
* attempts after SIGHUP, and force one immediately.
345+
*/
346+
if (rotation_disabled)
347+
{
348+
rotation_disabled = false;
349+
rotation_requested = true;
350+
}
335351
}
336352

337-
if (!rotation_requested && Log_RotationAge > 0)
353+
if (!rotation_requested && Log_RotationAge > 0 && !rotation_disabled)
338354
{
339355
/* Do a logfile rotation if it's time */
340356
pg_time_t now = (pg_time_t) time(NULL);
@@ -343,7 +359,7 @@ SysLoggerMain(int argc, char *argv[])
343359
rotation_requested = time_based_rotation = true;
344360
}
345361

346-
if (!rotation_requested && Log_RotationSize > 0)
362+
if (!rotation_requested && Log_RotationSize > 0 && !rotation_disabled)
347363
{
348364
/* Do a rotation if file is too big */
349365
if (ftell(syslogFile) >= Log_RotationSize * 1024L)
@@ -1106,8 +1122,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11061122
{
11071123
ereport(LOG,
11081124
(errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1109-
Log_RotationAge = 0;
1110-
Log_RotationSize = 0;
1125+
rotation_disabled = true;
11111126
}
11121127

11131128
if (filename)
@@ -1164,8 +1179,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11641179
{
11651180
ereport(LOG,
11661181
(errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1167-
Log_RotationAge = 0;
1168-
Log_RotationSize = 0;
1182+
rotation_disabled = true;
11691183
}
11701184

11711185
if (filename)

0 commit comments

Comments
 (0)
0