max_connections: 최대 허용 커넥션 수
total_connections: 현재 총 커넥션 수
active_connections: 활성 상태의 커넥션 수
idle_connections: 유휴 상태의 커넥션 수
idle_in_transaction_connections: 트랜잭션 중 유휴 상태의 커넥션 수
other_states: 위의 상태에 속하지 않는 기타 상태의 커넥션 수
SELECT
(SELECT setting FROM pg_settings WHERE name = 'max_connections') AS max_connections,
COUNT(*) as total_connections,
SUM(CASE WHEN state = 'active' THEN 1 ELSE 0 END) as active_connections,
SUM(CASE WHEN state = 'idle' THEN 1 ELSE 0 END) as idle_connections,
SUM(CASE WHEN state = 'idle in transaction' THEN 1 ELSE 0 END) as idle_in_transaction_connections,
SUM(CASE WHEN state NOT IN ('active', 'idle', 'idle in transaction') THEN 1 ELSE 0 END) as other_states
FROM
pg_stat_activity;
SELECT
pid,
usename,
pg_blocking_pids(pid) AS blocked_by,
query AS blocked_query,
state,
now() - pg_stat_activity.query_start AS duration
FROM
pg_stat_activity
WHERE
state != 'idle'
AND query ~* 'cust02';
SELECT * FROM pg_locks WHERE relation = (SELECT oid FROM pg_class WHERE relname = 'cust02');
SELECT pg_terminate_backend(134844);
-- VACUUM (VERBOSE, ANALYZE) cust02;