GP - Display Active Connections
As a operations person, the 1st and most important thing to check for Active Connections on Database.
Below are SQL(s) which will help in getting Active Connection(s):
1. Show Active Connection(s)
SELECT
datname AS "Database",
procpid AS "Process ID",
sess_id AS "Session ID",
usesysid AS "Role OID",
usename AS " Role Name",
substr(current_query, 1, 40) AS "Query",
query_start AS "Query Start Time",
backend_start AS "Query Backend Start Time",
(current_timestamp - query_start) AS "Runtime",
waiting AS "Is Query Waiting on Anything?",
waiting_reason AS "Reason Query is Waiting"
FROM pg_stat_activity
WHERE procpid != pg_backend_pid()
ORDER BY
substr(current_query, 1, 40) DESC,
waiting ASC,
(current_timestamp - query_start) DESC;
2. If user wants to check for Specific Process ID(s)SELECT
procpid || ':' || usename AS "Process Info",
current_query AS "Query"
FROM pg_stat_activity
WHERE procpid
IN (procpid#,...);
Above command can be used on individual database too.
psql -d <database_name> -c '<sql>'
Comments
Post a Comment