Re: Getting process id of a connection?

From: Colin Wetherbee <cww(at)denterprises(dot)org>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Webb Sprague <webb(dot)sprague(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Getting process id of a connection?
Date: 2008-01-04 23:11:02
Message-ID: 477EBD06.2040603@denterprises.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua D. Drake wrote:
> On Fri, 4 Jan 2008 14:59:47 -0800
> "Webb Sprague" <webb(dot)sprague(at)gmail(dot)com> wrote:
>
>> Hi all,
>>
>> Is there a way to determine the pid of a database connection from
>> within that connection?
>>
>> As a hypothetical example, I would like to be able to do the
>> following:
>>
>> $ps x
>> PID TTY STAT TIME COMMAND
>> 11674 ? S 0:00 sshd: webbs(at)pts/1
>> 11675 pts/1 Ss 0:00 -bash
>> 11682 pts/1 T 0:00 psql
>> 11685 pts/1 R+ 0:00 ps x
>>
>> psql=# select CURRENT_PID;
>> 11682
>>
>> I want this so that I can log the psycopg2 connection pid, and kill it
>> to test reconnection code.
>
> postgres=# select procpid from pg_stat_activity;
> procpid
> - ---------
> 30851
> 17510
> 4496
> 20237
> 1305
> (5 rows)

I think he's looking for the pid of the client, not the server.

cww=# select procpid from pg_stat_activity;
procpid
---------
8902
(1 row)

8902 ? Ss 0:00 \_ postgres: cww cww 192.168.171.100(40424)
idle

Colin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Webb Sprague 2008-01-04 23:17:33 Re: Getting process id of a connection?
Previous Message Bricklen Anderson 2008-01-04 23:08:45 Re: Getting process id of a connection?