Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutting down H2 database; Compact vs Defrag?

Tags:

java

h2

In my application, I connect to an H2 database and I've recently being looking into how this database is shutdown.

In my connection string I have set DEFRAG_ALWAYS=true, which according to H2 doc

Each time the database is closed, it is fully defragmented (SHUTDOWN DEFRAG).

Now I assume that when the JVM is shutting down, the shutdown hook will then shutdown the database and defragment it (as if executing SHUTDOWN DEFRAG).

But if I was to execute SHUTDOWN COMPACT before exiting the application, whilst having DEFRAG_ALWAYS=true applied in the connection string, Which shutdown process would be used?

like image 550
Java Devil Avatar asked Oct 07 '14 20:10

Java Devil


People also ask

What is a .H2 file?

H2 is an SQL database engine that is written in Java™ that implements the JDBC API. A browser-based console application is included. The H2 database is preinstalled with the Cúram software. After you install the Cúram platform software, the self-contained database is located in the %CURAMSDEJ%\drivers\h2. jar file.

Is H2 database case sensitive?

Text comparison in MySQL is case insensitive by default, while in H2 it is case sensitive (as in most other databases). H2 does support case insensitive text comparison, but it needs to be set separately, using SET IGNORECASE TRUE. This affects comparison using =, LIKE, REGEXP.


1 Answers

If you execute shutdown manually, then this has priority over the setting (defrag_always=true). So if you execute shutdown compact, then this is what is done, and the defrag is not done. If you execute shutdown defrag, then this is done, no matter what the setting. If you just close the database normally, then the setting defrag_always is used.

like image 150
Thomas Mueller Avatar answered Sep 21 '22 08:09

Thomas Mueller