我可以在PostgreSQL 8.4中记录查询执行时间吗?

编程入门 行业动态 更新时间:2024-10-28 00:14:01
本文介绍了我可以在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:

  • 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中记录查询执行时间吗?

本文发布于:2023-10-17 06:28:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:执行时间   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!