-
+
Server Configuration
Only superusers can change this setting.
- For clients using extended query protocol, durations of the Parse,
- Bind, and Execute steps are logged independently.
-
+ For clients using extended query protocol, durations of the Parse,
+ Bind, and Execute steps are logged independently.
+
- When using this option together with
- ,
- the text of statements that are logged because of
- log_statement> will not be repeated in the
- duration log message.
- If you are not using
syslog>, it is recommended
- that you log the PID or session ID using
-
- so that you can link the statement message to the later
- duration message using the process ID or session ID.
+ The difference between setting this option and setting
+ to zero is that
+ exceeding log_min_duration_statement> forces the text of
+ the query to be logged, but this option doesn't. Thus, if
+ log_duration> is on> and
+ log_min_duration_statement> has a positive value, all
+ durations are logged but the query text is included only for
+ statements exceeding the threshold. This behavior can be useful for
+ gathering statistics in high-load installations.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.91 2006/07/14 14:52:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.92 2006/09/08 15:55:53 tgl Exp $
*
* NOTES
* This cruft is the server side of PQfn.
struct fp_info my_fp;
struct fp_info *fip;
bool callit;
+ bool was_logged = false;
+ char msec_str[32];
/*
* Read message contents if not already done.
fid = (Oid) pq_getmsgint(msgBuf, 4); /* function oid */
+ /* Log as soon as we have the function OID */
if (log_statement == LOGSTMT_ALL)
+ {
ereport(LOG,
(errmsg("fastpath function call: function OID %u",
fid)));
+ was_logged = true;
+ }
/*
* There used to be a lame attempt at caching lookup info here. Now we
SendFunctionResult(retval, fcinfo.isnull, fip->rettype, rformat);
+ /*
+ * Emit duration logging if appropriate.
+ */
+ switch (check_log_duration(msec_str, was_logged))
+ {
+ case 1:
+ ereport(LOG,
+ (errmsg("duration: %s ms", msec_str)));
+ break;
+ case 2:
+ ereport(LOG,
+ (errmsg("duration: %s ms fastpath function call: function OID %u",
+ msec_str, fid)));
+ break;
+ }
+
return 0;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.507 2006/09/07 22:52:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.508 2006/09/08 15:55:53 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
static List *pg_rewrite_queries(List *querytree_list);
static bool check_log_statement_raw(List *raw_parsetree_list);
static bool check_log_statement_cooked(List *parsetree_list);
-static bool check_log_duration(char *msec_str);
static int errdetail_execute(List *raw_parsetree_list);
static int errdetail_params(ParamListInfo params);
static void start_xact_command(void);
/*
* Emit duration logging if appropriate.
*/
- if (check_log_duration(msec_str ))
+ switch (check_log_duration(msec_str, was_logged ))
{
- if (was_logged)
+ case 1:
ereport(LOG,
(errmsg("duration: %s ms", msec_str)));
- else
+ break;
+ case 2:
ereport(LOG,
(errmsg("duration: %s ms statement: %s",
msec_str, query_string),
errdetail_execute(parsetree_list)));
+ break;
}
if (save_log_statement_stats)
/*
* Emit duration logging if appropriate.
*/
- if (check_log_duration(msec_str))
- ereport(LOG,
- (errmsg("duration: %s ms parse %s: %s",
- msec_str,
- *stmt_name ? stmt_name : "",
- query_string)));
+ switch (check_log_duration(msec_str, false))
+ {
+ case 1:
+ ereport(LOG,
+ (errmsg("duration: %s ms", msec_str)));
+ break;
+ case 2:
+ ereport(LOG,
+ (errmsg("duration: %s ms parse %s: %s",
+ msec_str,
+ *stmt_name ? stmt_name : "",
+ query_string)));
+ break;
+ }
if (save_log_statement_stats)
ShowUsage("PARSE MESSAGE STATISTICS");
/*
* Emit duration logging if appropriate.
*/
- if (check_log_duration(msec_str))
- ereport(LOG,
- (errmsg("duration: %s ms bind %s to %s: %s",
- msec_str,
- *portal_name ? portal_name : "",
- *stmt_name ? stmt_name : "",
- pstmt->query_string ? pstmt->query_string : ""),
- errdetail_params(params)));
+ switch (check_log_duration(msec_str, false))
+ {
+ case 1:
+ ereport(LOG,
+ (errmsg("duration: %s ms", msec_str)));
+ break;
+ case 2:
+ ereport(LOG,
+ (errmsg("duration: %s ms bind %s to %s: %s",
+ msec_str,
+ *portal_name ? portal_name : "",
+ *stmt_name ? stmt_name : "",
+ pstmt->query_string ? pstmt->query_string : ""),
+ errdetail_params(params)));
+ break;
+ }
if (save_log_statement_stats)
ShowUsage("BIND MESSAGE STATISTICS");
/*
* Emit duration logging if appropriate.
*/
- if (check_log_duration(msec_str ))
+ switch (check_log_duration(msec_str, was_logged ))
{
- if (was_logged)
+ case 1:
ereport(LOG,
(errmsg("duration: %s ms", msec_str)));
- else
+ break;
+ case 2:
ereport(LOG,
(errmsg("duration: %s ms %s %s%s%s%s%s",
msec_str,
sourceText ? ": " : "",
sourceText ? sourceText : ""),
errdetail_params(portalParams)));
+ break;
}
if (save_log_statement_stats)
* check_log_duration
* Determine whether current command's duration should be logged
*
+ * Returns:
+ * 0 if no logging is needed
+ * 1 if just the duration should be logged
+ * 2 if duration and query details should be logged
+ *
* If logging is needed, the duration in msec is formatted into msec_str[],
* which must be a 32-byte buffer.
+ *
+ * was_logged should be TRUE if caller already logged query details (this
+ * essentially prevents 2 from being returned).
*/
-static bool
-check_log_duration(char *msec_str)
+int
+check_log_duration(char *msec_str, bool was_logged )
{
if (log_duration || log_min_duration_statement >= 0)
{
long secs;
int usecs;
int msecs;
+ bool exceeded;
TimestampDifference(GetCurrentStatementStartTimestamp(),
GetCurrentTimestamp(),
msecs = usecs / 1000;
/*
- * The odd-looking test for log_min_duration_statement being
+ * This odd-looking test for log_min_duration_statement being
* exceeded is designed to avoid integer overflow with very
* long durations: don't compute secs * 1000 until we've
* verified it will fit in int.
*/
- if (log_duration ||
- log_min_duration_statement == 0 ||
- (log_min_duration_statement > 0 &&
- (secs > log_min_duration_statement / 1000 ||
- secs * 1000 + msecs >= log_min_duration_statement)))
+ exceeded = (log_min_duration_statement == 0 ||
+ (log_min_duration_statement > 0 &&
+ (secs > log_min_duration_statement / 1000 ||
+ secs * 1000 + msecs >= log_min_duration_statement)));
+
+ if (exceeded || log_duration)
{
snprintf(msec_str, 32, "%ld.%03d",
secs * 1000 + msecs, usecs % 1000);
- return true;
+ if (exceeded && !was_logged)
+ return 2;
+ else
+ return 1;
}
}
- return false ;
+ return 0 ;
}
/*