将内存中的H2数据库保存到磁盘 [英] Saving in-memory H2 database to disk

查看:1272
本文介绍了将内存中的H2数据库保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以二进制方式将完整的嵌入式h2内存数据库保存/加载到某些文件或目录中,以加快加载速度.

How can I save/load full embedded h2 in-memory database to some file or directory in binary mode for faster loading.

我想用它来缓存数据,所以不必每次都运行create table/insert子句的所有行.

I want to use this for caching data so I don't have to run all the lines of create table/insert clauses every time.

推荐答案

可以使用常规(持久性)数据库代替内存数据库.即使这样,您仍然可以使用内存表(创建内存表).

Instead of using an in-memory database, you could use a regular (persisted) database. You can still use in-memory tables even then (create memory table).

将完全内存数据库保存到磁盘的最简单方法是使用 SCRIPT TO 'fileName' SQL语句.这将创建一个SQL脚本.数据以文本形式存储,这听起来并不是最有效的解决方案.但是通常瓶颈始终是磁盘,而不是格式化/解析文本.

The easiest way to persist a completely in-memory database to disk is to use the SCRIPT TO 'fileName' SQL statement. This will create an SQL script. The data is stored in text form, which doesn't sound like the most efficient solution. However usually the bottleneck is the disk anyway and not formatting / parsing the text.

另一种选择是创建另一个数据库,将表与内存数据库链接(使用创建链接表 link_schema 函数),然后使用创建表作为选择以保留表.

Another option is to create another database, link the tables with the in-memory database (using create linked table or the link_schema function), and then use create table as select to persist the tables.

这篇关于将内存中的H2数据库保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