pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
OutOfMemoryError
10+ messages / 6 participants
[nested] [flat]

* OutOfMemoryError
@ 2005-08-29 14:09  rstepha1@nycap.rr.com
  0 siblings, 2 replies; 10+ messages in thread

From: rstepha1@nycap.rr.com @ 2005-08-29 14:09 UTC (permalink / raw)
  To: pgsql-jdbc

I am having a problem with performing large selects and getting a
java.lang.OutOfMemoryError.

Database: 8.0.1 JVM: 1.5 Driver: 8.0-311 JDBC 3

Using a simple select: SELECT col1, col2 FROM schm.tab1 WHERE col2
BETWEEN 30000 AND 31000

It seems that the ResultSet is containing the entire selected set of
data and not using a cursor within the database engine.  I have tried
setting the resultSetType and resultSetConcurrency to TYPE_FORWARD_ONLY
and CONCUR_READ_ONLY respectively to hopefully force the cursor
management to be server oriented, without success.

It is possible to work around by increasing the heap size or lowering
the selection criteria, but ...

How do you get the driver to not retrieve all of the data into the
ResultSet?  Is there a setting either within the JDBC driver, or at the
database that would determine caching X number of rows returned at a time?

Richard 



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: OutOfMemoryError
@ 2005-08-29 19:00  Kris Jurka <books@ejurka.com>
  parent: rstepha1@nycap.rr.com
  1 sibling, 0 replies; 10+ messages in thread

From: Kris Jurka @ 2005-08-29 19:00 UTC (permalink / raw)
  To: rstepha1@nycap.rr.com; +Cc: pgsql-jdbc



On Mon, 29 Aug 2005 rstepha1@nycap.rr.com wrote:

> I am having a problem with performing large selects and getting a
> java.lang.OutOfMemoryError.
>
> How do you get the driver to not retrieve all of the data into the
> ResultSet?  Is there a setting either within the JDBC driver, or at the
> database that would determine caching X number of rows returned at a time?
>

http://jdbc.postgresql.org/documentation/80/query.html#query-with-cursor

Kris Jurka



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: OutOfMemoryError
@ 2005-08-29 19:03  Marc Herbert <Marc.Herbert@emicnetworks.com>
  parent: rstepha1@nycap.rr.com
  1 sibling, 0 replies; 10+ messages in thread

From: Marc Herbert @ 2005-08-29 19:03 UTC (permalink / raw)
  To: pgsql-jdbc

rstepha1@nycap.rr.com writes:

> It seems that the ResultSet is containing the entire selected set of
> data and not using a cursor within the database engine.  I have tried
> setting the resultSetType and resultSetConcurrency to TYPE_FORWARD_ONLY
> and CONCUR_READ_ONLY respectively to hopefully force the cursor
> management to be server oriented, without success.
>
> It is possible to work around by increasing the heap size or lowering
> the selection criteria, but ...
>
> How do you get the driver to not retrieve all of the data into the
> ResultSet?  Is there a setting either within the JDBC driver, or at the
> database that would determine caching X number of rows returned at a time?

Try this: 

   myStatement.setFetchSize(43);

Warning: according to the JDBC spec, it's just a "hint", the driver
may still do what it thinks is good.







^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* outOfMemoryError
@ 2006-08-29 07:46  Vidas Makauskas <vms@centras.lt>
  0 siblings, 1 reply; 10+ messages in thread

From: Vidas Makauskas @ 2006-08-29 07:46 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

I've upgrade
SLES9 with pg73b1jdbc3.jar, IBMjava1.4.2, postgres 7.4.3
to
SLES10 with postgresql-8.1-404.jdbc3.jar, sunjava1.4.2, postgres 8.1.4
and get error in well working program previously with 10,000,000+ rows:
 Exception in thread "main" java.lang.OutOfMemoryError
on ResultSet.insertRow() in application source row after 100,000+ inserted 
rows from Oracle to Postgres table.

With java -Xmx128M i can insert 200,000+ rows.
But i need 10,000,000+ rows - previosly inserted without problems.

