2

Is it possible to create an in-memory H2 database that is initialized with the contents of an on-disk H2 database, run some operations on it and then persist the in-memory database back into a database file?

The reason I want to do this is that I have some data processing (loading from external sources, calculating derived tables and creating indexes) that takes a long time using the on-disk database and I hope to speed this up by doing it in-memory.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • 2
    Related: http://stackoverflow.com/questions/9601038/saving-in-memory-h2-database-to-disk – Thilo Sep 13 '14 at 01:00

1 Answers1

1

Not directly, but you can accomplish this with the SCRIPT command.

First, open the on disk database. Next, dump it to a script file with SCRIPT TO 'initial.sql'. Next, open an in-memory database and import the script with RUNSCRIPT FROM 'initial.sql'. Operate on the database in memory, then script it out again with SCRIPT TO 'updated.sql'. Finally, run the updated script in a persistent database again.

ataylor
  • 64,891
  • 24
  • 161
  • 189