Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 29770632C56; Mon, 19 Apr 2010 20:33:37 -0300 (ADT) 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 10284-09; Mon, 19 Apr 2010 23:33:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f216.google.com (mail-bw0-f216.google.com [209.85.218.216]) by mail.postgresql.org (Postfix) with ESMTP id F32B9632D2A; Mon, 19 Apr 2010 20:33:25 -0300 (ADT) Received: by bwz8 with SMTP id 8so4996742bwz.3 for ; Mon, 19 Apr 2010 16:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:received:message-id :subject:from:to:cc:content-type; bh=Oubo9d7i9bAv5lOy571gqe7ah+EbruqU4ZFZ0py3ZlA=; b=G4MVgCRT/BUkxBSsX/z4rvBo/lgADMZIA5Yk1F3XDHxpxkw08oNBHMPnOgc/mCUAxC idvIYjcHF2p5Dm2zGioq+XnmwqA/3/rhkD16bujh7ryTKq4KPvkVS86jvtteJ5N4xRai 7NEhof0Ttzb9So1yJnm7kdG9IwRwma0LpzcJE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=NDi6ZLaId3n5DgudtquVUJC1xZUWcNR+Z+eIjCaZJxwrZiF8MQC0QvtY8xXcIEoVQ4 gdeip5exfIM1HfHzG0vQCqZWjaO+MhueRgxaziXw3RtqfOg8pX+DNBOU5lvTbGce4MFo UbEFedbp4Ui71ZX6NRQI5XjWoubUB4JMReJqo= MIME-Version: 1.0 Received: by 10.204.66.8 with HTTP; Mon, 19 Apr 2010 16:33:24 -0700 (PDT) Date: Mon, 19 Apr 2010 18:33:24 -0500 Received: by 10.204.23.80 with SMTP id q16mr5016727bkb.201.1271720004042; Mon, 19 Apr 2010 16:33:24 -0700 (PDT) Message-ID: Subject: SOLVED ... Re: Getting rid of a cursor from JDBC .... Re: [PERFORM] Re: HELP: How to tame the 8.3.x JDBC driver with a biq guery result set From: Dave Crooke To: Scott Carey Cc: pgsql-performance , pgsql-jdbc@postgresql.org Content-Type: multipart/alternative; boundary=00032555623a18414e04849f63f8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201004/30 X-Sequence-Number: 20441 --00032555623a18414e04849f63f8 Content-Type: text/plain; charset=UTF-8 Statement.close() appears to get the job done (in my envrionment, PG's driver never sees a Connection.close() because of DBCP). I'd consider the fact that ResultSet.close() does not release the implicit cursor to be something of a bug, but it may well have been fixed already. Cheers Dave On Mon, Apr 19, 2010 at 6:28 PM, Dave Crooke wrote: > Scott - I tried to post a SOLVED followup to the JDBC list but it was > rejected :-! > > I now have the opposite problem of getting rid of the cursor :-) > ResultSet.close() does not work. I am trying to do a DROP TABLE from the > other Connection, to whack the table I just finished the ETL on, but it just > hangs indefintiely, and pg_locks shows the shared read lock still sitting > there. > > I am trying a Statement.close() and Connection.close() now, but I fear I > may have to do something slightly ugly, as I have Apache DBCP sitting in > between me and the actual PG JDBC driver. > > I am hoping the slightly ugly thing is only closing the underlying > connection, and does not have to be */etc/init.d/postgresql8.3 restart*:-) Is there a backdoor way to forcibly get rid of a lock you don't need any > more? > > Cheers > Dave > > On Mon, Apr 19, 2010 at 1:05 PM, Scott Carey wrote: > >> On Apr 15, 2010, at 1:01 PM, Dave Crooke wrote: >> > On Thu, Apr 15, 2010 at 2:42 PM, Dave Crooke wrote: >> > Hey folks >> > >> > I am trying to do a full table scan on a large table from Java, using a >> straightforward "select * from foo". I've run into these problems: >> > >> > 1. By default, the PG JDBC driver attempts to suck the entire result set >> into RAM, resulting in java.lang.OutOfMemoryError ... this is not cool, in >> fact I consider it a serious bug (even MySQL gets this right ;-) I am only >> testing with a 9GB result set, but production needs to scale to 200GB or >> more, so throwing hardware at is is not feasible. >> > >> >> For scrolling large result sets you have to do the following to prevent it >> from loading the whole thing into memory: >> >> >> Use forward-only, read-only result scrolling and set the fetch size. Some >> of these may be the default depending on what the connection pool is doing, >> but if set otherwise it may cause the whole result set to load into memory. >> I regularly read several GB result sets with ~10K fetch size batches. >> >> Something like: >> Statement st = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, >> java.sql.ResultSet.CONCUR_READ_ONLY) >> st.setFetchSize(FETCH_SIZE); >> > > That's what I''m using, albeit without any args to createStatement, and it > now works. > > >> >> >> >> > 2. I tried using the official taming method, namely >> java.sql.Statement.setFetchSize(1000) and this makes it blow up entirely >> with an error I have no context for, as follows (the number C_10 varies, >> e.g. C_12 last time) ... >> > >> > org.postgresql.util.PSQLException: ERROR: portal "C_10" does not exist >> > at >> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592) >> > at >> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327) >> > at >> org.postgresql.core.v3.QueryExecutorImpl.fetch(QueryExecutorImpl.java:1527) >> > at >> org.postgresql.jdbc2.AbstractJdbc2ResultSet.next(AbstractJdbc2ResultSet.java:1843) >> > >> > This is definitely a bug :-) >> > >> > >> >> I have no idea what that is. >> > > It was because I was also writing to the same Connection ... when you call > Connection.commit() with the PG JDBC driver, it also kills all your open > cursors. > > I think this is a side effect of the PG internal design where it does MVCC > within a table (rows have multiple versions with min and max transaction > ids) ... even a query in PG has a notional virtual transaction ID, whereas > in e.g. Oracle, a query has a start time and visibility horizon, and as long > as you have enough undo tablespace, it has an existence which is totally > independent of any transactions going on around it even on the same JDBC > connection. > > > > > --00032555623a18414e04849f63f8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Statement.close() appears to get the job done (in my envrionment, PG's = driver never sees a Connection.close() because of DBCP).

