SQL call to get pid of current connection

Lists: pgsql-general
From: "David Parker" <dparker(at)tazznetworks(dot)com>
To: "postgres general" <pgsql-general(at)postgresql(dot)org>
Subject: SQL call to get pid of current connection
Date: 2005-06-02 21:04:22
Message-ID: 07FDEE0ED7455A48AC42AC2070EDFF7C746B74@corpsrv2.tazznetworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Is there a function call that will return the pid of the postgres
process associated with the current client connection?

- DAP
------------------------------------------------------------------------
----------
David Parker Tazz Networks (401) 709-5130



From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: David Parker <dparker(at)tazznetworks(dot)com>
Cc: postgres general <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL call to get pid of current connection
Date: 2005-06-02 22:02:14
Message-ID: 20050602220214.GA10425@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Jun 02, 2005 at 17:04:22 -0400,
David Parker <dparker(at)tazznetworks(dot)com> wrote:
> Is there a function call that will return the pid of the postgres
> process associated with the current client connection?

I thought I remembered seeing one, but I looked through the development
docs and didn't see a function or a GUC variable with that information.
It wouldn't be too hard to write a C or Perl function to get that
information.


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Bruno Wolff III <bruno(at)wolff(dot)to>, David Parker <dparker(at)tazznetworks(dot)com>, postgres general <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL call to get pid of current connection
Date: 2005-06-03 00:47:12
Message-ID: 20050603004712.GA15829@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Jun 02, 2005 at 05:02:14PM -0500, Bruno Wolff III wrote:
> On Thu, Jun 02, 2005 at 17:04:22 -0400,
> David Parker <dparker(at)tazznetworks(dot)com> wrote:
> > Is there a function call that will return the pid of the postgres
> > process associated with the current client connection?
>
> I thought I remembered seeing one, but I looked through the development
> docs and didn't see a function or a GUC variable with that information.

Are you looking for pg_backend_pid()? It's documented in the
"Statistics Collector" section of the "Monitoring Database Activity"
chapter; it's been around since 7.3:

http://www.postgresql.org/docs/7.3/interactive/release-7-3.html
http://www.postgresql.org/docs/7.3/interactive/monitoring-stats.html
http://www.postgresql.org/docs/7.4/interactive/monitoring-stats.html
http://www.postgresql.org/docs/8.0/interactive/monitoring-stats.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David Parker" <dparker(at)tazznetworks(dot)com>
Cc: "postgres general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL call to get pid of current connection
Date: 2005-06-03 01:03:12
Message-ID: 29425.1117760592@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

"David Parker" <dparker(at)tazznetworks(dot)com> writes:
> Is there a function call that will return the pid of the postgres
> process associated with the current client connection?

libpq makes this available as PQbackendPID(). Dunno about other
client libraries.

regards, tom lane