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

查看:111
本文介绍了将内存中的 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'文件名' 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函数),然后使用create table as select 以持久化这些表.

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天全站免登陆