数据库
首页 > 数据库> > 使用psql定制日常维护脚本

使用psql定制日常维护脚本

作者:互联网

编辑cat ~/.psqlrc文件

添加脚本

[postgres@localhost ~]$ cat ~/.psqlrc
\set active_session ' select pid,usename,datname,query,client_addr from pg_stat_activity where pid <> pg_backend_pid() and state=\'active\' order by query;'

使用方法:冒号后面接变量名

postgres=# :active_session
 pid | usename | datname | query | client_addr
-----+---------+---------+-------+-------------
(0 rows)

查询等待事件脚本

[postgres@localhost ~]$ cat ~/.psqlrc
\set active_session ' select pid,usename,datname,query,client_addr from pg_stat_activity where pid <> pg_backend_pid() and state=\'active\' order by query;'
\set wait_event 'select pid,usename,datname,query,client_addr,wait_event_type,wait_event_type from pg_stat_activity where pid <> pg_backend_pid() and wait_event_type is not null order by wait_event_type;'

 

标签:psql,pid,日常,active,query,定制,wait,event,pg
来源: https://www.cnblogs.com/LuoYao666/p/15404431.html