PostgreSQL 13に接続中のセッションを確認する
環境
Windows10 64 bit
PostgreSQL 13.2
書式
select * from pg_stat_activity
where datname = 'データベース名’;
使用例
postgres=# select * from pg_stat_activity where datname ='postgres'; datid | datname | pid | leader_pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | state_change | wait_event_type | wait_event | state | backend_xid | backend_xmin | query | backend_type -------+----------+------+------------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------------+------------+--------+-------------+--------------+-----------------------------------------------------------+---------------- 13442 | postgres | 5608 | | 10 | postgres | psql | 127.0.0.1 | | 52789 | 2022-01-07 23:09:32.776245+09 | 2022-01-08 08:19:17.925329+09 | 2022-01-08 08:19:17.925329+09 | 2022-01-08 08:19:17.925336+09 | | | active | | 487 | select * from pg_stat_activity where datname ='postgres'; | client backend (1 行)
接続中のセッションを切断する
書式
SELECT pg_terminate_backend(pidを設定)
操作例
SELECT pg_terminate_backend(5608)