Out Of Memory Error: Java heap space

3,255 views
Skip to first unread message

Alexander.Sirenko

unread,
May 24, 2009, 4:04:20 PM5/24/09
to H2 Database
Hello,
I have some large table
wordforms(key INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
key_base INT,
name VARCHAR(50),
type VARCHAR(10),
isProcessed BOOLEAN )
with about 1 300 000 entries.

In my Java program I make query "SELECT key FROM wordforms" to get all
keys.
Executing query causes exception:

Exception in thread "Thread-7" java.lang.OutOfMemoryError: Java heap
space
at org.h2.value.Value.cache(Value.java:338)
at org.h2.value.ValueString.get(ValueString.java:91)
at org.h2.store.DataPage.readValue(DataPage.java:623)
at org.h2.table.TableData.readRow(TableData.java:620)
at org.h2.table.TableData.read(TableData.java:607)
at org.h2.store.DiskFile.getRecord(DiskFile.java:595)
at org.h2.store.Storage.getRecord(Storage.java:94)
at org.h2.index.ScanIndex.getNextRow(ScanIndex.java:258)
at org.h2.index.ScanCursor.next(ScanCursor.java:71)
at org.h2.table.TableFilter.next(TableFilter.java:318)
at org.h2.command.dml.Select.queryFlat(Select.java:491)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:
559)
at org.h2.command.dml.Query.query(Query.java:233)
at org.h2.command.CommandContainer.query(CommandContainer.java:
81)
at org.h2.command.Command.executeQueryLocal(Command.java:141)
at org.h2.command.Command.executeQuery(Command.java:122)
at org.h2.jdbc.JdbcStatement.executeQuery(JdbcStatement.java:
75)

// NetBeans error message

I use h2.1.1.111 in embedded mode.
I tried different CACHE_SIZE from CACHE_SIZE=25000 to
CACHE_SIZE=200000

Database includes other tables and it is more than 1.5Gb

Steve McLeod

unread,
May 25, 2009, 2:53:15 AM5/25/09
to H2 Database
Hi Alexander,

Can you post your database connection url?

My guess is that you have an in-memory database and are using the
default Java memory configuration. If that's the case, you'll need to
start up your program with increased heap size.

Regards,

Steve

On May 24, 10:04 pm, "Alexander.Sirenko" <alexander.sire...@gmail.com>
wrote:

Alexander.Sirenko

unread,
May 25, 2009, 8:34:53 AM5/25/09
to H2 Database
My connection string is "jdbc:h2:file:c:\\db/tesh2;CACHE_SIZE=50000".
I think, my database stored on disk.

Dror

unread,
May 26, 2009, 3:04:40 PM5/26/09
to H2 Database
You should
increase your Heap memory.
try to add the following to your java command line.
XX:MaxPermSize=128m -Xms256m -Xmx1024m
Regards
Dror

On May 25, 3:34 pm, "Alexander.Sirenko" <alexander.sire...@gmail.com>
wrote:
> > > Database includes other tables and it is more than 1.5Gb- Hide quoted text -
>
> - Show quoted text -

Thomas Mueller

unread,
May 30, 2009, 4:55:24 AM5/30/09
to h2-da...@googlegroups.com
Hi,

Could you post a reproducible test case? I can't reproduce the problem
so far. My test case is:

import java.sql.*;
import org.h2.tools.DeleteDbFiles;
public class Test {
public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
DeleteDbFiles.execute("~", "test", true);
Connection conn = DriverManager.getConnection(
"jdbc:h2:~/test", "sa", "sa");
Statement stmt = conn.createStatement();
stmt.execute("create table wordforms(key INT " +
"NOT NULL PRIMARY KEY AUTO_INCREMENT, " +
"key_base INT, name VARCHAR(50), " +
"type VARCHAR(10), isProcessed BOOLEAN)");
PreparedStatement prep = conn.prepareStatement(
"insert into wordforms values(?, ?, space(30)||?, ?, true)");
System.out.println("inserting");
for (int i = 0; i < 1300000; i++) {
if (i % 100000 == 0) {
System.out.println(i);
}
prep.setInt(1, i);
prep.setInt(2, i);
prep.setInt(3, i);
prep.setInt(4, i);
prep.execute();
}
System.out.println("selecting");
ResultSet rs = stmt.executeQuery(
"select key from wordforms");
for (int i = 0; rs.next(); i++) {
if (i % 100000 == 0) {
System.out.println(i);
}
rs.getInt(1);
}
System.out.println("done");
conn.close();
}
}

