我可以在PostgreSQL 8.4中记录查询执行时间吗? [英] Can I log query execution time in PostgreSQL 8.4?
问题描述
我想记录一天中运行的每个查询的执行时间。
I want to log each query execution time which is run in a day.
例如,
2012-10-01 13:23:38 STATEMENT: SELECT * FROM pg_stat_database runtime:265 ms.
请给我一些指导。
推荐答案
如果您设置
log_min_duration_statement = 0
log_statement = all
,那么您将看到所有语句都被记录到Postgres日志文件中。
in your postgresql.conf, then you will see all statements being logged into the Postgres logfile.
如果启用
log_duration
还将打印每个语句花费的时间。
that will also print the time taken for each statement. This is off by default.
使用 log_statement
参数,您可以控制哪种类型要记录的语句(DDL,DML等)
Using the log_statement
parameter you can control which type of statement you want to log (DDL, DML, ...)
这将在日志文件中生成如下输出:
This will produce an output like this in the logfile:
2012-10-01 13:00:43 CEST postgres LOG: statement: select count(*) from pg_class;
2012-10-01 13:00:43 CEST postgres LOG: duration: 47.000 ms
手册中的更多详细信息:
More details in the manual:
- http://www.postgresql.org/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN
- http://www.postgresql.org/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT
- http://www.postgresql.org/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN
- http://www.postgresql.org/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT
如果需要每日列表,则可能需要将日志文件配置为每天轮换。再次在手册中对此进行了描述。
If you want a daily list, you probably want to configure the logfile to rotate on a daily basis. Again this is described in the manual.
这篇关于我可以在PostgreSQL 8.4中记录查询执行时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!