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

Commita1ce88a

Browse files
committed
Have log_duration only output when log_statement has printed the query.
This handles the new multiple log_statement values.Ed L.
1 parentc96c02c commita1ce88a

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.287 2004/10/09 23:12:53 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.288 2004/10/15 16:50:29 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -2355,13 +2355,14 @@ archive_command = 'copy "%p" /mnt/server/archivedir/"%f"' # Win32
23552355
<term><varname>log_duration</varname> (<type>boolean</type>)</term>
23562356
<listitem>
23572357
<para>
2358-
Causes the duration of every completed statement to be logged.
2359-
To use this option, it is recommended that you also enable
2360-
<varname>log_statement</> and if not using <application>syslog</>
2361-
log the PID using <varname>log_line_prefix</> so that you
2362-
can link the statement to the duration using the process
2363-
ID. The default is off. Only superusers can turn off this
2364-
option if it is enabled by the administrator.
2358+
Causes the duration of every completed statement which satisfies
2359+
<varname>log_statement</> to be logged. When using this option,
2360+
if you are not using <application>syslog</>, it is recommended
2361+
that you log the PID or session ID using <varname>log_line_prefix</>
2362+
or log the session ID so that you can link the statement to the
2363+
duration using the process ID or session ID. The default is off.
2364+
Only superusers can turn off this option if it is enabled by the
2365+
administrator.
23652366
</para>
23662367
</listitem>
23672368
</varlistentry>

‎src/backend/tcop/postgres.c

Lines changed: 12 additions & 2 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.435 2004/10/12 21:54:40 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.436 2004/10/15 16:50:31 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -81,6 +81,9 @@ boolLog_disconnections = false;
8181

8282
LogStmtLevellog_statement=LOGSTMT_NONE;
8383

84+
/* flag indicating if the statement satisfies log_statement */
85+
boolstatement_logged;
86+
8487
/* GUC variable for maximum stack depth (measured in kilobytes) */
8588
intmax_stack_depth=2048;
8689

@@ -463,9 +466,13 @@ pg_parse_query(const char *query_string)
463466
List*raw_parsetree_list;
464467
ListCell*parsetree_item;
465468

469+
statement_logged= false;
466470
if (log_statement==LOGSTMT_ALL)
471+
{
467472
ereport(LOG,
468473
(errmsg("statement: %s",query_string)));
474+
statement_logged= true;
475+
}
469476

470477
if (log_parser_stats)
471478
ResetUsage();
@@ -501,6 +508,7 @@ pg_parse_query(const char *query_string)
501508
{
502509
ereport(LOG,
503510
(errmsg("statement: %s",query_string)));
511+
statement_logged= true;
504512
break;
505513
}
506514
commandTag=CreateCommandTag(parsetree);
@@ -512,6 +520,7 @@ pg_parse_query(const char *query_string)
512520
{
513521
ereport(LOG,
514522
(errmsg("statement: %s",query_string)));
523+
statement_logged= true;
515524
break;
516525
}
517526
}
@@ -1003,7 +1012,8 @@ exec_simple_query(const char *query_string)
10031012
}
10041013
usecs= (long) (stop_t.tv_sec-start_t.tv_sec)*1000000+ (long) (stop_t.tv_usec-start_t.tv_usec);
10051014

1006-
if (save_log_duration)
1015+
/* Only print duration if we previously printed the statement. */
1016+
if (statement_logged&&save_log_duration)
10071017
ereport(LOG,
10081018
(errmsg("duration: %ld.%03ld ms",
10091019
(long) ((stop_t.tv_sec-start_t.tv_sec)*1000+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp