<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.182 2003/05/27 17:49:45 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.183 2003/06/11 18:01:13 momjian Exp $
-->
<Chapter Id="runtime">
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>LOG_MIN_DURATION_STATEMENT</varname> (<type>integer</type>)</term>
+ <listitem>
+ <para>
+ Sets a minimum statement execution time (in milliseconds)
+ above which a statement will be logged. All SQL statements
+ that run longer than the time specified will be logged together
+ with the duration, in seconds. The default is <literal>0</literal>
+ (turning this feature off). For example, if you set it
+ to <literal>250</literal> then all SQL statements that run longer
+ than 250ms will be logged along with the duration. Enabling this
+ option can be useful in tracking down unoptimized queries in
+ your applications.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><varname>LOG_MIN_ERROR_STATEMENT</varname> (<type>string</type>)</term>
<listitem>
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.346 2003/05/27 17:49:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.347 2003/06/11 18:01:14 momjian Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
struct timeval start_t,
stop_t;
bool save_log_duration = log_duration;
+ int save_log_min_duration_statement = log_min_duration_statement;
bool save_log_statement_stats = log_statement_stats;
/*
pgstat_report_activity(query_string);
/*
- * We use save_log_duration so "SET log_duration = true" doesn't
- * report incorrect time because gettimeofday() wasn't called.
+ * We use save_log_* so "SET log_duration = true" and
+ * "SET log_min_duration_statement = true" don't report incorrect
+ * time because gettimeofday() wasn't called.
* Similarly, log_statement_stats has to be captured once.
*/
- if (save_log_duration)
+ if (save_log_duration || save_log_min_duration_statement > 0)
gettimeofday(&start_t, NULL);
if (save_log_statement_stats)
QueryContext = NULL;
/*
- * Finish up monitoring.
+ * Combine processing here as we need to calculate the query
+ * duration in both instances.
*/
- if (save_log_duration)
+ if (save_log_duration || save_log_min_duration_statement > 0)
{
+ long usecs;
gettimeofday(&stop_t, NULL);
if (stop_t.tv_usec < start_t.tv_usec)
{
stop_t.tv_sec--;
stop_t.tv_usec += 1000000;
}
- elog(LOG, "duration: %ld.%06ld sec",
- (long) (stop_t.tv_sec - start_t.tv_sec),
- (long) (stop_t.tv_usec - start_t.tv_usec));
+ usecs = (long) (stop_t.tv_sec - start_t.tv_sec) * 1000000 + (long) (stop_t.tv_usec - start_t.tv_usec);
+
+ /*
+ * Output a duration_query to the log if the query has exceeded the
+ * min duration.
+ */
+ if (usecs >= save_log_min_duration_statement * 1000)
+ elog(LOG, "duration_statement: %ld.%06ld %s",
+ (long) (stop_t.tv_sec - start_t.tv_sec),
+ (long) (stop_t.tv_usec - start_t.tv_usec),
+ query_string);
+
+ /*
+ * If the user is requesting logging of all durations, then log
+ * that as well.
+ */
+ if (save_log_duration)
+ elog(LOG, "duration: %ld.%06ld sec",
+ (long) (stop_t.tv_sec - start_t.tv_sec),
+ (long) (stop_t.tv_usec - start_t.tv_usec));
}
if (save_log_statement_stats)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.346 $ $Date: 2003/05/27 17:49:46 $\n");
+ puts("$Revision: 1.347 $ $Date: 2003/06/11 18:01:14 $\n");
}
/*
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.128 2003/06/11 05:04:51 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.129 2003/06/11 18:01:14 momjian Exp $
*
*--------------------------------------------------------------------
*/
#include "utils/pg_locale.h"
#include "pgstat.h"
+int log_min_duration_statement = 0;
+
#ifndef PG_KRB_SRVTAB
#define PG_KRB_SRVTAB ""
0, -15, 2, NULL, NULL
},
+ {
+ {"log_min_duration_statement", PGC_USERSET}, &log_min_duration_statement,
+ 0, 0, INT_MAX / 1000, NULL, NULL
+ },
+
{
{NULL, 0}, NULL, 0, 0, 0, NULL, NULL
}
# debug5, debug4, debug3, debug2, debug1,
# info, notice, warning, error, panic(off)
+#log_min_duration_statement = 0 # Log all statements whose
+ # execution time exceeds the value, in
+ # milliseconds. Zero disables.
+
#debug_print_parse = false
#debug_print_rewritten = false
#debug_print_plan = false
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.77 2003/05/14 03:26:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.78 2003/06/11 18:01:14 momjian Exp $
*/
/*----------------------------------------------------------------------
"lc_time",
"log_duration",
"log_executor_stats",
+ "log_min_duration_statement",
"log_min_error_statement",
"log_min_messages",
"log_parser_stats",
* Copyright 2000-2003 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
- * $Id: guc.h,v 1.31 2003/05/06 20:26:28 tgl Exp $
+ * $Id: guc.h,v 1.32 2003/06/11 18:01:14 momjian Exp $
*--------------------------------------------------------------------
*/
#ifndef GUC_H
void read_nondefault_variables(void);
#endif
+extern int log_min_duration_statement;
+
#endif /* GUC_H */