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

Re: session_id

From: Richard Huxton <dev(at)archonet(dot)com>
To: abief_ag_-postgresql(at)yahoo(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: session_id
Date: 2004-11-17 13:49:00
Message-ID: 419B56CC.8090703@archonet.com (view raw or flat)
Thread:
Lists: pgsql-sql
Riccardo G. Facchini wrote:
> hi all,
> 
> is there a way to determine the session id on a database session?
> 
> I would need to have a unique number whenever a session is started, and
> have this available as a function or view result.

Add a new sequence to your database:
   CREATE SEQUENCE my_session_id;

Then, at the start of every session:
   SELECT nextval('my_session_id');

and whenever you need the value:
   SELECT currval('my_session_id');

Sequences are concurrency-safe, so you're OK with multiple clients. They 
return INT8 values, so you should be good for unique numbers for a while.

The only thing is, you need to remember to call nextval() every time you 
connect.

HTH
-- 
   Richard Huxton
   Archonet Ltd

In response to

  • session_id at 2004-11-17 13:13:43 from Riccardo G. Facchini

Responses

pgsql-sql by date

Next:From: Riccardo G. FacchiniDate: 2004-11-17 14:25:25
Subject: Re: session_id
Previous:From: Riccardo G. FacchiniDate: 2004-11-17 13:13:43
Subject: session_id

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