https://access.redhat.com/solutions/1248183
SOLUTION IN PROGRESS - 已更新 2014年十一月5日00:35 -
环境
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- PostgreSQL 8.4 or higher
问题
- How can I check all the current SQL queries being executed by the PostgreSQL?
决议
- To show all current queries:
SELECT datname,procpid,current_query FROM pg_stat_activity;
SELECT datname,usename,procpid,client_addr,waiting,query_start,current_query FROM pg_stat_activity ;
- To group the queries by status:
SELECT count(*) as counter, usename, current_query FROM pg_stat_activity GROUP BY usename,current_query ORDER BY counter DESC;
- To save to a log all the queries that takes more the 2 seconds, you can use:
# vim /var/lib/pgsql/data/postgresql.conf
log_min_duration_statement = 2000
# service postgresql restart
本文介绍如何使用PostgreSQL内置的pg_stat_activity视图来查看当前正在执行的所有SQL查询,包括查询用户、进程ID、客户端地址及等待状态。此外,还提供了按状态分组查询的方法,以及如何设置日志记录所有超过2秒的查询。
4020

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