Then I make suppose what it's memory java managment isue
there fore atempt close and open outputResultSet every 100,000 inserted 
records
and reach 1,000,000+ inserted records.

But i need 10,000,000,000+ and with java -Xmx can't.

Next i check with pg73b1jdbc3.jar and get the exacly same result.
I've check SELECT * FROM outputTable WHERE oid=0,
because i need append only.

I found in google "Reduce the amount of memory you need during processing of
the ResultSets".
setFetchSize(1) not impact.
How to do?

Next I plan remove sun java and will install IBM java?
Why my program work previously with default configuration?

What next?

I can't believe that it is problem for me only.
May be I'm too new to java and miss some requirements.

Any advices are wellcome.

Vidas 





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: outOfMemoryError
@ 2006-08-29 12:05  Dave Cramer <pg@fastcrypt.com>
  parent: Vidas Makauskas <vms@centras.lt>
  0 siblings, 1 reply; 10+ messages in thread

From: Dave Cramer @ 2006-08-29 12:05 UTC (permalink / raw)
  To: Vidas Makauskas <vms@centras.lt>; +Cc: pgsql-jdbc

Vidas,

Can you post your basic loop ?

 From what I can see your expectations are a little unrealistic how  
do you expect to process 10G rows at a time?

Dave
On 29-Aug-06, at 3:46 AM, Vidas Makauskas wrote:

> Hi,
>
> I've upgrade
> SLES9 with pg73b1jdbc3.jar, IBMjava1.4.2, postgres 7.4.3
> to
> SLES10 with postgresql-8.1-404.jdbc3.jar, sunjava1.4.2, postgres 8.1.4
> and get error in well working program previously with 10,000,000+  
> rows:
>  Exception in thread "main" java.lang.OutOfMemoryError
> on ResultSet.insertRow() in application source row after 100,000+  
> inserted
> rows from Oracle to Postgres table.
>
> With java -Xmx128M i can insert 200,000+ rows.
> But i need 10,000,000+ rows - previosly inserted without problems.
>
> Then I make suppose what it's memory java managment isue
> there fore atempt close and open outputResultSet every 100,000  
> inserted
> records
> and reach 1,000,000+ inserted records.
>
> But i need 10,000,000,000+ and with java -Xmx can't.
>
> Next i check with pg73b1jdbc3.jar and get the exacly same result.
> I've check SELECT * FROM outputTable WHERE oid=0,
> because i need append only.
>
> I found in google "Reduce the amount of memory you need during  
> processing of
> the ResultSets".
> setFetchSize(1) not impact.
> How to do?
>
> Next I plan remove sun java and will install IBM java?
> Why my program work previously with default configuration?
>
> What next?
>
> I can't believe that it is problem for me only.
> May be I'm too new to java and miss some requirements.
>
> Any advices are wellcome.
>
> Vidas
>
>
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: outOfMemoryError
@ 2006-08-29 13:22  Vidas Makauskas <vms@centras.lt>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Vidas Makauskas @ 2006-08-29 13:22 UTC (permalink / raw)
  To: pgsql-jdbc

> Can you post your basic loop ?
>

ResultSet oracle = <"SELECT * FROM oracle">
ResultSet postgres = <SELECT oid,* FROM postgres WHERE oid=0>
ResultSetMetaData rsmd = postgres.getMetaData();
int vnt = rsmd.getColumnCount();
int rows = 0;
while (oracle.next()) {
<***** SEE BELLOW ******>
 postgres.moveToInsertRow();
 for (int i=1; i <= vnt; i++)
  if ( ! "oid".equals(rsmd.getColumnName(i)))
   if (oracle.getObject(rsmd.getColumnName(i)) != null)
    postgres.updateObject(i, oracle.getObject(rsmd.getColumnName(i)));
 postgres.insertRow();
}

