Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DF9C06364AD for ; Thu, 17 Sep 2009 11:55:06 -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 33085-01 for ; Thu, 17 Sep 2009 14:54:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from is.rice.edu (is.rice.edu [128.42.42.24]) by mail.postgresql.org (Postfix) with ESMTP id 3011D632A10 for ; Thu, 17 Sep 2009 11:54:56 -0300 (ADT) Received: from scan1.mail.rice.edu (scan1.mail.rice.edu [128.42.58.160]) by is.rice.edu (Postfix) with ESMTP id 4397F4181C; Thu, 17 Sep 2009 09:54:54 -0500 (CDT) Received: from is.rice.edu ([128.42.42.24]) by scan1.mail.rice.edu (scan1.mail.rice.edu [128.42.58.160]) (amavisd-new, port 10024) with ESMTP id 02566-07; Thu, 17 Sep 2009 09:54:53 -0500 (CDT) Received: by is.rice.edu (Postfix, from userid 18612) id 8A28B41819; Thu, 17 Sep 2009 09:54:53 -0500 (CDT) Date: Thu, 17 Sep 2009 09:54:53 -0500 From: Kenneth Marshall To: rawi Cc: pgsql-sql@postgresql.org Subject: Re: Hibernate, web application and only one sequence for all primary keys Message-ID: <20090917145453.GC22802@it.is.rice.edu> References: <25490498.post@talk.nabble.com> <4AB23593.4090906@beecom.ch> <25491924.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <25491924.post@talk.nabble.com> User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: by amavis-2.2.1 at scan1.mail.rice.edu X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.586 tagged_above=-10 required=5 tests=AWL=0.013, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200909/93 X-Sequence-Number: 33158 On Thu, Sep 17, 2009 at 07:47:13AM -0700, rawi wrote: > > > Leo Mannhart wrote: > > > > Caveat: If you use the standard sequence generator in hibernate, it is > > not using the postgres-sequence in the "usual" manner. hibernate itself > > caches 50 ID's as sequence numbers by default. This means, hibernate > > only does a select on the database sequence every 50 numbers. it > > multyplies the database sequence by 50 to get the "real" sequence > > number. it generates the sequence numbers in blocks of 50 numbers or > > according to the sequence cache size. > > That said, you would probably not see any performance bottlenecks > > because of the sequence number generator in the database, even with > > thousands of inserts per second. > > > > Hi Leo, thank you for the explanation! > > I don't know if it is that cool to lose up to 50 IDs on each session-end of > Hibernate... > And what do you suppose it would happen, if I set the cache size of > Hibernate's own sequence (after generation) by hand to 1 instead of 50? I > wouldn't need tausends of inserts per second... > > Kind regards, Rawi > Hi Rawi, If hibernate manages its pool of 50, it can use much lighter-weight processes than using a full SQL query to a database. I would recommend leaving it be. You can afford to lose a few ids in 2**63. Regards, Ken