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

Commita6708e2

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 parentb0f24b5 commita6708e2

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
@@ -87,6 +87,7 @@ extern bool redirection_done;
8787
*/
8888
staticpg_time_tnext_rotation_time;
8989
staticboolpipe_eof_seen= false;
90+
staticboolrotation_disabled= false;
9091
staticFILE*syslogFile=NULL;
9192
staticFILE*csvlogFile=NULL;
9293
staticchar*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_tnow= (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)

[8]ページ先頭

©2009-2025 Movatter.jp