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 2373F3A3FAE for ; Wed, 17 Nov 2004 14:02:21 +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 73020-07 for ; Wed, 17 Nov 2004 14:02:06 +0000 (GMT) Received: from matrix.gatewaynet.com (matrix.gatewaynet.com [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id E53563A3F53 for ; Wed, 17 Nov 2004 14:02:08 +0000 (GMT) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id iAHEX35x008722; Wed, 17 Nov 2004 16:33:03 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id iAHEX3o9008718; Wed, 17 Nov 2004 16:33:03 +0200 Date: Wed, 17 Nov 2004 16:33:03 +0200 (EET) From: Achilleus Mantzios To: Richard Huxton Cc: abief_ag_-postgresql@yahoo.com, Subject: Re: session_id In-Reply-To: <419B56CC.8090703@archonet.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT 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/170 X-Sequence-Number: 19489 O Richard Huxton έγραψε στις Nov 17, 2004 : > 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. Why not SELECT pg_backend_pid(); ?? > > 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 > -- -Achilleus