Re: session id and global storage - Mailing list pgsql-hackers

From Tom Lane
Subject Re: session id and global storage
Date
Msg-id 20345.1151590254@sss.pgh.pa.us
Whole thread Raw
In response to Re: session id and global storage  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
Andrew Dunstan <andrew@dunslane.net> writes:
> Rodrigo De Leon wrote:
>> You could do this:
>> 
>> SELECT procpid||' '||backend_start
>> FROM pg_stat_activity
>> WHERE datname = current_database()
>> AND usename = session_user
>> AND client_addr = inet_client_addr()
>> AND client_port = inet_client_port();

> That's pretty roundabout.

Indeed.  Use pg_backend_pid() instead:

SELECT whatever FROM pg_stat_activity WHERE procpid = pg_backend_pid();

A difficulty with this in existing releases is that pg_stat_activity
lags behind reality, so that you won't see your session listed in it
until you've been connected at least half a second or so.  8.2 won't
have that problem.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Thomas Hallgren
Date:
Subject: Re: [GENERAL] UUID's as primary keys
Next
From: "Hiroshi Saito"
Date:
Subject: Re: Compilatiuon of source code for windows