【问题标题】:Why are long-running queries blank in postgresql log?为什么 postgresql 日志中长时间运行的查询为空白?
【发布时间】:2012-06-30 14:24:40
【问题描述】:

我正在运行一个日志 (log_min_duration_statement = 200) 来分析 PostgreSQL 9.0 中的一些慢查询,但没有记录最差查询的语句。有什么方法可以找出查询的实际内容吗?

(为了简洁和隐私,一些值替换为***。)

2012-06-29 02:10:39 UTC LOG:  duration: 266.658 ms  statement: SELECT *** FROM "oauth_accesstoken" WHERE "oauth_accesstoken"."token" = E'***' 
2012-06-29 02:10:40 UTC LOG:  duration: 1797.400 ms  statement: 
2012-06-29 02:10:49 UTC LOG:  duration: 1670.132 ms  statement: 
2012-06-29 02:10:50 UTC LOG:  duration: 354.336 ms  statement: SELECT *** FROM ***
...

【问题讨论】:

  • 天哪,真是个傻瓜。事实证明,因为我用tail -f path | grep 'duration .+ ms' 密切关注日志,任何以换行符开头的语句都不可见。 面部护理
  • 您可以回答自己的问题并接受该答案。这样其他人就会知道这个问题已经解决了。

标签: postgresql postgresql-9.0


【解决方案1】:

postgresql.conf中有一些日志文件目的地选项,如下图所示。我建议使用csvlog

log_destination = 'csvlog'  
logging_collector = on  
log_directory = '/var/applog/pg_log/1922/'   
log_rotation_age = 1d 
log_rotation_size = 10MB 
log_statement = 'ddl'                   # none, ddl, mod, all
log_min_duration_statement = 200

进行任何更改后,您需要重新加载postgresql.conf 文件。

【讨论】:

    【解决方案2】:

    事实证明,因为我用tail -f path | grep 'duration .+ ms' 密切关注日志,所以任何以换行符开头的语句都不可见。我这样做主要是为了突出显示持续时间字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 2021-07-14
      • 2019-04-15
      • 1970-01-01
      相关资源
      最近更新 更多