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

Commit1f9158b

Browse files
committed
Suppress log spam from multiple reports of SIGQUIT shutdown.
When the postmaster sends SIGQUIT to its children, there's no realneed for all the children to log that fact; the postmaster alreadymade a log entry about it, so adding perhaps dozens or hundreds ofchild-process log entries adds nothing of value. So, let's introducea new ereport level to specify "WARNING, but never send to log" anduse that for these messages.Such a change wouldn't have been desirable before commit7e784d1,because if someone manually SIGQUIT's a backend, we *do* want to logthat. But now we can tell the difference between a signal that wasissued by the postmaster and one that was not with reasonablecertainty.While we're here, also clear error_context_stack before ereport'ing,to prevent error callbacks from being invoked in the signal-handlercontext. This should reduce the odds of getting hung up while tryingto notify the client.Per a suggestion from Andres Freund.Discussion:https://postgr.es/m/20201225230331.hru3u6obyy6j53tk@alap3.anarazel.de
1 parentdb6335b commit1f9158b

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

‎src/backend/tcop/postgres.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,6 +2789,18 @@ quickdie(SIGNAL_ARGS)
27892789
* wrong, so there's not much to lose. Assuming the postmaster is still
27902790
* running, it will SIGKILL us soon if we get stuck for some reason.
27912791
*
2792+
* One thing we can do to make this a tad safer is to clear the error
2793+
* context stack, so that context callbacks are not called. That's a lot
2794+
* less code that could be reached here, and the context info is unlikely
2795+
* to be very relevant to a SIGQUIT report anyway.
2796+
*/
2797+
error_context_stack=NULL;
2798+
2799+
/*
2800+
* When responding to a postmaster-issued signal, we send the message only
2801+
* to the client; sending to the server log just creates log spam, plus
2802+
* it's more code that we need to hope will work in a signal handler.
2803+
*
27922804
* Ideally these should be ereport(FATAL), but then we'd not get control
27932805
* back to force the correct type of process exit.
27942806
*/
@@ -2802,7 +2814,7 @@ quickdie(SIGNAL_ARGS)
28022814
break;
28032815
casePMQUIT_FOR_CRASH:
28042816
/* A crash-and-restart cycle is in progress */
2805-
ereport(WARNING,
2817+
ereport(WARNING_CLIENT_ONLY,
28062818
(errcode(ERRCODE_CRASH_SHUTDOWN),
28072819
errmsg("terminating connection because of crash of another server process"),
28082820
errdetail("The postmaster has commanded this server process to roll back"
@@ -2814,7 +2826,7 @@ quickdie(SIGNAL_ARGS)
28142826
break;
28152827
casePMQUIT_FOR_STOP:
28162828
/* Immediate-mode stop */
2817-
ereport(WARNING,
2829+
ereport(WARNING_CLIENT_ONLY,
28182830
(errcode(ERRCODE_ADMIN_SHUTDOWN),
28192831
errmsg("terminating connection due to immediate shutdown command")));
28202832
break;

‎src/backend/utils/error/elog.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ is_log_level_output(int elevel, int log_min_level)
202202
if (log_min_level==LOG||log_min_level <=ERROR)
203203
return true;
204204
}
205+
elseif (elevel==WARNING_CLIENT_ONLY)
206+
{
207+
/* never sent to log, regardless of log_min_level */
208+
return false;
209+
}
205210
elseif (log_min_level==LOG)
206211
{
207212
/* elevel != LOG */
@@ -453,7 +458,7 @@ errstart(int elevel, const char *domain)
453458
/* Select default errcode based on elevel */
454459
if (elevel >=ERROR)
455460
edata->sqlerrcode=ERRCODE_INTERNAL_ERROR;
456-
elseif (elevel==WARNING)
461+
elseif (elevel>=WARNING)
457462
edata->sqlerrcode=ERRCODE_WARNING;
458463
else
459464
edata->sqlerrcode=ERRCODE_SUCCESSFUL_COMPLETION;
@@ -2152,6 +2157,7 @@ write_eventlog(int level, const char *line, int len)
21522157
eventlevel=EVENTLOG_INFORMATION_TYPE;
21532158
break;
21542159
caseWARNING:
2160+
caseWARNING_CLIENT_ONLY:
21552161
eventlevel=EVENTLOG_WARNING_TYPE;
21562162
break;
21572163
caseERROR:
@@ -3109,6 +3115,7 @@ send_message_to_server_log(ErrorData *edata)
31093115
break;
31103116
caseNOTICE:
31113117
caseWARNING:
3118+
caseWARNING_CLIENT_ONLY:
31123119
syslog_level=LOG_NOTICE;
31133120
break;
31143121
caseERROR:
@@ -3484,6 +3491,7 @@ error_severity(int elevel)
34843491
prefix=gettext_noop("NOTICE");
34853492
break;
34863493
caseWARNING:
3494+
caseWARNING_CLIENT_ONLY:
34873495
prefix=gettext_noop("WARNING");
34883496
break;
34893497
caseERROR:

‎src/include/utils/elog.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@
4040
#defineWARNING19/* Warnings. NOTICE is for expected messages
4141
* like implicit sequence creation by SERIAL.
4242
* WARNING is for unexpected messages. */
43-
#defineERROR20/* user error - abort transaction; return to
43+
#defineWARNING_CLIENT_ONLY20/* Warnings to be sent to client as usual, but
44+
* never to the server log. */
45+
#defineERROR21/* user error - abort transaction; return to
4446
* known state */
4547
/* Save ERROR value in PGERROR so it can be restored when Win32 includes
4648
* modify it. We have to use a constant rather than ERROR because macros
4749
* are expanded only when referenced outside macros.
4850
*/
4951
#ifdefWIN32
50-
#definePGERROR20
52+
#definePGERROR21
5153
#endif
52-
#defineFATAL21/* fatal error - abort process */
53-
#definePANIC22/* take down the other backends with me */
54-
55-
/* #define DEBUG DEBUG1 *//* Backward compatibility with pre-7.3 */
54+
#defineFATAL22/* fatal error - abort process */
55+
#definePANIC23/* take down the other backends with me */
5656

5757

5858
/* macros for representing SQLSTATE strings compactly */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp