如何選擇一個PostgreSQL數據庫的活動連接列表?

[英]How to select list of active connections to a PostgreSQL database


Is there a command in PostgreSQL to select active connections to a given database?

PostgreSQL中是否有命令選擇到給定數據庫的活動連接?

psql states that I can't drop one of my databases because there are active connections to it, so I would like to see what the connections are (and from which machines)

psql說我不能刪除一個數據庫,因為它有活動連接,所以我想看看連接是什么(以及從哪個機器)

2 个解决方案

#1


88  

Oh, I just found that command on PostgreSQL forum:

哦,我剛在PostgreSQL論壇上找到這個命令:

SELECT * FROM pg_stat_activity;

#2


2  

Following will give you active connections/ queries in postgres DB-

以下將為您提供在postgres DB中的活動連接/查詢。

SELECT 
    pid
    ,datname
    ,usename
    ,application_name
    ,client_hostname
    ,client_port
    ,backend_start
    ,query_start
    ,query
    ,state
FROM pg_stat_activity
WHERE state = 'active'

You may use 'idle' instead of active to get already executed connections/queries.

您可以使用'idle'代替active來獲取已執行的連接/查詢。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/12/12/73013dee498094e174cb6dda2059a5af.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com