Commit 548d646e authored by Bruce Momjian's avatar Bruce Momjian

Add log_duration to GUC/postgresql.conf.

Rename debug_print_query to log_statement and rename show_query_stats to
show_statement_stats.
parent f4abdd82
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.118 2002/08/29 05:17:55 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.119 2002/09/01 23:26:05 momjian Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -5241,7 +5241,7 @@ select current_setting('DateStyle'); ...@@ -5241,7 +5241,7 @@ select current_setting('DateStyle');
<literal>false</literal> instead. It is the equivalent to the SQL <literal>false</literal> instead. It is the equivalent to the SQL
<command>SET</command> command. For example: <command>SET</command> command. For example:
<programlisting> <programlisting>
select set_config('show_query_stats','off','f'); select set_config('show_statement_stats','off','f');
set_config set_config
------------ ------------
off off
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.131 2002/08/30 22:18:05 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.132 2002/09/01 23:26:06 momjian Exp $
--> -->
<Chapter Id="runtime"> <Chapter Id="runtime">
...@@ -928,7 +928,6 @@ env PGOPTIONS='-c geqo=off' psql ...@@ -928,7 +928,6 @@ env PGOPTIONS='-c geqo=off' psql
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>DEBUG_PRINT_QUERY</varname> (<type>boolean</type>)</term>
<term><varname>DEBUG_PRINT_PARSE</varname> (<type>boolean</type>)</term> <term><varname>DEBUG_PRINT_PARSE</varname> (<type>boolean</type>)</term>
<term><varname>DEBUG_PRINT_REWRITTEN</varname> (<type>boolean</type>)</term> <term><varname>DEBUG_PRINT_REWRITTEN</varname> (<type>boolean</type>)</term>
<term><varname>DEBUG_PRINT_PLAN</varname> (<type>boolean</type>)</term> <term><varname>DEBUG_PRINT_PLAN</varname> (<type>boolean</type>)</term>
...@@ -992,6 +991,26 @@ env PGOPTIONS='-c geqo=off' psql ...@@ -992,6 +991,26 @@ env PGOPTIONS='-c geqo=off' psql
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>LOG_STATEMENT</varname> (<type>boolean</type>)</term>
<listitem>
<para>
Prints each query received.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>LOG_DURATION</varname> (<type>boolean</type>)</term>
<listitem>
<para>
Prints the duration of every completed query. To use this option,
enable LOG_STATEMENT and LOG_PID so you can link the original query
to the duration using the process id.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>LOG_TIMESTAMP</varname> (<type>boolean</type>)</term> <term><varname>LOG_TIMESTAMP</varname> (<type>boolean</type>)</term>
<listitem> <listitem>
...@@ -1003,7 +1022,7 @@ env PGOPTIONS='-c geqo=off' psql ...@@ -1003,7 +1022,7 @@ env PGOPTIONS='-c geqo=off' psql
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>SHOW_QUERY_STATS</varname> (<type>boolean</type>)</term> <term><varname>SHOW_STATEMENT_STATS</varname> (<type>boolean</type>)</term>
<term><varname>SHOW_PARSER_STATS</varname> (<type>boolean</type>)</term> <term><varname>SHOW_PARSER_STATS</varname> (<type>boolean</type>)</term>
<term><varname>SHOW_PLANNER_STATS</varname> (<type>boolean</type>)</term> <term><varname>SHOW_PLANNER_STATS</varname> (<type>boolean</type>)</term>
<term><varname>SHOW_EXECUTOR_STATS</varname> (<type>boolean</type>)</term> <term><varname>SHOW_EXECUTOR_STATS</varname> (<type>boolean</type>)</term>
...@@ -2072,7 +2091,7 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir' ...@@ -2072,7 +2091,7 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
</row> </row>
<row> <row>
<entry><option>-s</option></entry> <entry><option>-s</option></entry>
<entry><literal>show_query_stats = on</></entry> <entry><literal>show_statement_stats = on</></entry>
<entry>*</entry> <entry>*</entry>
</row> </row>
<row> <row>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.287 2002/08/30 22:18:06 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.288 2002/09/01 23:26:06 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -220,7 +220,7 @@ InteractiveBackend(StringInfo inBuf) ...@@ -220,7 +220,7 @@ InteractiveBackend(StringInfo inBuf)
* if the query echo flag was given, print the query.. * if the query echo flag was given, print the query..
*/ */
if (EchoQuery) if (EchoQuery)
printf("query: %s\n", inBuf->data); printf("statement: %s\n", inBuf->data);
fflush(stdout); fflush(stdout);
return 'Q'; return 'Q';
...@@ -372,7 +372,7 @@ pg_parse_query(StringInfo query_string, Oid *typev, int nargs) ...@@ -372,7 +372,7 @@ pg_parse_query(StringInfo query_string, Oid *typev, int nargs)
{ {
List *raw_parsetree_list; List *raw_parsetree_list;
if (Debug_print_query) if (Log_statement)
elog(LOG, "query: %s", query_string->data); elog(LOG, "query: %s", query_string->data);
if (Show_parser_stats) if (Show_parser_stats)
...@@ -561,9 +561,19 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */ ...@@ -561,9 +561,19 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
MemoryContext oldcontext; MemoryContext oldcontext;
List *parsetree_list, List *parsetree_list,
*parsetree_item; *parsetree_item;
struct timezone tz;
struct timeval start_t, stop_t;
bool save_Log_duration = Log_duration;
debug_query_string = query_string->data; /* used by pgmonitor */ debug_query_string = query_string->data; /* used by pgmonitor */
/*
* We use save_Log_duration so setting Log_duration to true doesn't
* report incorrect time because gettimeofday() wasn't called.
*/
if (save_Log_duration)
gettimeofday(&start_t, &tz);
/* /*
* Start up a transaction command. All queries generated by the * Start up a transaction command. All queries generated by the
* query_string will be in this same command block, *unless* we find a * query_string will be in this same command block, *unless* we find a
...@@ -850,6 +860,19 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */ ...@@ -850,6 +860,19 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
if (xact_started) if (xact_started)
finish_xact_command(); finish_xact_command();
if (save_Log_duration)
{
gettimeofday(&stop_t, &tz);
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 int) stop_t.tv_sec - start_t.tv_sec,
(long int) stop_t.tv_usec - start_t.tv_usec);
}
debug_query_string = NULL; /* used by pgmonitor */ debug_query_string = NULL; /* used by pgmonitor */
} }
...@@ -1234,7 +1257,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1234,7 +1257,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (atoi(optarg) >= 1) if (atoi(optarg) >= 1)
SetConfigOption("log_connections", "true", ctx, gucsource); SetConfigOption("log_connections", "true", ctx, gucsource);
if (atoi(optarg) >= 2) if (atoi(optarg) >= 2)
SetConfigOption("debug_print_query", "true", ctx, gucsource); SetConfigOption("log_statement", "true", ctx, gucsource);
if (atoi(optarg) >= 3) if (atoi(optarg) >= 3)
SetConfigOption("debug_print_parse", "true", ctx, gucsource); SetConfigOption("debug_print_parse", "true", ctx, gucsource);
if (atoi(optarg) >= 4) if (atoi(optarg) >= 4)
...@@ -1377,7 +1400,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1377,7 +1400,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/* /*
* s - report usage statistics (timings) after each query * s - report usage statistics (timings) after each query
*/ */
SetConfigOption("show_query_stats", "true", ctx, gucsource); SetConfigOption("show_statement_stats", "true", ctx, gucsource);
break; break;
case 't': case 't':
...@@ -1489,11 +1512,11 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1489,11 +1512,11 @@ PostgresMain(int argc, char *argv[], const char *username)
/* /*
* Post-processing for command line options. * Post-processing for command line options.
*/ */
if (Show_query_stats && if (Show_statement_stats &&
(Show_parser_stats || Show_planner_stats || Show_executor_stats)) (Show_parser_stats || Show_planner_stats || Show_executor_stats))
{ {
elog(WARNING, "Query statistics are disabled because parser, planner, or executor statistics are on."); elog(WARNING, "Query statistics are disabled because parser, planner, or executor statistics are on.");
SetConfigOption("show_query_stats", "false", ctx, gucsource); SetConfigOption("show_statement_stats", "false", ctx, gucsource);
} }
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
...@@ -1664,7 +1687,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1664,7 +1687,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.287 $ $Date: 2002/08/30 22:18:06 $\n"); puts("$Revision: 1.288 $ $Date: 2002/09/01 23:26:06 $\n");
} }
/* /*
...@@ -1887,7 +1910,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1887,7 +1910,7 @@ PostgresMain(int argc, char *argv[], const char *username)
* Note: transaction command start/end is now done within * Note: transaction command start/end is now done within
* pg_exec_query_string(), not here. * pg_exec_query_string(), not here.
*/ */
if (Show_query_stats) if (Show_statement_stats)
ResetUsage(); ResetUsage();
pgstat_report_activity(parser_input->data); pgstat_report_activity(parser_input->data);
...@@ -1896,7 +1919,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1896,7 +1919,7 @@ PostgresMain(int argc, char *argv[], const char *username)
whereToSendOutput, whereToSendOutput,
QueryContext); QueryContext);
if (Show_query_stats) if (Show_statement_stats)
ShowUsage("QUERY STATISTICS"); ShowUsage("QUERY STATISTICS");
} }
break; break;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* command, configuration file, and command line options. * command, configuration file, and command line options.
* See src/backend/utils/misc/README for more information. * See src/backend/utils/misc/README for more information.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.89 2002/08/30 22:18:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.90 2002/09/01 23:26:06 momjian Exp $
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
...@@ -77,7 +77,8 @@ static const char *assign_facility(const char *facility, ...@@ -77,7 +77,8 @@ static const char *assign_facility(const char *facility,
#ifdef USE_ASSERT_CHECKING #ifdef USE_ASSERT_CHECKING
bool assert_enabled = true; bool assert_enabled = true;
#endif #endif
bool Debug_print_query = false; bool Log_statement = false;
bool Log_duration = false;
bool Debug_print_plan = false; bool Debug_print_plan = false;
bool Debug_print_parse = false; bool Debug_print_parse = false;
bool Debug_print_rewritten = false; bool Debug_print_rewritten = false;
...@@ -86,7 +87,7 @@ bool Debug_pretty_print = false; ...@@ -86,7 +87,7 @@ bool Debug_pretty_print = false;
bool Show_parser_stats = false; bool Show_parser_stats = false;
bool Show_planner_stats = false; bool Show_planner_stats = false;
bool Show_executor_stats = false; bool Show_executor_stats = false;
bool Show_query_stats = false; /* this is sort of all three above bool Show_statement_stats = false; /* this is sort of all three above
* together */ * together */
bool Show_btree_build_stats = false; bool Show_btree_build_stats = false;
...@@ -362,7 +363,11 @@ static struct config_bool ...@@ -362,7 +363,11 @@ static struct config_bool
#endif #endif
{ {
{ "debug_print_query", PGC_USERSET }, &Debug_print_query, { "log_statement", PGC_USERSET }, &Log_statement,
false, NULL, NULL
},
{
{ "log_duration", PGC_USERSET }, &Log_duration,
false, NULL, NULL false, NULL, NULL
}, },
{ {
...@@ -395,7 +400,7 @@ static struct config_bool ...@@ -395,7 +400,7 @@ static struct config_bool
false, NULL, NULL false, NULL, NULL
}, },
{ {
{ "show_query_stats", PGC_USERSET }, &Show_query_stats, { "show_statement_stats", PGC_USERSET }, &Show_statement_stats,
false, NULL, NULL false, NULL, NULL
}, },
#ifdef BTREE_BUILD_STATS #ifdef BTREE_BUILD_STATS
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
#geqo = true #geqo = true
#geqo_selection_bias = 2.0 # range 1.5-2.0 #geqo_selection_bias = 2.0 # range 1.5-2.0
#geqo_threshold = 11 #geqo_threshold = 11
#geqo_pool_size = 0 # default based on tables in query, #geqo_pool_size = 0 # default based on tables in statement,
# range 128-1024 # range 128-1024
#geqo_effort = 1 #geqo_effort = 1
#geqo_generations = 0 #geqo_generations = 0
...@@ -122,10 +122,11 @@ ...@@ -122,10 +122,11 @@
#silent_mode = false #silent_mode = false
#log_connections = false #log_connections = false
#log_timestamp = false
#log_pid = false #log_pid = false
#log_statement = false
#log_duration = false
#log_timestamp = false
#debug_print_query = false
#debug_print_parse = false #debug_print_parse = false
#debug_print_rewritten = false #debug_print_rewritten = false
#debug_print_plan = false #debug_print_plan = false
...@@ -151,7 +152,7 @@ ...@@ -151,7 +152,7 @@
#show_parser_stats = false #show_parser_stats = false
#show_planner_stats = false #show_planner_stats = false
#show_executor_stats = false #show_executor_stats = false
#show_query_stats = false #show_statement_stats = false
# requires BTREE_BUILD_STATS # requires BTREE_BUILD_STATS
#show_btree_build_stats = false #show_btree_build_stats = false
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000-2002 by PostgreSQL Global Development Group * Copyright 2000-2002 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.60 2002/08/30 22:18:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.61 2002/09/01 23:26:06 momjian Exp $
*/ */
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
...@@ -231,7 +231,8 @@ psql_completion(char *text, int start, int end) ...@@ -231,7 +231,8 @@ psql_completion(char *text, int start, int end)
"server_min_messages", "server_min_messages",
"client_min_messages", "client_min_messages",
"debug_assertions", "debug_assertions",
"debug_print_query", "log_statement",
"log_duration",
"debug_print_parse", "debug_print_parse",
"debug_print_rewritten", "debug_print_rewritten",
"debug_print_plan", "debug_print_plan",
...@@ -239,7 +240,7 @@ psql_completion(char *text, int start, int end) ...@@ -239,7 +240,7 @@ psql_completion(char *text, int start, int end)
"show_parser_stats", "show_parser_stats",
"show_planner_stats", "show_planner_stats",
"show_executor_stats", "show_executor_stats",
"show_query_stats", "show_statement_stats",
"trace_notify", "trace_notify",
"explain_pretty_print", "explain_pretty_print",
"sql_inheritance", "sql_inheritance",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* External declarations pertaining to backend/utils/misc/guc.c and * External declarations pertaining to backend/utils/misc/guc.c and
* backend/utils/misc/guc-file.l * backend/utils/misc/guc-file.l
* *
* $Id: guc.h,v 1.20 2002/07/30 16:20:03 momjian Exp $ * $Id: guc.h,v 1.21 2002/09/01 23:26:06 momjian Exp $
*/ */
#ifndef GUC_H #ifndef GUC_H
#define GUC_H #define GUC_H
...@@ -100,7 +100,8 @@ extern void ProcessGUCArray(ArrayType *array, GucSource source); ...@@ -100,7 +100,8 @@ extern void ProcessGUCArray(ArrayType *array, GucSource source);
extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value); extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name); extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
extern bool Debug_print_query; extern bool Log_statement;
extern bool Log_duration;
extern bool Debug_print_plan; extern bool Debug_print_plan;
extern bool Debug_print_parse; extern bool Debug_print_parse;
extern bool Debug_print_rewritten; extern bool Debug_print_rewritten;
...@@ -109,7 +110,7 @@ extern bool Debug_pretty_print; ...@@ -109,7 +110,7 @@ extern bool Debug_pretty_print;
extern bool Show_parser_stats; extern bool Show_parser_stats;
extern bool Show_planner_stats; extern bool Show_planner_stats;
extern bool Show_executor_stats; extern bool Show_executor_stats;
extern bool Show_query_stats; extern bool Show_statement_stats;
extern bool Show_btree_build_stats; extern bool Show_btree_build_stats;
extern bool Explain_pretty_print; extern bool Explain_pretty_print;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment