pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Cursors for PGJDBC queries
Date: Thu, 1 Aug 2019 09:43:52 +0200
Message-ID: <efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net> (raw)
In-Reply-To: <OFBD5B2616.7CB99C1C-ON00258449.00276250-00258449.00276254@notes.na.collabserv.com>
References: <OFBD5B2616.7CB99C1C-ON00258449.00276250-00258449.00276254@notes.na.collabserv.com>

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
> <https://jdbc.postgresql.org/documentation/head/query.html#query-with-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.












view thread (4+ messages)

Message-ID: <efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net>
Permalink:  ../efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net/
Also on:    postgresql.org/message-id/efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: Cursors for PGJDBC queries
  In-Reply-To: <efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net>
  References: <OFBD5B2616.7CB99C1C-ON00258449.00276250-00258449.00276254@notes.na.collabserv.com> <efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox