Skip site navigation (1) Skip section navigation (2)

Re: session id and global storage

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: rdeleonp(at)gmail(dot)com, rdeleonp(at)yahoo(dot)com, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: session id and global storage
Date: 2006-06-29 14:10:54
Message-ID: 20345.1151590254@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Andrew Dunstan <andrew(at)dunslane(dot)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

In response to

pgsql-hackers by date

Next:From: Hiroshi SaitoDate: 2006-06-29 14:52:46
Subject: Re: Compilatiuon of source code for windows
Previous:From: Thomas HallgrenDate: 2006-06-29 13:54:36
Subject: Re: [GENERAL] UUID's as primary keys

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group