Regards,
Thomas

priyanka

unread,
Oct 18, 2012, 9:55:56 AM10/18/12
to h2-da...@googlegroups.com
hello sir,

Iam using latest version h2 database h2-1.3.169
I have deleted some tables from my H2 database...Now i want to shrink the empty spaces..
but according to forums i got the information as
H2 doesn't shrink the data, or index files so it's possible there is empty space in it.

so i can use script files for for it to take backup.sql
and again run the script
This is my url
jdbc:h2:tcp://localhost/~/abc;mvcc=true;lock_timeout=100000;lock_mode=0;auto_reconnect=true;auto_server=true;AUTOCOMMIT=OFF

But iam getting an exception as
Out of memory.; SQL statement:
SCRIPT


  1. How to increase the memory and how to run the script successfully
  2. Is this really help full in place of shrinking the data or we can any other method...to shrink the empty space

Please help me...as soon as possible ....Thanks in advance...

 iam getting an exception as

Out of memory.; SQL statement:
SCRIPT [90108-169]
90108/90108 (Help)
org.h2.jdbc.JdbcSQLException: Out of memory.; SQL statement:
SCRIPT [90108-169]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:158)
    at org.h2.message.DbException.convert(DbException.java:275)
    at org.h2.command.Command.executeQuery(Command.java:195)
    at org.h2.server.TcpServerThread.process(TcpServerThread.java:308)
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:149)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

    at org.h2.engine.SessionRemote.done(SessionRemote.java:567)
    at org.h2.command.CommandRemote.executeQuery(CommandRemote.java:151)
    at org.h2.jdbc.JdbcStatement.executeQuery(JdbcStatement.java:76)
    at org.h2.tools.Script.process(Script.java:172)
    at org.h2.tools.Script.execute(Script.java:153)
    at org.h2.tools.Script.execute(Script.java:133)
    at org.h2.tools.Script.runTool(Script.java:101)
    at org.h2.server.web.WebApp.tools(WebApp.java:390)
    at org.h2.server.web.WebApp.process(WebApp.java:235)
    at org.h2.server.web.WebApp.processRequest(WebApp.java:164)
    at org.h2.server.web.WebThread.process(WebThread.java:137)
    at org.h2.server.web.WebThread.run(WebThread.java:93)
    at java.lang.Thread.run(Unknown Source)


Noel Grandin

unread,
Oct 18, 2012, 9:59:34 AM10/18/12
to h2-da...@googlegroups.com, priyanka
remove the autocommit=off part of your URL.

Thomas Mueller

unread,
Oct 18, 2012, 2:25:10 PM10/18/12
to h2-da...@googlegroups.com
Hi,

You should also remove the lock_mode=0 part, unless you are 100% sure you need it. See the FAQ for details.

Regards,
Thomas


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

priyanka priya

unread,
Oct 19, 2012, 1:13:08 AM10/19/12
to h2-da...@googlegroups.com

Thank you so much for replying sir,

I have tried with dis 2 urls then also iam facing the same exception

jdbc:h2:tcp://localhost/~/abc;

jdbc:h2:tcp://localhost/~/abc;mvcc=true;lock_timeout=100000;auto_reconnect=true;auto_server=truePlease help me...

Thomas Mueller

unread,
Oct 19, 2012, 1:34:17 AM10/19/12
to h2-da...@googlegroups.com
Hi,

I'm not sure if you got my previous mail in which I wrote "Could you post a reproducible test case? I can't reproduce the problem"

Regards,
Thomas

Noel Grandin

unread,
Oct 22, 2012, 3:18:42 AM10/22/12
to h2-da...@googlegroups.com, priyanka priya
Your best bet at debugging out of memory problems is to

(1) add the -XX:+HeapDumpOnOutOfMemoryError  option to your command line

(2) run the program. when it crashes, it will produce a file with a name like java_1305.hprof

(3) analyze the dump with something like Eclipse MAT:
http://blog.bosch-si.com/how-to-analyze-leaky-webapps/
http://www.slideshare.net/BonitaSoft/first-steps-with-mat
Reply all
Reply to author
Forward
0 new messages