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

From Andrew Dunstan
Subject Re: session id and global storage
Date
Msg-id 44A3D92D.8020502@dunslane.net
Whole thread Raw
In response to Re: session id and global storage  ("Rodrigo De Leon" <rdeleonp@gmail.com>)
Responses Re: session id and global storage  ("Rodrigo De Leon" <rdeleonp@gmail.com>)
Re: session id and global storage  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Rodrigo De Leon wrote:

>>>> Hi, I cant find any function, which tells me something like session
>>>> id. Is there something like that? I need it in my AM, because I need
>>>> to know, if something which I wrote in file was written in this
>>>> current session or previously.
>>>
>>>
>>> How about
>>> select procpid||' '||backend_start from pg_stat_activity;
>>> Yours,
>>> Laurenz Albe
>>
>>
>> Something like this would be maybe possible, but this select can
>> return more rows, when the user is connected with more instances...
>>
>
> 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. We already expose (hex coded) pid.starttime as 
a session identifier in log_line_prefix (it's the %c escape) so I don't 
see any reason not to provide either the same thing directly in a 
function, or at least to expose the backend pid.

If you need it in backend C code, the data can be fetched from MyProcPid 
and MyProcPort->session_start.tv_sec

cheers

andrew



pgsql-hackers by date:

Previous
From: "Rodrigo De Leon"
Date:
Subject: Re: session id and global storage
Next
From: Greg Stark
Date:
Subject: Re: [GENERAL] UUID's as primary keys