Java 为什么我的嵌入式 h2 程序写入 .mv.db 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23806471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:16:58  来源:igfitidea点击:

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

javadatabasejdbch2

提问by FelixZett

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.

我按照 h2 数据库网站上的快速入门指南创建了一个新的数据库表并插入了一些数据。应用程序运行流畅,可以毫无问题地读写数据库。

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

快速入门 h2

  • 将 h2*.jar 添加到类路径(H2 没有任何依赖项)
  • 使用 JDBC 驱动类:org.h2.Driver
  • 数据库 URL jdbc:h2:~/test 在您的用户主目录中打开数据库 test
  • 自动创建一个新数据库

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?

现在我想用 web-frontend h2 控制台查看数据,但每次我尝试打开我的数据库时,它只会创建一个新数据库。

经过长时间的搜索,我注意到我的 Java-App,它使用 h2 嵌入式版本写入一个名为“.mv.db”的文件,而网络前端创建文件“.h2.db”(这对于我)

此外,当我的应用程序写入数据库时​​,它使用了大量空间(80MB 用于 ~600 个整数值)
我如何为我的嵌入式数据库使用“.h2.db”扩展名?

采纳答案by Daniel Ruf

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

自版本 1.4.177 Beta (2014-04-12) 起,此功能现已自动启用。

You can disable it by adding ;MV_STORE=FALSEand ;MVCC=FALSEto the database URL

您可以通过将;MV_STORE=FALSE和添加;MVCC=FALSE到数据库 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

默认情况下,启用 MV_STORE 选项,因此它使用新的 MVStore 存储。MVCC 设置默认设置为与 MV_STORE 设置相同的值,因此它也默认启用。为了进行测试,可以通过将“;MV_STORE=FALSE”和/或“;MVCC=FALSE”附加到数据库 URL 来禁用这两个设置。

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

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

您应该告诉我们您使用的 H2 的确切版本。

回答by Martin Wickman

.mv.db-files are for the upcoming/beta storage type "MVStore" for H2.

.mv.db-files 适用于 H2 即将推出的/测试版存储类型“MVStore”。

Here is from the http://www.h2database.com/html/changelog.html:

这是来自http://www.h2database.com/html/changelog.html

New table engine "org.h2.mvstore.db.MVTableEngine" that internally uses the MVStore to persist data. To try it out, append ";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine" to the database URL. This is still very experimental, and many features are not supported yet. The data is stored in a file with the suffix .mv.db.

新的表引擎“org.h2.mvstore.db.MVTableEngine”在内部使用 MVStore 来持久化数据。要试用它,请将“;DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine”附加到数据库 URL。这仍然是非常实验性的,许多功能尚不支持。数据存储在后缀为.mv.db的文件中 。