Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 2B0D36326AD for ; Tue, 17 Mar 2009 14:05:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 65517-03 for ; Tue, 17 Mar 2009 14:05:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx02.burntmail.com (7a.3f.5746.static.theplanet.com [70.87.63.122]) by mail.postgresql.org (Postfix) with ESMTP id 90C5F632516 for ; Tue, 17 Mar 2009 14:05:22 -0300 (ADT) Received: from pool-173-79-61-185.washdc.fios.verizon.net ([173.79.61.185] helo=[127.0.0.1]) by mx02.burntmail.com with esmtpa (Exim 4.63) (envelope-from ) id 1LjcjB-0002Kx-1c for pgsql-jdbc@postgresql.org; Tue, 17 Mar 2009 12:05:21 -0500 Message-ID: <49BFD848.5040207@burntmail.com> Date: Tue, 17 Mar 2009 13:05:12 -0400 From: Guy Rouillier User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Totally weird behaviour in org.postgresql.Driver References: <49b7bfef$0$1343$834e42db@reader.greatnowhere.com> <491f66a50903120342j67e87c7dob10cfdc23580c8f4@mail.gmail.com> <003001c9a315$a68a9330$f39fb990$@com> <200903121341.59498.cservin@cromagnon.com> <49bca9e8$0$1341$834e42db@reader.greatnowhere.com> <491f66a50903150409y648b448pc3825ef4fc1ed7e@mail.gmail.com> <49bcfe15$0$1344$834e42db@reader.greatnowhere.com> <49BDABC7.3030108@burntmail.com> <491f66a50903160257m3cd01c07v828a33fab173e775@mail.gmail.com> <49bf5e7f$0$1347$834e42db@reader.greatnowhere.com> In-Reply-To: <49bf5e7f$0$1347$834e42db@reader.greatnowhere.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 090317-0, 03/17/2009), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/90 X-Sequence-Number: 19420 Peter wrote: >>>>> It's fairly unusual to have a tomcat application of any size login to >>>>> the db as the user. Could you share the reason why ? >>>>> >>>>> >>>> The app is actually middleware for Adobe Flex frontend and PG backend, >>>> not a regular web app. The architecture requires PG to know which user >>>> has connected (lots of heavy lifting takes place in PG), and we so far >>>> havent found any other way how to let PG know which user has connected. >>>> The only alternative was to supply user ID in every PG function call but >>>> that is messy and introduces it's own limitations as well. If you have >>>> any suggestions I'm all ears! ;) >>>> >>> Set a user variable after you've obtained a connection from the pool, and >>> use that to log user-specific values. That way, you maintain the >>> benefits >>> of connection pools, but can still identify individual users. >>> >> It would seem to me that if you need to scale this app then you are going >> to >> have to set the user in the application somewhere. Having all of the users >> connect as themselves doesn't lend itself to being scalable. > > I guess you're right, but even so I should be able to scale it to hundreds > of simultaneous users - the only limiting factor is number of connections on > PG server. > > So is there a way to associate user variable with Postgres connection that > can be picked up by SQL code running in that connection? Right now I can > only think of PlPerl function that caches user id in a global variable, but > am not sure about potential pitfalls of such setup... Yes, that is what I was suggesting in my previous post. From an old thread titled "can I define own variables?": ======= To do this, you need to set custom_variable_classes in postgresql.conf, perhaps custom_variable_classes = uservars and then you can do things like SET uservars.foo = whatever; SHOW uservars.bar; ====== So, you can use pooled connections for scalability. After you retrieve a connection, set your user variable to contain the end user identifier. Then you can retrieve it as necessary (e.g., in a trigger) for the duration of the connection. -- Guy Rouillier