Sidebar

How to recover corrupt H2 database

0 votes
14.2K views
asked Nov 26, 2014 by rich-c-2789 (16,180 points)
How to recover corrupt H2 database

1 Answer

0 votes
 
Best answer

If an H2 database is corrupted you may see following errors:

In the logs:

...Cannot open connection

...

Caused by: java.lang.RuntimeException: page[139109] data leaf table:358 T358 entries:2 parent:144065 keys:[14571, 14572] offsets:[1354, 724] parent 144065 expected 263693

When this happens the browser may return a 503 error

To attempt to recovery the database execute the follwing commands at a windows command prompt.  The h2 jar matching the version of the database is required.  Either place a copy in C:\ProgramData\QIE\h2 or adjusts the commands below to point to its location.

cd C:\ProgramData\QIE\h2
java -cp h2*.jar org.h2.tools.Recover

mkdir old
move qie.h2.db old\qie.h2.db
move qie.trace.db old\qie.trace.db
java -cp h2*.jar org.h2.tools.RunScript -url jdbc:h2:./qie -user sa -script qie.h2.sql
del qie.h2.sql

 

 

 

answered Nov 26, 2014 by rich-c-2789 (16,180 points)
selected Nov 26, 2014 by michael-h-5027
...