Re: Getting process id of a connection?

From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: Webb Sprague <webb(dot)sprague(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting process id of a connection?
Date: 2008-01-04 23:08:45
Message-ID: 477EBC7D.2060908@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Webb Sprague 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.
>
> Thanks!
> -W

I think select pg_backend_pid(); will do that.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Colin Wetherbee 2008-01-04 23:11:02 Re: Getting process id of a connection?
Previous Message Joshua D. Drake 2008-01-04 23:06:58 Re: Getting process id of a connection?