> From what I can see your expectations are a little unrealistic how  do you 
> expect to process 10G rows at a time?
rows += 1;
if ( rows > 100000 ) {
 postgres = <SELECT oid,* FROM postgres WHERE oid=0>
 rsmd = postgres.getMetaData();
 rows = 0;
}





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: outOfMemoryError
@ 2006-08-29 16:59  Dave Cramer <pg@fastcrypt.com>
  parent: Vidas Makauskas <vms@centras.lt>
  0 siblings, 2 replies; 10+ messages in thread

From: Dave Cramer @ 2006-08-29 16:59 UTC (permalink / raw)
  To: Vidas Makauskas <vms@centras.lt>; +Cc: pgsql-jdbc

This design is limited by memory.

You would be far better off inserting directly instead of using a  
ResultSet

Dave
On 29-Aug-06, at 9:22 AM, Vidas Makauskas wrote:

>> Can you post your basic loop ?
>>
>
> ResultSet oracle = <"SELECT * FROM oracle">
> ResultSet postgres = <SELECT oid,* FROM postgres WHERE oid=0>
> ResultSetMetaData rsmd = postgres.getMetaData();
> int vnt = rsmd.getColumnCount();
> int rows = 0;
> while (oracle.next()) {
> <***** SEE BELLOW ******>
>  postgres.moveToInsertRow();
>  for (int i=1; i <= vnt; i++)
>   if ( ! "oid".equals(rsmd.getColumnName(i)))
>    if (oracle.getObject(rsmd.getColumnName(i)) != null)
>     postgres.updateObject(i, oracle.getObject(rsmd.getColumnName(i)));
>  postgres.insertRow();
> }
>
>> From what I can see your expectations are a little unrealistic  
>> how  do you
>> expect to process 10G rows at a time?
> rows += 1;
> if ( rows > 100000 ) {
>  postgres = <SELECT oid,* FROM postgres WHERE oid=0>
>  rsmd = postgres.getMetaData();
>  rows = 0;
> }
>
>
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org
>




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: outOfMemoryError
@ 2006-08-29 22:02  Luis Vilar Flores <lflores@evolute.pt>
  parent: Dave Cramer <pg@fastcrypt.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Luis Vilar Flores @ 2006-08-29 22:02 UTC (permalink / raw)
  To: pgsql-jdbc

I wrote a program for moving full databases between different db  
engines, the main loop for inserting is:

The main difference is that I use batch insert on prepared statements.

public class Move
{
	public static final int MAX_BATCH_ROWS = 4096;
	
	public static move( Connection CON_SRC, Connection CON_DEST, String  
table )
		throws Exception
	{
		Statement stm = CON_SRC.createStatement( ResultSet.TYPE_FORWARD_ONLY,
				ResultSet.CONCUR_READ_ONLY );
		ResultSet rs = statement.executeQuery( "SELECT * FROM " + table );
		StringBuffer buff = new StringBuffer( "INSERT INTO " );
		StringBuffer args = new StringBuffer();
		buff.append( table );
		buff.append( " ( " );
		ResultSetMetaData rsmd = rs.getMetaData();
		for( int j = 1; j <= rsmd.getColumnCount(); ++j )
		{
			if( j != 1 )
			{
				buff.append( ", " );
				args.append( ", " );
			}
			buff.append( rsmd.getColumnName( j ) );
			args.append( "?" );
		}
		buff.append( " ) VALUES ( " );
		buff.append( args );
		buff.append( " )" );
		String insert = buff.toString();
		PreparedStatement pstm = CON_DEST.prepareStatement( insert );
		System.out.println( "I: " + i + " " + TABLES[ i ] );
		int typesCache[] = new int[ rsmd.getColumnCount() + 1 ];
		for( int j = 1; j <= rsmd.getColumnCount(); ++j )
		{
			typesCache[ j ] = rsmd.getColumnType( j );
		}
		
		int rows = 0;
		while( rs.next() )
		{
			for( int j = 1; j < typesCache.length; ++j )
			{
				Object data = rs.getObject( j );
				pstm.setObject( j, rs.getObject( j ), typesCache[ j ] );
			}
			++rows;
			if( ( rows % MAX_BATCH_ROWS ) == 0 )
			{
				pstm.executeBatch();
			}
		}
		rs.close();
		pstm.close();
	}
		
}

