13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLで各クライアントからの接続数とその内訳を確認するSQL

13
Posted at
SELECT
  client_addr,
  sum(1) numconns,
  sum(CASE WHEN state = 'active' THEN 1 ELSE 0 END) active,
  sum(CASE WHEN state = 'idle' THEN 1 ELSE 0 END) idle,
  sum(CASE WHEN state = 'idle in transaction' THEN 1 ELSE 0 END) idle_in_transaction,
  sum(CASE WHEN state = 'idle in transaction (aborted)' THEN 1 ELSE 0 END) aborted,
  sum(CASE WHEN state = 'fastpath function call' THEN 1 ELSE 0 END) fastpath,
  sum(CASE WHEN state = 'disabled' THEN 1 ELSE 0 END) disabled,
  sum(CASE WHEN state IS NULL THEN 1 ELSE 0 END) undefined
FROM
  pg_stat_activity
GROUP BY
  client_addr
ORDER BY
  client_addr;
13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?