https://access.redhat.com/solutions/69314
SOLUTION UNVERIFIED - 已更新 2013年三月13日22:09 -
环境
- Red Hat Enterprise Linux 6
- postgresql-server
问题
- How to activate slow queries logs in postgresql?
决议
You could set this in postgresql.conf, To find the postgresql.conf you could use the find command like this:
# find / -name postgresql.conf
Now, in the postgresql.conf file you should look for the line:
#log_min_duration_statement = -1
and replace it with:
log_min_duration_statement = 500
This will log any querie that takes more than 500ms (miliseconds) to be done. You could adjust this to the value that you may considerer correct.
After that, save the file and reload the PostgreSQL configuration:
# service postgresql reload
Go to the directory where the logs of PostgreSQL are (comonly located in /var/lib/pgsql/data/pg_lo) and look for the lasted log file created.
Below, you will find an example of a query that took more than 500ms:
2011-09-29 11:27:39 BRT LOG: duration: 2051.457 ms execute pdo_stmt_000000b4: select * from backuplog WHERE message LIKE '%xyz%'
本文介绍如何在PostgreSQL中激活慢查询日志。通过修改postgresql.conf文件中的log_min_duration_statement参数,可以记录所有执行时间超过设定阈值(如500毫秒)的查询。调整此参数后,需重新加载PostgreSQL配置并检查日志文件。
1040

被折叠的 条评论
为什么被折叠?



