The attached patch forces queryless duration log statements to be turned off in step with the log_statement directive. Without this patch, and with log_statement = 'mod' and log_duration = true, there is no way to silence SELECT query duration logging when quieting the logging of SELECT queries.
Note this patch changes the semantics of log_duration from logging the duration of "every completed statement" to "every completed statement that satisfies log_statement directive". I argue this semantic change is justified given 1) the docs themselves recommend turning log_statement sufficiently up to be able to make this mapping, and 2) I can see it being quite common that folks only want to log queries (and durations) that change the database, while I fail to see the usefulness of queryless durations (and I'm trying to scratch my own itch with a small effort). It's possible someone else feels strongly about their queryless durations for reasons I cannot imagine. If so, then another more conservative approach may be in order. Note also this patch is independent of queries and durations logged due to the log_min_duration_statement directive. If, for example, log_statement = 'all', log_min_duration_statement = 1 (ms), and a SELECT query takes longer than 1ms, it's duration will be logged twice, with the 2nd log entry including the statement with the duration. Ed
Index: doc/src/sgml/runtime.sgml =================================================================== RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v retrieving revision 1.284 diff -C1 -r1.284 runtime.sgml *** doc/src/sgml/runtime.sgml 26 Sep 2004 22:51:49 -0000 1.284 --- doc/src/sgml/runtime.sgml 28 Sep 2004 02:19:16 -0000 *************** *** 2305,2313 **** <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. </para> --- 2305,2314 ---- <para> ! Causes the duration of every completed statement which satisfies ! <varname>log_statement</> directive 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> Index: src/backend/tcop/postgres.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/tcop/postgres.c,v retrieving revision 1.433 diff -C1 -r1.433 postgres.c *** src/backend/tcop/postgres.c 26 Sep 2004 00:26:25 -0000 1.433 --- src/backend/tcop/postgres.c 28 Sep 2004 02:19:19 -0000 *************** *** 83,84 **** --- 83,87 ---- + /* flag noting if the statement satisfies log_statement directive */ + bool loggable_statement; + /* GUC variable for maximum stack depth (measured in kilobytes) */ *************** *** 465,469 **** --- 468,476 ---- + loggable_statement = false; if (log_statement == LOGSTMT_ALL) + { ereport(LOG, (errmsg("statement: %s", query_string))); + loggable_statement = true; + } *************** *** 503,504 **** --- 510,512 ---- (errmsg("statement: %s", query_string))); + loggable_statement = true; break; *************** *** 514,515 **** --- 522,524 ---- (errmsg("statement: %s", query_string))); + loggable_statement = true; break; *************** *** 1005,1007 **** ! if (save_log_duration) ereport(LOG, --- 1014,1023 ---- ! /* ! * If log_duration = true, don't log duration unless statement ! * statement also satifies log_statement directive. Otherwise, ! * the duration statements are devoid of context without their ! * query having been logged. Note the statement still may be ! * below due to log_min_duration_statement directive. ! */ ! if (loggable_statement && save_log_duration) ereport(LOG,
---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings