Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit537b266

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 somethingwrong with its parameters (such as log_directory), and stops attemptingautomatic time-based or size-based log file rotations. Sending it SIGHUPis supposed to start that up again. However, the original coding for thatwas really bogus, involving clobbering a couple of GUC variables and hopingthat SIGHUP processing would restore them. Get rid of that technique infavor 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_directorydirectory 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 valueof log_directory is changed by SIGHUP.Back-patch to all supported branches.
1 parent3424bff commit537b266

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
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extern bool redirection_done;
8888
*/
8989
staticpg_time_tnext_rotation_time;
9090
staticboolpipe_eof_seen= false;
91+
staticboolrotation_disabled= false;
9192
staticFILE*syslogFile=NULL;
9293
staticFILE*csvlogFile=NULL;
9394
staticchar*last_file_name=NULL;
@@ -318,6 +319,11 @@ SysLoggerMain(int argc, char *argv[])
318319
pfree(currentLogDir);
319320
currentLogDir=pstrdup(Log_directory);
320321
rotation_requested= true;
322+
323+
/*
324+
* Also, create new directory if not present; ignore errors
325+
*/
326+
mkdir(Log_directory,S_IRWXU);
321327
}
322328
if (strcmp(Log_filename,currentLogFilename)!=0)
323329
{
@@ -335,9 +341,19 @@ SysLoggerMain(int argc, char *argv[])
335341
currentLogRotationAge=Log_RotationAge;
336342
set_next_rotation_time();
337343
}
344+
345+
/*
346+
* If we had a rotation-disabling failure, re-enable rotation
347+
* attempts after SIGHUP, and force one immediately.
348+
*/
349+
if (rotation_disabled)
350+
{
351+
rotation_disabled= false;
352+
rotation_requested= true;
353+
}
338354
}
339355

340-
if (!rotation_requested&&Log_RotationAge>0)
356+
if (!rotation_requested&&Log_RotationAge>0&& !rotation_disabled)
341357
{
342358
/* Do a logfile rotation if it's time */
343359
pg_time_tnow= (pg_time_t)time(NULL);
@@ -346,7 +362,7 @@ SysLoggerMain(int argc, char *argv[])
346362
rotation_requested=time_based_rotation= true;
347363
}
348364

349-
if (!rotation_requested&&Log_RotationSize>0)
365+
if (!rotation_requested&&Log_RotationSize>0&& !rotation_disabled)
350366
{
351367
/* Do a rotation if file is too big */
352368
if (ftell(syslogFile) >=Log_RotationSize*1024L)
@@ -1122,8 +1138,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11221138
{
11231139
ereport(LOG,
11241140
(errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1125-
Log_RotationAge=0;
1126-
Log_RotationSize=0;
1141+
rotation_disabled= true;
11271142
}
11281143

11291144
if (filename)
@@ -1167,8 +1182,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11671182
{
11681183
ereport(LOG,
11691184
(errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1170-
Log_RotationAge=0;
1171-
Log_RotationSize=0;
1185+
rotation_disabled= true;
11721186
}
11731187

11741188
if (filename)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp