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

Commit61c3e5b

Browse files
committed
Make log_min_error_statement put LOG level at the same priority as
log_min_messages does; and arrange to suppress the duplicative outputthat would otherwise result from log_statement and log_duration messages.Bruce Momjian and Tom Lane.
1 parent1a7f630 commit61c3e5b

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.112 2007/02/16 16:37:29 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.113 2007/03/02 23:37:22 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -2507,9 +2507,10 @@ SELECT * FROM parent WHERE key = 2400;
25072507
<literal>DEBUG2</literal>, <literal>DEBUG1</literal>,
25082508
<literal>INFO</literal>, <literal>NOTICE</literal>,
25092509
<literal>WARNING</literal>, <literal>ERROR</literal>,
2510+
<literal>LOG</literal>,
25102511
<literal>FATAL</literal>, and <literal>PANIC</literal>.
25112512
The default is <literal>ERROR</literal>, which means statements
2512-
causing errors, fatal errors, or panics will be logged.
2513+
causing errors,log messages,fatal errors, or panics will be logged.
25132514
To effectively turn off logging of failing statements,
25142515
set this parameter to <literal>PANIC</literal>.
25152516
Only superusers can change this setting.

‎doc/src/sgml/sources.sgml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/sources.sgml,v 2.27 2007/02/01 22:06:14 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/sources.sgml,v 2.28 2007/03/02 23:37:22 tgl Exp $ -->
22

33
<chapter id="source">
44
<title>PostgreSQL Coding Conventions</title>
@@ -206,6 +206,14 @@ ereport(ERROR,
206206
socket-related system call.
207207
</para>
208208
</listitem>
209+
<listitem>
210+
<para>
211+
<function>errhidestmt(bool hide_stmt)</function> can be called to specify
212+
suppression of the <literal>STATEMENT:</> portion of a message in the
213+
postmaster log. Generally this is appropriate if the message text
214+
includes the current statement already.
215+
</para>
216+
</listitem>
209217
</itemizedlist>
210218
</para>
211219

‎src/backend/tcop/postgres.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.525 2007/02/20 17:32:16 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.526 2007/03/02 23:37:22 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -823,6 +823,7 @@ exec_simple_query(const char *query_string)
823823
{
824824
ereport(LOG,
825825
(errmsg("statement: %s",query_string),
826+
errhidestmt(true),
826827
errdetail_execute(parsetree_list)));
827828
was_logged= true;
828829
}
@@ -1020,12 +1021,14 @@ exec_simple_query(const char *query_string)
10201021
{
10211022
case1:
10221023
ereport(LOG,
1023-
(errmsg("duration: %s ms",msec_str)));
1024+
(errmsg("duration: %s ms",msec_str),
1025+
errhidestmt(true)));
10241026
break;
10251027
case2:
10261028
ereport(LOG,
10271029
(errmsg("duration: %s ms statement: %s",
10281030
msec_str,query_string),
1031+
errhidestmt(true),
10291032
errdetail_execute(parsetree_list)));
10301033
break;
10311034
}
@@ -1281,14 +1284,16 @@ exec_parse_message(const char *query_string,/* string to execute */
12811284
{
12821285
case1:
12831286
ereport(LOG,
1284-
(errmsg("duration: %s ms",msec_str)));
1287+
(errmsg("duration: %s ms",msec_str),
1288+
errhidestmt(true)));
12851289
break;
12861290
case2:
12871291
ereport(LOG,
12881292
(errmsg("duration: %s ms parse %s: %s",
12891293
msec_str,
12901294
*stmt_name ?stmt_name :"<unnamed>",
1291-
query_string)));
1295+
query_string),
1296+
errhidestmt(true)));
12921297
break;
12931298
}
12941299

@@ -1635,7 +1640,8 @@ exec_bind_message(StringInfo input_message)
16351640
{
16361641
case1:
16371642
ereport(LOG,
1638-
(errmsg("duration: %s ms",msec_str)));
1643+
(errmsg("duration: %s ms",msec_str),
1644+
errhidestmt(true)));
16391645
break;
16401646
case2:
16411647
ereport(LOG,
@@ -1645,6 +1651,7 @@ exec_bind_message(StringInfo input_message)
16451651
*portal_name ?"/" :"",
16461652
*portal_name ?portal_name :"",
16471653
pstmt->query_string ?pstmt->query_string :"<source not stored>"),
1654+
errhidestmt(true),
16481655
errdetail_params(params)));
16491656
break;
16501657
}
@@ -1778,6 +1785,7 @@ exec_execute_message(const char *portal_name, long max_rows)
17781785
*portal_name ?portal_name :"",
17791786
sourceText ?": " :"",
17801787
sourceText ?sourceText :""),
1788+
errhidestmt(true),
17811789
errdetail_params(portalParams)));
17821790
was_logged= true;
17831791
}
@@ -1846,7 +1854,8 @@ exec_execute_message(const char *portal_name, long max_rows)
18461854
{
18471855
case1:
18481856
ereport(LOG,
1849-
(errmsg("duration: %s ms",msec_str)));
1857+
(errmsg("duration: %s ms",msec_str),
1858+
errhidestmt(true)));
18501859
break;
18511860
case2:
18521861
ereport(LOG,
@@ -1860,6 +1869,7 @@ exec_execute_message(const char *portal_name, long max_rows)
18601869
*portal_name ?portal_name :"",
18611870
sourceText ?": " :"",
18621871
sourceText ?sourceText :""),
1872+
errhidestmt(true),
18631873
errdetail_params(portalParams)));
18641874
break;
18651875
}

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.182 2007/02/11 11:59:26 mha Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.183 2007/03/02 23:37:23 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -731,6 +731,25 @@ errcontext(const char *fmt,...)
731731
}
732732

