diff options
author | Bruce Momjian <bruce@momjian.us> | 2003-06-11 18:01:14 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2003-06-11 18:01:14 +0000 |
commit | b952d61c545e6c5fd827187a3ec6b9871cc0ebed (patch) | |
tree | 76abb87b20311471c937ee6b57eccc719b373166 /src/backend/tcop/postgres.c | |
parent | 8bfe93c5c8b10c9a824fd07138c55d3a857f4e98 (diff) | |
download | postgresql-b952d61c545e6c5fd827187a3ec6b9871cc0ebed.tar.gz postgresql-b952d61c545e6c5fd827187a3ec6b9871cc0ebed.zip |
Add log_min_duration_statement.
Christopher Kings-Lynne
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 6fa751640d5..96f3ca00e69 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * 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 @@ -663,6 +663,7 @@ exec_simple_query(const char *query_string) 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; /* @@ -673,11 +674,12 @@ exec_simple_query(const char *query_string) 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) @@ -915,19 +917,38 @@ exec_simple_query(const char *query_string) 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) @@ -2526,7 +2547,7 @@ PostgresMain(int argc, char *argv[], const char *username) 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"); } /* |