I'd con= sider the fact that ResultSet.close() does not release the implicit cursor = to be something of a bug, but it may well have been fixed already.

Cheers
Dave

On Mon, Apr 19, 2010 a= t 6:28 PM, Dave Crooke <dcrooke@gmail.com> wrote:
Scott - I tried to post a SOLVED followup to the JDBC list but it was rejec= ted :-!

I now have the opposite problem of getting rid of the cursor= :-) ResultSet.close() does not work. I am trying to do a DROP TABLE from t= he other Connection, to whack the table I just finished the ETL on, but it = just hangs indefintiely, and pg_locks shows the shared read lock still sitt= ing there.

I am trying a Statement.close() and Connection.close() now, but I fear = I may have to do something slightly ugly, as I have Apache DBCP sitting in = between me and the actual PG JDBC driver.

I am hoping the slightly u= gly thing is only closing the underlying connection, and does not have to b= e /etc/init.d/postgresql8.3 restart :-) Is there a backdoor way to f= orcibly get rid of a lock you don't need any more?

Cheers
Dave

On Mon, Apr 19, 2010 a= t 1:05 PM, Scott Carey <scott@richrelevance.com> wrote= :
On Apr 15, 2010, at 1:01 PM, Dave Crooke wrote:
> On Thu, Apr 15, 2010 at 2:42 PM, Dave Crooke <dcrooke@gmail.com> wrote:
> Hey folks
>
> I am trying to do a full table scan on a large table from Java, using = a straightforward "select * from foo". I've run into these pr= oblems:
>
> 1. By default, the PG JDBC driver attempts to suck the entire result s= et into RAM, resulting in java.lang.OutOfMemoryError ... this is not cool, = in fact I consider it a serious bug (even MySQL gets this right ;-) I am on= ly testing with a 9GB result set, but production needs to scale to 200GB or= more, so throwing hardware at is is not feasible.
>

For scrolling large result sets you have to do the following to preve= nt it from loading the whole thing into memory:


Use forward-only, read-only result scrolling and set the fetch size. =C2=A0= Some of these may be the default depending on what the connection pool is d= oing, but if set otherwise it may cause the whole result set to load into m= emory. =C2=A0I regularly read several GB result sets with ~10K fetch size b= atches.

Something like:
Statement st =3D =C2=A0conn.createStatement(java.sql.ResultSet.TYPE_FORWARD= _ONLY, java.sql.ResultSet.CONCUR_READ_ONLY)
st.setFetchSize(FETCH_SIZE);

That's what I'= ;'m using, albeit without any args to createStatement, and it now works= .
=C2=A0



> 2. I tried using the official taming method, namely java.sql.Statement= .setFetchSize(1000) and this makes it blow up entirely with an error I have= no context for, as follows (the number C_10 varies, e.g. C_12 last time) .= ..
>
> org.postgresql.util.PSQLException: ERROR: portal "C_10" does= not exist
> =C2=A0 =C2=A0 at org.postgresql.core.v3.QueryExecutorImpl.receiveError= Response(QueryExecutorImpl.java:1592)
> =C2=A0 =C2=A0 at org.postgresql.core.v3.QueryExecutorImpl.processResul= ts(QueryExecutorImpl.java:1327)
> =C2=A0 =C2=A0 at org.postgresql.core.v3.QueryExecutorImpl.fetch(QueryE= xecutorImpl.java:1527)
> =C2=A0 =C2=A0 at org.postgresql.jdbc2.AbstractJdbc2ResultSet.next(Abst= ractJdbc2ResultSet.java:1843)
>
> This is definitely a bug :-)
>
>

I have no idea what that is.

It was because = I was also writing to the same Connection ... when you call Connection.comm= it() with the PG JDBC driver, it also kills all your open cursors.

I think this is a side effect of the PG internal design where it does M= VCC within a table (rows have multiple versions with min and max transactio= n ids) ... even a query in PG has a notional virtual transaction ID, wherea= s in e.g. Oracle, a query has a start time and visibility horizon, and as l= ong as you have enough undo tablespace, it has an existence which is totall= y independent of any transactions going on around it even on the same JDBC = connection.


=C2=A0


--00032555623a18414e04849f63f8--