Skip to content

Instantly share code, notes, and snippets.

@ralexx
Created December 9, 2019 16:37
Show Gist options
  • Save ralexx/5ac45775e5a483b30c7813b17197c8d7 to your computer and use it in GitHub Desktop.
Save ralexx/5ac45775e5a483b30c7813b17197c8d7 to your computer and use it in GitHub Desktop.
Postgresql available connections
-- https://dba.stackexchange.com/a/161761
SELECT
max_conn,
used,
res_for_super,
max_conn-used-res_for_super res_for_normal
FROM
(
SELECT
COUNT(*) used
FROM
pg_stat_activity) t1,
(
SELECT
setting::INT res_for_super
FROM
pg_settings
WHERE
NAME = $$superuser_reserved_connections$$) t2,
(
SELECT
setting::INT max_conn
FROM
pg_settings
WHERE
NAME = $$max_connections$$) t3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment