Skip to content

H2 DB

This is the default database for object storage since v1.25. It is lightweight and embedded, which speeds up the startup of the server. All tables are stored inside a ./data folder by default. Keep in mind that each app has its own table which is created automatically when the app is created.

The implementing class H2DAO is part of the para-dao-sql plugin.

There are several configuration properties for H2 (these go in your para-application.conf file):

propertydescription
para.db.dirThe data directory for storing DB files. Defaults to ./data.
para.db.hostnameThe hostname of the server. Setting this will enable H2’s “server mode” and starts a TCP server. Defaults to blank.
para.db.userThe username with access to the database. Defaults to para.
para.db.passwordThe password. Defaults to secret.
para.db.tcpServerParameters for the H2 TCP server. Defaults to blank.

Browsing the data stored in H2 is relatively simple. Any JDBC-compatible client will work. You can also download the H2 JAR package and execute the command java -jar h2*.jar. This will open up the web console where you can open the Para DB file. The default credentials are:

  • JDBC URL: jdbc:h2:file:/para_folder/data/para
  • User name: para
  • Password: secret

The URL for your DB file will be different and it should not end with .mv.db.

H2 web console showing the Para database tables

To make a backup copy of the entire Para dabatase, including all child app tables, run this command:

java -cp h2*.jar org.h2.tools.Script -url jdbc:h2:file:/para_folder/data/para -user para -password secret -script para.zip -options compression zip

To restore an existing backup, run:

java -cp h2*.jar org.h2.tools.RunScript -url jdbc:h2:file:/para_folder/data/para -user para -password secret -script para.zip -options compression zip

When upgrading to a new version of the H2 library, you might get an exception like Unsupported type 17 [1.4.200/3] and java.lang.IllegalStateException: Unable to read the page at position 2080825755576522. This means that you’re trying to access an H2 database with a version incompatible with the H2 version used by the para-dao-sql plugin. You can either downgrade the plugin version or migrate the H2 database to the new version.

Migrating an old version of the H2 database to a new one requires you to first backup the data using the old H2 engine JAR, then restore the data using the new engine JAR like so:

  1. Stop Para.

  2. Open a terminal in the para_folder/data directory.

  3. Download the H2 JARs and back up the para database:

    Terminal window
    $ java -cp h2-{OLD_H2_VERSION}.jar org.h2.tools.Script -url jdbc:h2:./para -user para -password secret -script para.sql
  4. Delete the old files and create a new para database using the Shell tool:

    Terminal window
    $ rm para.mv.db para.trace.db
    $ java -cp h2-{NEW_H2_VERSION}.jar org.h2.tools.Shell
  5. Restore the backup to the newly created para database:

    Terminal window
    $ java -cp h2-{NEW_H2_VERSION}.jar org.h2.tools.RunScript -url jdbc:h2:./para -user para -password secret -script para.sql
  6. Start Para again.