Number of Connections

Started by Steve McAteeabout 25 years ago8 messagesgeneral
Jump to latest
#1Steve McAtee
steve@proactivedev.com

Hello,

I'm a bit new to postgres. Is there anyway to tell the current number of
connections on a database or server? I'm having a connection closing
problem and would like to debug it somehow. I know on Sybase you can check
a sys table to determine this. Not familiar with how to do this on
Postgres.

Please advise and thank you.

#2Bryan White
bryan@arcamax.com
In reply to: Steve McAtee (#1)
Re: Number of Connections

Hello,

I'm a bit new to postgres. Is there anyway to tell the current number of
connections on a database or server? I'm having a connection closing
problem and would like to debug it somehow. I know on Sybase you can

check

a sys table to determine this. Not familiar with how to do this on
Postgres.

I use:
ps ax | grep postgres | wc -l
Note the value is often one to high because is picks up the grep process.

Use
ps ax | grep postgres
to look at the processes and see what IP are connected, what users, and what
the backend is doing (IDLE, SELECT, ..)

#3Neil Conway
neilc@samurai.com
In reply to: Bryan White (#2)
Re: Number of Connections

On Fri, Feb 16, 2001 at 02:09:42PM -0500, Bryan White wrote:

I use:
ps ax | grep postgres | wc -l
Note the value is often one to high because is picks up the grep process.

Why not just remove 'grep' - i.e

ps ax | grep postgres | grep -v grep | wc -l

HTH,

Neil

--
Neil Conway <neilconway@home.com>
Get my GnuPG key from: http://klamath.dyndns.org/mykey.asc
Encrypted mail welcomed

Four stages of acceptance:
i) this is worthless nonsense;
ii) this is an interesting, but perverse, point of view;
iii) this is true, but quite unimportant;
iv) I always said so.
-- J. B. S. Haldane in Journal of Genetics 58:464 (1963).

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#3)
Re: Number of Connections

Neil Conway <nconway@klamath.dyndns.org> writes:

On Fri, Feb 16, 2001 at 02:09:42PM -0500, Bryan White wrote:

ps ax | grep postgres | wc -l
Note the value is often one to high because is picks up the grep process.

Why not just remove 'grep' - i.e
ps ax | grep postgres | grep -v grep | wc -l

Actually this is a standard problem with a standard solution: use a
not-so-literal grep pattern, eg

ps ax | grep '[p]ostgres' | wc -l

This pattern matches 'postgres' but not '[p]ostgres'. Problem solved.

regards, tom lane

#5Tim Barnard
tbarnard@povn.com
In reply to: Steve McAtee (#1)
Re: Number of Connections

What's the purpose of the "grep -v grep" ?

Tim

----- Original Message -----
From: "Neil Conway" <nconway@klamath.dyndns.org>
To: "pgsql-general" <pgsql-general@postgreSQL.org>
Sent: Friday, February 16, 2001 12:05 PM
Subject: Re: [GENERAL] Number of Connections

On Fri, Feb 16, 2001 at 02:09:42PM -0500, Bryan White wrote:

I use:
ps ax | grep postgres | wc -l
Note the value is often one to high because is picks up the grep

process.

Show quoted text

Why not just remove 'grep' - i.e

ps ax | grep postgres | grep -v grep | wc -l

HTH,

Neil

--
Neil Conway <neilconway@home.com>
Get my GnuPG key from: http://klamath.dyndns.org/mykey.asc
Encrypted mail welcomed

#6Brett W. McCoy
bmccoy@chapelperilous.net
In reply to: Tim Barnard (#5)
Re: Number of Connections

On Fri, 16 Feb 2001, Tim Barnard wrote:

What's the purpose of the "grep -v grep" ?

It ignores listing of grep in the output stream.

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Q: What do agnostic, insomniac dyslexics do at night?
A: Stay awake and wonder if there's a dog.

#7John Burski
John.Burski@911ep.com
In reply to: Steve McAtee (#1)
Re: Number of Connections

The "-v" option tells grep to select everything EXCEPT the following
term. Therefore, the "grep -v grep" section of the piped commands will
delete the "extra" line (the one generated by the "grep postgres"
command) that the ps command spits out prior to piping it into the "wc
-l" command.

Tim Barnard wrote:

What's the purpose of the "grep -v grep" ?

Tim

----- Original Message -----
From: "Neil Conway" <nconway@klamath.dyndns.org>
To: "pgsql-general" <pgsql-general@postgreSQL.org>
Sent: Friday, February 16, 2001 12:05 PM
Subject: Re: [GENERAL] Number of Connections

On Fri, Feb 16, 2001 at 02:09:42PM -0500, Bryan White wrote:

I use:
ps ax | grep postgres | wc -l
Note the value is often one to high because is picks up the grep

process.

Why not just remove 'grep' - i.e

ps ax | grep postgres | grep -v grep | wc -l

HTH,

Neil

--
Neil Conway <neilconway@home.com>
Get my GnuPG key from: http://klamath.dyndns.org/mykey.asc
Encrypted mail welcomed

--
John Burski
Chief IT Cook and Bottlewasher
911 Emergency Products, St. Cloud, MN
(320) 656 0076 www.911ep.com

++++++++++++++++++++++++++++++++++
+ How's your cheese holding out? +
++++++++++++++++++++++++++++++++++
#8Tim Barnard
tbarnard@povn.com
In reply to: Steve McAtee (#1)
Re: Number of Connections

Thanks.

Tim

----- Original Message -----
From: "John Burski" <John.Burski@911ep.com>
To: "Tim Barnard" <tbarnard@povn.com>
Cc: "pgsql-general" <pgsql-general@postgresql.org>
Sent: Friday, February 16, 2001 2:47 PM
Subject: Re: [GENERAL] Number of Connections

Show quoted text

The "-v" option tells grep to select everything EXCEPT the following
term. Therefore, the "grep -v grep" section of the piped commands will
delete the "extra" line (the one generated by the "grep postgres"
command) that the ps command spits out prior to piping it into the "wc
-l" command.

Tim Barnard wrote:

What's the purpose of the "grep -v grep" ?

Tim