Get Database already closed when calling SHUTDOWN COMPACT

575 views
Skip to first unread message

Uwe

unread,
Nov 6, 2009, 6:13:08 AM11/6/09
to H2 Database
Hi,

I'm using lastest H2 ( 1.2.122 ) mainly because I need new feature
COMPACT to reduce file size after deleting rows.

I'm not sure how to use this feature however. When calling SHUTDOWN
COMPACT, I'll just get an exception telling me that the database is
already closed.

I've tried this call from Shell, Web Console and sql script with all
the same result. The DB files didn't get shrinked in any case.

How do I need to use this feature? Thx for helping....

Uwe

andrepintorj

unread,
Nov 6, 2009, 1:37:19 PM11/6/09
to H2 Database
The same problem here. The database doesn't shrink and after calling
it, I have the message "database already closed".

Thomas Mueller

unread,
Nov 9, 2009, 3:20:20 PM11/9/09
to h2-da...@googlegroups.com
Hi,

What you see is a bit strange, but it's not a bug.

This alone doesn't throw the exception:
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("shutdown compact");
stat.close();
conn.close();

But the H2 Console and other tools do this:

stat.execute("shutdown compact");
stat.getUpdateCount();

The getUpdateCount() method throws an exception because after calling
"shutdown" the database is closed, so calling getUpdateCount() is
technically illegal.

The database doesn't shrink because most likely it is already at it's
minimal size. Whenever the database is closed normally, it is
compressed for up to 1 second by default - see
http://www.h2database.com/javadoc/org/h2/constant/SysProperties.html#h2.maxCompactTime

Of course you can compress it further with tools such as 'zip', but
then the database is no longer usable (random access writes are very
very slow in compressed files).

Regards,
Thomas

andrepintorj

unread,
Nov 10, 2009, 1:00:16 PM11/10/09
to H2 Database
Thanks Thomas for the explanation.

Regards,
André Pinto
Reply all
Reply to author
Forward
0 new messages