Re: identify database process given client process - Mailing list pgsql-general

From Gurjeet Singh
Subject Re: identify database process given client process
Date
Msg-id 65937bea0803180020y1b607d1ax1f4ef620b7b1b21c@mail.gmail.com
Whole thread Raw
In response to identify database process given client process  (hogcia <hogcia@gmail.com>)
List pgsql-general
On Mon, Mar 17, 2008 at 8:28 PM, hogcia <hogcia@gmail.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[.singh]@EnterpriseDB.com
singh.gurjeet@{ 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

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: Problem with async notifications of table updates
Next
From: "Blair Bethwaite"
Date:
Subject: Re: Is autovacuum on?