733733

734+
/*
735+
* errhidestmt --- optionally suppress STATEMENT: field of log entry
736+
*
737+
* This should be called if the message text already includes the statement.
738+
*/
739+
int
740+
errhidestmt(boolhide_stmt)
741+
{
742+
ErrorData*edata=&errordata[errordata_stack_depth];
743+
744+
/* we don't bother incrementing recursion_depth */
745+
CHECK_STACK_DEPTH();
746+
747+
edata->hide_stmt=hide_stmt;
748+
749+
return0;/* return value does not matter */
750+
}
751+
752+
734753
/*
735754
* errfunction --- add reporting function name to the current error
736755
*
@@ -1629,7 +1648,9 @@ send_message_to_server_log(ErrorData *edata)
16291648
/*
16301649
* If the user wants the query that generated this error logged, do it.
16311650
*/
1632-
if (edata->elevel >=log_min_error_statement&&debug_query_string!=NULL)
1651+
if (is_log_level_output(edata->elevel,log_min_error_statement)&&
1652+
debug_query_string!=NULL&&
1653+
!edata->hide_stmt)
16331654
{
16341655
log_line_prefix(&buf);
16351656
appendStringInfoString(&buf,_("STATEMENT: "));
@@ -2046,7 +2067,7 @@ write_stderr(const char *fmt,...)
20462067

20472068
vsnprintf(errbuf,sizeof(errbuf),fmt,ap);
20482069

2049-
write_eventlog(EVENTLOG_ERROR_TYPE,errbuf);
2070+
write_eventlog(ERROR,errbuf);
20502071
}
20512072
else
20522073
/* Not running as service, write to stderr */
@@ -2055,13 +2076,18 @@ write_stderr(const char *fmt,...)
20552076
va_end(ap);
20562077
}
20572078

2079+
2080+
/*
2081+
* is_log_level_output -- is elevel logically >= log_min_level?
2082+
*
2083+
* We use this for tests that should consider LOG to sort out-of-order,
2084+
* between ERROR and FATAL. Generally this is the right thing for testing
2085+
* whether a message should go to the postmaster log, whereas a simple >=
2086+
* test is correct for testing whether the message should go to the client.
2087+
*/
20582088
staticbool
20592089
is_log_level_output(intelevel,intlog_min_level)
20602090
{
2061-
/*
2062-
*Complicated because LOG is sorted out-of-order here, between
2063-
*ERROR and FATAL.
2064-
*/
20652091
if (elevel==LOG||elevel==COMMERROR)
20662092
{
20672093
if (log_min_level==LOG||log_min_level <=ERROR)

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262

263263
# - When to Log -
264264

265-
#client_min_messages = notice# Values, in order of decreasing detail:
265+
#client_min_messages = notice# Values in order of decreasing detail:
266266
# debug5
267267
# debug4
268268
# debug3
@@ -273,7 +273,7 @@
273273
# warning
274274
# error
275275

276-
#log_min_messages = notice# Values, in order of decreasing detail:
276+
#log_min_messages = notice# Values in order of decreasing detail:
277277
# debug5
278278
# debug4
279279
# debug3
@@ -289,7 +289,7 @@
289289

290290
#log_error_verbosity = default# terse, default, or verbose messages
291291

292-
#log_min_error_statement = error# Values in order ofincreasing severity:
292+
#log_min_error_statement = error# Values in order ofdecreasing detail:
293293
# debug5
294294
# debug4
295295
# debug3
@@ -299,11 +299,14 @@
299299
# notice
300300
# warning
301301
# error
302+
# log
302303
# fatal
303304
# panic (effectively off)
304305

305306
#log_min_duration_statement = -1# -1 is disabled, 0 logs all statements
306-
# and their durations.
307+
# and their durations, > 0 logs only
308+
# statements running at least N msec.
309+
307310

308311
#silent_mode = off# DO NOT USE without syslog or
309312
# redirect_stderr

‎src/include/utils/elog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.83 2007/01/05 22:19:59 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.84 2007/03/02 23:37:23 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -137,6 +137,8 @@ errcontext(const char *fmt,...)
137137
the supplied arguments. */
138138
__attribute__((format(printf,1,2)));
139139

140+
externinterrhidestmt(boolhide_stmt);
141+
140142
externinterrfunction(constchar*funcname);
141143
externinterrposition(intcursorpos);
142144

@@ -240,6 +242,7 @@ typedef struct ErrorData
240242
booloutput_to_server;/* will report to server log? */
241243
booloutput_to_client;/* will report to client? */
242244
boolshow_funcname;/* true to force funcname inclusion */
245+
boolhide_stmt;/* true to prevent STATEMENT: inclusion */
243246
constchar*filename;/* __FILE__ of ereport() call */
244247
intlineno;/* __LINE__ of ereport() call */
245248
constchar*funcname;/* __func__ of ereport() call */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp