Re: identify database process given client process

Lists: pgsql-general
From: hogcia <hogcia(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: identify database process given client process
Date: 2008-03-17 14:58:25
Message-ID: 5aeaab6c-3676-482a-80c8-e908e76b84b7@e6g2000prf.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,
I have to find a Postgres database process pid (or other
identification) for a given client process pid. Or client processes
for a database process. How are they connected? I was suggested maybe
netstat could give me the answer and I think those are two pf_unix
processes. But maybe there are some PostgreSQL functions that do this?
How should I approach this topic?
Thanks in advance,
--
Agata Krawcewicz


From: "Joey K(dot)" <pguser(at)gmail(dot)com>
To: hogcia <hogcia(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: identify database process given client process
Date: 2008-03-17 18:53:56
Message-ID: 467669b30803171153o688dcc8ag84bd224efc47324@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Mon, Mar 17, 2008 at 6:58 AM, hogcia <hogcia(at)gmail(dot)com> wrote:

> Hi,
> I have to find a Postgres database process pid (or other
> identification) for a given client process pid. Or client processes
> for a database process. How are they connected? I was suggested maybe
> netstat could give me the answer and I think those are two pf_unix
> processes. But maybe there are some PostgreSQL functions that do this?
> How should I approach this topic?
> Thanks in advance,
>

Try

select pg_stat_activity;

Joey


From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: "Joey K(dot)" <pguser(at)gmail(dot)com>
Cc: hogcia <hogcia(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: identify database process given client process
Date: 2008-03-18 06:51:00
Message-ID: 47DF6654.5000405@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Joey K. wrote:
> On Mon, Mar 17, 2008 at 6:58 AM, hogcia <hogcia(at)gmail(dot)com> wrote:
>
>> Hi,
>> I have to find a Postgres database process pid (or other
>> identification) for a given client process pid. Or client processes
>> for a database process. How are they connected? I was suggested maybe
>> netstat could give me the answer and I think those are two pf_unix
>> processes. But maybe there are some PostgreSQL functions that do this?
>> How should I approach this topic?
>> Thanks in advance,
>>
>
> Try
>
> select pg_stat_activity;
>
>
> Joey
>

That would be select * from pg_stat_activity;

The columns that interest you would be datname,procpid,usename and
client_addr

The other way would be using ps (for a *nix server)

Depending on your system something similar to ps aux will give the
process details so the command column will give you something like -

postgres: mydbuser mydbname 192.168.0.3(49438) idle

which is the info you are after - pgsql is the dbusername, postgres is
the db they are connected to then the ip address and port they are
connecting from. The idle at the end will be replaced with the query
they are running.

--

Shane Ambler
pgSQL (at) Sheeky (dot) Biz

Get Sheeky @ http://Sheeky.Biz


From: "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com>
To: hogcia <hogcia(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: identify database process given client process
Date: 2008-03-18 07:20:57
Message-ID: 65937bea0803180020y1b607d1ax1f4ef620b7b1b21c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Mon, Mar 17, 2008 at 8:28 PM, hogcia <hogcia(at)gmail(dot)com> wrote:

> Hi,
> I have to find a Postgres database process pid (or other
> identification) for a given client process pid. Or client processes
> for a database process. How are they connected? I was suggested maybe
> netstat could give me the answer and I think those are two pf_unix
> processes. But maybe there are some PostgreSQL functions that do this?
> How should I approach this topic?
>

If possible, execute the following query from your client, and it will show
that server process the client is connected to.

select pg_backend_pid();

This is an easy, one way route to determine a client's shadow process, be it
local or remote.

If you want reverse lookup, that is, trying to find out which backend
process is servicing which client, it'd be a bit difficult. You have to
query pg_stat_activity and the client_addr and client_port columns wil give
you some information about the remote clients. For local clients using Unix
sockets, these columns are null.

Best regards,
--
gurjeet[(dot)singh](at)EnterpriseDB(dot)com
singh(dot)gurjeet(at){ gmail | hotmail | indiatimes | yahoo }.com

EnterpriseDB http://www.enterprisedb.com

17° 29' 34.37"N, 78° 30' 59.76"E - Hyderabad *
18° 32' 57.25"N, 73° 56' 25.42"E - Pune
37° 47' 19.72"N, 122° 24' 1.69" W - San Francisco

http://gurjeet.frihost.net

Mail sent from my BlackLaptop device