Cannot get log_min_duration_statement to work

冷暖自知 提交于 2019-12-21 02:45:08

问题


I have been googling for more than 2 hours, but I am really stuck with this one.
I want PostgreSQL (I am using version 8.4 on Debian) to start logging slow queries only.

To that extend I use the following configuration in postgresql.conf:

log_destination = 'csvlog'
logging_collector = on
log_min_messages = log
log_min_duration_statement = 1000
log_duration = on
log_line_prefix = '%t '
log_statement = 'all' 

The rest of the configuration is all on default settings (commented out). The logging works, but it logs all statements, even the ones below the threshold of 1000 (ms). If I do a 'show all' I see that all settings are in effect. I also tried restarting Postgres.

I hope someone can help me out.


回答1:


log_statement = 'all'

instructs the server to log all statements, simple as that. In addition,

log_duration = on

also instructs the server to log all statements, including duration info.
Change that to

log_statement = none
log_duration = off

No quotes needed. Or comment them out and reload. Then no statement will logged, except those running longer than 1000 ms - instructed by

log_min_duration_statement = 1000

It's all in the excellent manual.




回答2:


Should be:

log_destination = 'csvlog'
logging_collector = on
log_min_duration_statement = 1000
log_line_prefix = '%t %p %r %d %u '### more context
log_statement = 'ddl' ### log schema changes 


来源:https://stackoverflow.com/questions/8414172/cannot-get-log-min-duration-statement-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!