Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ht5kq-00032W-Bs for pgsql-general@arkaria.postgresql.org; Thu, 01 Aug 2019 07:44:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ht5ko-0002jP-Qc for pgsql-general@arkaria.postgresql.org; Thu, 01 Aug 2019 07:44:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ht5ko-0002jI-HH for pgsql-general@lists.postgresql.org; Thu, 01 Aug 2019 07:44:02 +0000 Received: from mout.kundenserver.de ([212.227.126.131]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ht5kh-0005qo-0e for pgsql-general@lists.postgresql.org; Thu, 01 Aug 2019 07:44:01 +0000 Received: from [10.8.0.6] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPSA (Nemesis) id 1MdNse-1iS9WL0Trs-00ZQ7n for ; Thu, 01 Aug 2019 09:43:53 +0200 Subject: Re: Cursors for PGJDBC queries To: pgsql-general@lists.postgresql.org References: From: Thomas Kellerer Message-ID: Date: Thu, 1 Aug 2019 09:43:52 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:g02+97ccz5MJoiCnKBgp1QeqIdTqonSBXazm44cGk8UC/C0B8eu E5zAA0O5T/90gYkQyQ3pCELgbxTk+YOTj78O6gX1xlJbQos4F4qiJOEle4Oa48BNgR6Xh1t jCLmJjrhJCSMEzz68aTqLSLh4YJoSrlvo6UpbcfMSgbTzmGBFD8uAVGx+zHI0xjDpfzXFkJ QvYH+Gqw/6DZcTcgblHjw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:eJ7EFJrZAYk=:pvRP0M1Wc1/NuE3xIH9YO6 ci2f6ljbbkLjJpK0A+KmAwrHgoadeADsovNXOfnXBQLwuEibOSgWIDHNCQhTfR0ysYyr0O+Oh 3JPZp2X8CvMVMwwzYylN2mhxUjIpFp9QQHnT3Rx4epKvcQ7DmUxy2C4QJjZkhyUGqi+lNxt+V QaNGecJE2zFCzd9JppKPAbMIozlhWfuuU1rn4KuByt+x67sBCbF2idA1tJal7xMH0XLlmJQpe GJqKTyUn2ugTbI8/AfZQX/Mx5tgQSU9uxcGu2iFK8INyNUSIN/le7N34Q6TwZadaTr/Y9gCCk g4VAU1OUpw+Q0e9Oq2SoeQD917dbIrwHINNrYnlCGw1OIYoEiW2DdSLwuXByqh4amUoLh1J3l 69NKH0KSRQo/Sp8JxN9eBQrwV7apoxnyYvImVQ4HpdrScqGbizN8B1kodxuwsqhA6ie8g5Xft NQeFN67e46sWq5sJx6joh63Ox8V2XTco6O4bVnL0j5wfnfsA4mvGsTVER3PwJYDsdoj2KcVGP cAkNfO/RUqULmB1Hti9Ds5jerfdsio1gpW8SRuZ1afKpUIoWNopJPeSmkTYWkSJZogUN8+aOf E+0iHkH44H/5bPZV4sGmV0nAUhxjplE+RNkWY0FIW4651EpjUF7b+9l6NfCDNH68odEmj3Iuh GqKIeepv0adpvp3ksuorE8xhufHbaW11PZqYTbKx+jv49bQ1Dfxqg+kOHDM5juEDg16YPRZZz pNPfB1N+Q3K0KXuy4KW6SNmvQ6G9Y9nz86higBmPSb7djYFE1V6Zba9EqGw= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rashmi V Bharadwaj schrieb am 01.08.2019 um 09:10: > I am trying to set the fetch size for my ResultSet to avoid Out of > Memory exception. I have created the Statement with > ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY and > ResultSet.HOLD_CURSORS_OVER_COMMIT and I've also disabled auto commit > as mentioned in the link Getting results based on a cursor > . > I am still getting Out of memory error. My SQL query is a simple > SELECT statement to retrieve all the rows from a table. According to > https://postgrespro.com/list/thread-id/2370772, the holdability must > be CLOSE_CURSORS_AT_COMMIT. Could you please confirm this is a > requirement? To rule out the obvious: you did call Statement.setFetchSize() before calling executeQuery()? Using connection.setAutoCommit(false); Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(100); ResultSet rs = stmt.executeQuery("...."); while (rs.next()) { ... } works perfectly for me, even with really large results.