常用短命令查询
1 | \? #查看所有帮助 |
查看死锁的SQL
1 | SELECT blocked_locks.pid AS blocked_pid, |
或者使用这个sql
1 | SELECT blocked_locks.pid AS blocked_pid, |
按建立连接的时间排序的正在运行查询的列表
1 | SELECT * FROM pg_stat_activity ORDER BY backend_start; |
统计idle,active,null的运行的sql的数量
1 | select state, wait_event, wait_event_type, count(*) from pg_stat_activity group by 1,2,3 order by wait_event; |
终止pid会话
1 | SELECT pg_terminate_backend('pid'); |
确认当前的连接用户和对应的连接机器
1 | SELECT datname,usename,client_addr,client_port FROM pg_stat_activity ; |
查看sql使用情况
1 | SELECT datname,usename,query FROM pg_stat_activity ; |
只查看当前正在运行的sql
1 | SELECT datname,usename,query |
查看耗时较长的sql
1 | select current_timestamp - query_start as runtime, datname, usename, query |
查看数据库的最大链接数
1 | show max_connections; |
查看当前使用的连接数
1 | SELECT COUNT(*) from pg_stat_activity; |
查看prepostsql的最大链接数
1 | select min_val, max_val from pg_settings where name='max_connections'; |
查看正在运行的sql,并且带上运行时长
1 | SELECT |