I'm running a log (log_min_duration_statement = 200) to analyse some slow queries in PostgreSQL 9.0 but the statements for worst queries aren't being logged. Is there any way I can find out what the queries actually are?

(some values replaced with *** for brevity and privacy.)

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 ***
...
有帮助吗?

解决方案 2

It turns out because I was keeping an eye on the logs with tail -f path | grep 'duration .+ ms' any statement starting with a newline was not visible. I was mainly doing this to highlight the duration string.

其他提示

There are some log file destination options in postgresql.conf, as shown below. I suggest to use 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

After making any changes, you need to reload the postgresql.conf file.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top