10

Has HSQLDB some mechanism for saving in-memory data to file?

As I know after the server is shutted down, all in-memory data become unaccessible. So I want to save all in-memory data to file. Unfortunately I can't use BACKUP mechanism, because it can't be applied for in-memory data.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user850155
  • 101
  • 1
  • 1
  • 4
  • I too want this feature. The fact that there isn't goes against "Unix Philosophy" where text should be pipeable into and out of a process. Bloatware wins again. – Sridhar Sarnobat Mar 21 '18 at 03:15

2 Answers2

9

HSQLDB databases are of different types. The all-in-memory databases do not store the data to disk. These databases have URLs in the form jdbc:hsqldb:mem:<name>.

If your database URL is in the form jdbc:hsqldb:file:<file path> and your tables are the default MEMORY tables, the data is all in memory but the changes are written to a set of disk files.

With all types of database, including all_in_memory, you can use the SQL statement SCRIPT <file path> to save the full database to a file. If you save the data to a file with the .script extension, you can open the file as a file database.

When you run a server, the URL's are used without the jdbc:hsqldb prefix, for example server.database.0=file:C:/myfile

See the guide here http://hsqldb.org/doc/2.0/guide/running-chapt.html#running_db-sect

fredt
  • 24,044
  • 3
  • 40
  • 61
  • Does HSQLDB write any temporary files to disk and then delete them, when I am using db URL as jdbc:hsqldb:mem: , and I am inserting a row into a table? I am deploying my Java Mule ESB application to cloudhub. It works fine on local but not on cloud. It seems cloudhub does not allow writing files. Application works fine when I comment out db insert and return dummy response. – RuntimeException Jun 14 '16 at 08:50
  • 1
    A mem: database (URL jdbc:hsqldb:mem:) does not write anything to the file system. – fredt Jun 14 '16 at 09:56
  • @fredt if we exclude temp files – Antoniossss Aug 17 '16 at 13:59
7

There is an SQL command for that. Try this:

SCRIPT '/tmp/data.sql'

See here for details.

Archie
  • 4,959
  • 1
  • 30
  • 36