By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

How to know the Number of Connection made with the database

P: 18
hi friends,

I would like to know the number of connections made with a particular database and at the same time i like to restrict the number of connections from my VC++ Application. I am Using yhe 'libpq' interface. Is it there any way to do this.

Mar 14 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 534
There is a number of ways to get the connection count, including these:

Expand|Select|Wrap|Line Numbers
  1. template1=# select datname, count(*) from pg_stat_activity group by datname;
  2.   datname  | count 
  3. -----------+-------
  4.  testdb    |     5
  5.  template1 |     1
  6. (2 rows)
  8. template1=# select datname, numbackends from pg_stat_database;
  9.   datname  | numbackends 
  10. -----------+-------------
  11.  testdb    |           5
  12.  template1 |           1
  13.  template0 |           0
  14. (3 rows)
Obviously you can use the WHERE clause in your query to get just the number of connections for particular database.

You can limit the number of connections using the run-time parameter max_connections
This setting controls the overall connection limit for the server, so if you have more than one
database there this option may not be very helpful.

Starting with version 8.1 you can control connection limit per user and per database, using
Mar 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.