Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my embedded h2 program writing to a .mv.db file

I followed the quickstart guide on the h2 database website to create a new database a table and insert some data. The application runs smooth and can read and write to the database without problems.

Quickstart h2

  • Add the h2*.jar to the classpath (H2 does not have any dependencies)
  • Use the JDBC driver class: org.h2.Driver
  • The database URL jdbc:h2:~/test opens the database test in your user home directory
  • A new database is automatically created

Now i want to look at the data with the web-frontend h2 console but everytime I try to open my database it just creates a new database.

After a long search I noticed that my Java-App, which uses the h2 embedded version writes to a file called ".mv.db" while the web-frontend creates the file ".h2.db" (which makes much more sense for me)

Also when my App writes to the database it uses extreme amounts of space (80MB for ~600 integer values)
How can I use the ".h2.db" extension for my embedded database?

like image 477
FelixZett Avatar asked May 22 '14 12:05

FelixZett


People also ask

How does H2 connect to memory DB?

Accessing the H2 Console H2 database has an embedded GUI console for browsing the contents of a database and running SQL queries. By default, the H2 console is not enabled in Spring. Then, after starting the application, we can navigate to http://localhost:8080/h2-console, which will present us with a login page.

What is MV DB?

mv. db is the default. (The storage engine "MVStore" is used). The MVStore is still beta right now (November 2014). But you can disable the MVStore by appending ;mv_store=false to the database URL.

How do I open an embedded H2 database?

Connect to the embedded H2 database using the H2 console Alternatively you can connect using the browser based H2 console. The easiest way to access the console is to double click the H2 database jar file at <installation-directory>\confluence\WEB-INF\lib\h2-x.x.x.jar .


1 Answers

This is now automatically enabled since version 1.4.177 Beta (2014-04-12).

You can disable it by adding ;MV_STORE=FALSE and ;MVCC=FALSE to the database URL

By default, the MV_STORE option is enabled, so it is using the new MVStore storage. The MVCC setting is by default set to the same values as the MV_STORE setting, so it is also enabled by default. For testing, both settings can be disabled by appending ";MV_STORE=FALSE" and/or ";MVCC=FALSE" to the database URL.

http://www.h2database.com/html/changelog.html

You should tell us, what exact version of H2 you use.

like image 200
Daniel Ruf Avatar answered Sep 24 '22 17:09

Daniel Ruf