我想记录一天中运行的每个查询的执行时间。
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:
- www.postgresql/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN
- www.postgresql/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT
- www.postgresql/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN
- www.postgresql/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中记录查询执行时间吗?
发布评论