From: | "Riccardo G(dot) Facchini" <abief_ag_-postgresql(at)yahoo(dot)com> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com>, abief_ag_-postgresql(at)yahoo(dot)com |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: session_id |
Date: | 2004-11-17 14:25:25 |
Message-ID: | 20041117142525.97895.qmail@web13924.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
--- Richard Huxton <__> wrote:
> 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
>
Good idea, but it won't work for what I need.
I'll be able to do get the nextval('my_session_id') as soon as the
session initiates, but my problem is that I need to make all the
subsecuent actions aware of that particular value. using
currval('my_session_id') is not good, as any other session is likely to
also change my_session_id to another value.
I was looking more on the pg_stat_activity view, but the problem I face
is that I'm not sure on how to retrieve the unique
pg_stat_get_backend_pid that corresponds to my own job...
thank you,
any other suggestion?
regards,
From | Date | Subject | |
---|---|---|---|
Next Message | Riccardo G. Facchini | 2004-11-17 14:27:32 | Re: session_id |
Previous Message | Richard Huxton | 2004-11-17 13:49:00 | Re: session_id |