查看当前节点有那些会话
最近更新时间: 2024-10-17 17:10:00
select * from pg_stat_activity;
- 查看活跃超时会话。
select pid,client_addr,state_change,query_start,state_change,EXTRACT(EPOCH FROM(now()-query_start)),query,state,usename,application_name from pg_stat_activity where EXTRACT(EPOCH FROM (now()-query_start))>60 and state!='idle';
- 按用户统计活跃连接数。
select count(1),usename from pg_stat_activity where EXTRACT(EPOCH FROM (now()-query_start))>60 and state!='idle' group by usename;
- 按客户端统计活跃连接数。
select count(1),client_addr from pg_stat_activity where EXTRACT(EPOCH FROM (now()-query_start))>60 and state!='idle' group by client_addr;