Bravo
Bravo

Reputation: 9037

How to find/command/sql query to find max number of connections available in PostgreSQL?

We are using PostgreSQL. Is there any command to know, what is the maximum number of connections possible? And how many are currently used? And how many additional connections can be made?

Is there any command or SQL query to run and check all this?

Upvotes: 1

Views: 470

Answers (3)

wildplasser
wildplasser

Reputation: 44250

You can check max_connections:

postgres=# show max_connections;

Output:

 max_connections 
-----------------
 30
(1 row)

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 246878

This should do the trick:

SELECT current_setting('max_connections')::bigint,
       current_setting('superuser_reserved_connections')::bigint,
       count(*) AS current_connections
FROM pg_stat_activity
WHERE datid IS NOT NULL;

The number of available connections is the first entry minus the other two.

Upvotes: 0

Vao Tsun
Vao Tsun

Reputation: 51529

smth like should work:

t=# select current_setting('max_connections')::int - count(1) from pg_stat_activity;
 ?column?
----------
       93
(1 row)

where current_setting('max_connections') is allowed maximum, and pg_stat_activity knows how many connection and of what type( column state) you have

Upvotes: 1

Related Questions