X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 486973A3FAF for ; Wed, 17 Nov 2004 14:25:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82742-05 for ; Wed, 17 Nov 2004 14:25:22 +0000 (GMT) Received: from web13924.mail.yahoo.com (web13924.mail.yahoo.com [66.163.176.49]) by svr1.postgresql.org (Postfix) with SMTP id C8E073A3F24 for ; Wed, 17 Nov 2004 14:25:25 +0000 (GMT) Received: (qmail 97897 invoked by uid 60001); 17 Nov 2004 14:25:25 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=XDQsT4mJaPr0NZAbQqZRAL7yb9tcvGKIfM6kAu67L8PbRDi76Sh2F5QPSLaEEvCB/qqL7Wz2edG614M4k/Y7cFAvei2EovCllUwRjUHdQ/0sBfHpP8yAsPt4onckv6HpEnrlm2mbPpxnZziNLnixamvGWqUd7OcgSYfwxFvN1WU= ; Message-ID: <20041117142525.97895.qmail@web13924.mail.yahoo.com> Received: from [80.67.100.162] by web13924.mail.yahoo.com via HTTP; Wed, 17 Nov 2004 06:25:25 PST Date: Wed, 17 Nov 2004 06:25:25 -0800 (PST) From: "Riccardo G. Facchini" Reply-To: abief_ag_-postgresql@yahoo.com Subject: Re: session_id To: Richard Huxton , abief_ag_-postgresql@yahoo.com Cc: pgsql-sql@postgresql.org In-Reply-To: <419B56CC.8090703@archonet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/171 X-Sequence-Number: 19490 --- 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,