Please have attention, this code was copy/paste from 2 classes (my  
program is multi-threaded for performance - async read/write and  
multiple tables at once)
This method works on at least 5 million rows.


Luis Flores

Analista de Sistemas

Evolute - Consultoria Informática

Email: lflores@evolute.pt

Tel: (+351) 212949689


AVISO DE CONFIDENCIALIDADE
Esta mensagem de correio electrónico e eventuais ficheiros anexos são  
confidenciais e destinados apenas à(s) pessoa(s) ou entidade(s) acima  
referida(s), podendo conter informação privilegiada e confidencial, a  
qual não poderá ser divulgada, copiada, gravada ou distribuída nos  
termos da lei vigente. Caso não seja o destinatário da mensagem, ou  
se ela lhe foi enviada por engano, agradecemos que não faça uso ou  
divulgação da mesma. A distribuição ou utilização da informação nela  
contida é interdita. Se recebeu esta mensagem por engano, por favor  
notifique o remetente e apague este e-mail do seu sistema. Obrigado.

CONFIDENTIALITY NOTICE
This e-mail transmission and eventual attached files are intended  
only for the use of the individual(s) or entity(ies) named above and  
may contain information that is both privileged and confidential and  
is exempt from disclosure under applicable law. If you are not the  
intended recipient, you are hereby notified that any disclosure,  
copying, distribution or use of any of the information contained in  
this transmission is strictly restricted. If by any means you have  
received this transmission in error, please immediately notify the  
sender and delete this e-mail from your system. Thank you.

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: outOfMemoryError
@ 2006-08-30 00:47  Kris Jurka <books@ejurka.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Kris Jurka @ 2006-08-30 00:47 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: Vidas Makauskas <vms@centras.lt>; pgsql-jdbc



On Tue, 29 Aug 2006, Dave Cramer wrote:

> This design is limited by memory.
>
> You would be far better off inserting directly instead of using a ResultSet

Actually I think there is a point to be made here.  If the ResultSet is 
not scrollable then there is no need to store all the inserts that are 
made to it, so there should be no memory limit.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: outOfMemoryError
@ 2006-08-30 12:36  Dave Cramer <pg@fastcrypt.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Dave Cramer @ 2006-08-30 12:36 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Vidas Makauskas <vms@centras.lt>; pgsql-jdbc


On 29-Aug-06, at 8:47 PM, Kris Jurka wrote:

>
>
> On Tue, 29 Aug 2006, Dave Cramer wrote:
>
>> This design is limited by memory.
>>
>> You would be far better off inserting directly instead of using a  
>> ResultSet
>
> Actually I think there is a point to be made here.  If the  
> ResultSet is not scrollable then there is no need to store all the  
> inserts that are made to it, so there should be no memory limit.

True, but this is hardly documented. It also suggests adding  
complexity for a special case.
>
> Kris Jurka
>
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>




^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2006-08-30 12:36 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-29 14:09 OutOfMemoryError rstepha1@nycap.rr.com
2005-08-29 19:00 ` Kris Jurka <books@ejurka.com>
2005-08-29 19:03 ` Marc Herbert <Marc.Herbert@emicnetworks.com>
2006-08-29 07:46 outOfMemoryError Vidas Makauskas <vms@centras.lt>
2006-08-29 12:05 ` Re: outOfMemoryError Dave Cramer <pg@fastcrypt.com>
2006-08-29 13:22   ` Re: outOfMemoryError Vidas Makauskas <vms@centras.lt>
2006-08-29 16:59     ` Re: outOfMemoryError Dave Cramer <pg@fastcrypt.com>
2006-08-29 22:02       ` Re: outOfMemoryError Luis Vilar Flores <lflores@evolute.pt>
2006-08-30 00:47       ` Re: outOfMemoryError Kris Jurka <books@ejurka.com>
2006-08-30 12:36         ` Re: outOfMemoryError Dave Cramer <pg@fastcrypt.com>

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