Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 5352B633130 for ; Tue, 22 Dec 2009 00:35:38 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 39389-09 for ; Tue, 22 Dec 2009 04:35:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.catalyst.net.nz (bertrand.catalyst.net.nz [202.78.240.40]) by mail.postgresql.org (Postfix) with ESMTP id 95954632A1B for ; Tue, 22 Dec 2009 00:35:30 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id B4EA331FA5; Tue, 22 Dec 2009 17:35:26 +1300 (NZDT) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9Ag6lHh-83Le; Tue, 22 Dec 2009 17:35:25 +1300 (NZDT) Received: from [IPv6:2404:130:0:1000:222:15ff:fe5c:2471] (unknown [IPv6:2404:130:0:1000:222:15ff:fe5c:2471]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 96E8331D7F; Tue, 22 Dec 2009 17:35:25 +1300 (NZDT) Message-ID: <4B304C8D.8000608@catalyst.net.nz> Date: Tue, 22 Dec 2009 17:35:25 +1300 From: Mark Kirkwood User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Ankit Kumar CC: pgsql-jdbc@postgresql.org Subject: Re: OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB References: <4B3047E7.9020901@xebia.com> In-Reply-To: <4B3047E7.9020901@xebia.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/84 X-Sequence-Number: 20165 Ankit Kumar wrote: > Hi > > I am running a Criteria.scroll() on postgresql on a DB containing 2M > records. The memory keeps increasing and finally it generates an > OutOfMemoryException. Please can you advice how to fix this. > > *Postgresql DB version:* 8.4 > *Postgresql Driver Used:* postgresql-8.4-701.jdbc4.jar > > Some forums do mention that "/scroll/" is slow on Postgresql. > > Is this a known issue or we need to do something specific to make > scroll work on Postgresql? > > It appears the driver class is loading all entity objects in memory > and not releasing them as expected in a scroll operation. > > > Appreciate any guidance/suggestion. > > *Exception StackTrace*: > java.lang.OutOfMemoryError: Java heap space > > This link might be useful for you to look at: https://forums.hibernate.org/viewtopic.php?p=2398604&sid=f277fe884089594fe39272f69b68e329 It would appear that you need to encourage Hibernate to use a cursor, instead of buffering the entire resultset in memory - I haven't looked too much at the hibernate docs (never used it before...) so I have no idea how to do this myself, but if I have time I'll dig a bit. Do you have a self contained example to show us how you are setting up the scrollable resultset? regards Mark