X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6BA80D1CE38 for ; Thu, 20 May 2004 19:55:13 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 61382-02 for ; Thu, 20 May 2004 19:54:49 -0300 (ADT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id CD1C4D1C4C3 for ; Thu, 20 May 2004 19:54:45 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1BQwR4-0007KO-00; Fri, 21 May 2004 10:54:46 +1200 Message-ID: <40AD3733.5000905@opencloud.com> Date: Fri, 21 May 2004 10:54:43 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andrea Aime Cc: pgsql-jdbc@postgresql.org Subject: Re: Queries with large ResultSets References: <40ABD19C.8080109@geophile.com> <200405202022.37646.andrea.aime@aliceposta.it> In-Reply-To: <200405202022.37646.andrea.aime@aliceposta.it> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200405/131 X-Sequence-Number: 10141 Andrea Aime wrote: > Ugh... those limitation are really frightening, this means we cannot fetch > big quantities of data outside of a transaction... this is a problem with > application servers like GeoServer that keep a connection pool and > need to fetch big quantities of data also outside a transaction... any hope > to see this fixed soon? Is it a driver problem or a server limitation? Cursor are implicitly closed at the end of a transaction unless they are declared WITH HOLD. Declaring a cursor WITH HOLD has an associated cost on the backend (namely it will copy the cursor's contents at the end of the transaction). If autocommit is on, you have an implicit transaction around every query, so it doesn't make sense to use a non-holdable cursor with autocommit on -- you'd never be able to fetch any results. This could be controllable via the JDBC3 resultset holdability methods, but currently it isn't and all resultsets effectively default to ResultSet.CLOSE_CURSORS_AT_COMMIT. I don't think you want a holdable cursor for this case anyway since the backend would end up doing a lot of unnecessary copying results around. If you're accessing big quantities of data, the overhead of an explicit commit() after you're done with the resultset is going to be insignificant compared to the cost of actually transferring and handling that data. Use something like this: connection.setAutoCommit(false); PreparedStatement stmt = connection.prepareStatement("SELECT ...."); ResultSet rs = stmt.executeQuery(); while (rs.next()) { // process data } rs.close(); connection.commit(); -O