1.查询时间长的sql
SELECT calls, (total_time/calls) as average ,rows, 100.0 * shared_blks_hit /nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent ,query FROM pg_stat_statements where calls > 100
ORDER BY average DESC LIMIT 100;
2.重置sql查询 select pg_stat_statements_reset();
3.查询活跃链接数
select pid,(now() - xact_start) as time , state,query::char(120)
from pg_stat_activity where state != 'idle' order by time desc ;
4.取消执行SQL,proceed为PID值。
SELECT pg_terminate_backend(proceed) from pg_stat_activity where current_query='<IDLE>';