Thread: To monitor the number of PostgreSQL database connections?

To monitor the number of PostgreSQL database connections?

From
Nithya Soman
Date:
Hi

Could you please provide any method (query or any logfile) to check
max connections happened during a time interval in psql DB ?


Re: To monitor the number of PostgreSQL database connections?

From
Bruce Momjian
Date:
On Wed, Mar 26, 2014 at 11:01:28AM +0530, Nithya Soman wrote:
> Hi
>
> Could you please provide any method (query or any logfile) to check
> max connections happened during a time interval in psql DB ?

I think there will be a message in the logs when you exceed
max_connections.  I think the error string will be:

    sorry, too many clients already

That is kind of an odd message.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +


Re: To monitor the number of PostgreSQL database connections?

From
Brian Cosgrove
Date:
I know this isn't exactly what you're looking for (a query or log), but we use this tool to monitor our connections and alert when they hit a particular threshold:



On Wed, Mar 26, 2014 at 12:31 AM, Nithya Soman <nithya@quintetsolutions.com> wrote:
Hi

Could you please provide any method (query or any logfile) to check
max connections happened during a time interval in psql DB ?


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: To monitor the number of PostgreSQL database connections?

From
David Johnston
Date:
Nithya Soman wrote
> Hi
>
> Could you please provide any method (query or any logfile) to check
> max connections happened during a time interval in psql DB ?

Only if the time interval desired in basically zero-width (i.e.,
instantaneous).  The "pg_stat_activity" view is your friend in this.

You have numerous options, including self-coding, for capturing and
historically reviewing these snapshots and/or setting up monitoring on them.

This presumes you are actually wondering "over any given time period how
many open connections were there"?  If your question is actually "In the
given time period did any clients get rejected because {max connections}
were already in use." you can check the PostgreSQL logs for the relevant
error.

Bruce basically said this question while Brian answered the first question.

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/To-monitor-the-number-of-PostgreSQL-database-connections-tp5797571p5797608.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: To monitor the number of PostgreSQL database connections?

From
Merlin Moncure
Date:
On Wed, Mar 26, 2014 at 7:02 PM, David Johnston <polobo@yahoo.com> wrote:
> Nithya Soman wrote
>> Hi
>>
>> Could you please provide any method (query or any logfile) to check
>> max connections happened during a time interval in psql DB ?
>
> Only if the time interval desired in basically zero-width (i.e.,
> instantaneous).  The "pg_stat_activity" view is your friend in this.
>
> You have numerous options, including self-coding, for capturing and
> historically reviewing these snapshots and/or setting up monitoring on them.
>
> This presumes you are actually wondering "over any given time period how
> many open connections were there"?  If your question is actually "In the
> given time period did any clients get rejected because {max connections}
> were already in use." you can check the PostgreSQL logs for the relevant
> error.

There's also some useful high level statistics (including connection
count) in pg_stat_database.  For exact connection count over time
frame, I'd turn on log_connections in postgresql.conf and grep the
log.

merlin


Re: To monitor the number of PostgreSQL database connections?

From
chiru r
Date:
And also you can monitor by scheduling below command in cron. It will collect the detailed data, so that we came to know where the connections are coming.

[postgres@local~]$ crontab -l
* * * * *  /opt/postgres/9.3/bin/psql -Aqt -p 5493 -c "select * from pg_stat_activity;" >>/tmp/stats.csv



On Thu, Mar 27, 2014 at 10:20 PM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Wed, Mar 26, 2014 at 7:02 PM, David Johnston <polobo@yahoo.com> wrote:
> Nithya Soman wrote
>> Hi
>>
>> Could you please provide any method (query or any logfile) to check
>> max connections happened during a time interval in psql DB ?
>
> Only if the time interval desired in basically zero-width (i.e.,
> instantaneous).  The "pg_stat_activity" view is your friend in this.
>
> You have numerous options, including self-coding, for capturing and
> historically reviewing these snapshots and/or setting up monitoring on them.
>
> This presumes you are actually wondering "over any given time period how
> many open connections were there"?  If your question is actually "In the
> given time period did any clients get rejected because {max connections}
> were already in use." you can check the PostgreSQL logs for the relevant
> error.

There's also some useful high level statistics (including connection
count) in pg_stat_database.  For exact connection count over time
frame, I'd turn on log_connections in postgresql.conf and grep the
log.

merlin


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general