<!--
-$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.287 2004/10/09 23:12:53 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.288 2004/10/15 16:50:29 momjian Exp $
-->
<Chapter Id="runtime">
<term><varname>log_duration</varname> (<type>boolean</type>)</term>
<listitem>
<para>
- Causes the duration of every completed statement to be logged.
- To use this option, it is recommended that you also enable
- <varname>log_statement</> and if not using <application>syslog</>
- log the PID using <varname>log_line_prefix</> so that you
- can link the statement to the duration using the process
- ID. The default is off. Only superusers can turn off this
- option if it is enabled by the administrator.
+ Causes the duration of every completed statement which satisfies
+ <varname>log_statement</> to be logged. When using this option,
+ if you are not using <application>syslog</>, it is recommended
+ that you log the PID or session ID using <varname>log_line_prefix</>
+ or log the session ID so that you can link the statement to the
+ duration using the process ID or session ID. The default is off.
+ Only superusers can turn off this option if it is enabled by the
+ administrator.
</para>
</listitem>
</varlistentry>
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.435 2004/10/12 21:54:40 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.436 2004/10/15 16:50:31 momjian Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
LogStmtLevel log_statement = LOGSTMT_NONE;
+/* flag indicating if the statement satisfies log_statement */
+bool statement_logged;
+
/* GUC variable for maximum stack depth (measured in kilobytes) */
int max_stack_depth = 2048;
List *raw_parsetree_list;
ListCell *parsetree_item;
+ statement_logged = false;
if (log_statement == LOGSTMT_ALL)
+ {
ereport(LOG,
(errmsg("statement: %s", query_string)));
+ statement_logged = true;
+ }
if (log_parser_stats)
ResetUsage();
{
ereport(LOG,
(errmsg("statement: %s", query_string)));
+ statement_logged = true;
break;
}
commandTag = CreateCommandTag(parsetree);
{
ereport(LOG,
(errmsg("statement: %s", query_string)));
+ statement_logged = true;
break;
}
}
}
usecs = (long) (stop_t.tv_sec - start_t.tv_sec) * 1000000 + (long) (stop_t.tv_usec - start_t.tv_usec);
- if (save_log_duration)
+ /* Only print duration if we previously printed the statement. */
+ if (statement_logged && save_log_duration)
ereport(LOG,
(errmsg("duration: %ld.%03ld ms",
(long) ((stop_t.tv_sec - start_t.tv_sec) * 1000 +