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):
| property | description |
|---|---|
para.db.dir | The data directory for storing DB files. Defaults to ./data. |
para.db.hostname | The hostname of the server. Setting this will enable H2’s “server mode” and starts a TCP server. Defaults to blank. |
para.db.user | The username with access to the database. Defaults to para. |
para.db.password | The password. Defaults to secret. |
para.db.tcpServer | Parameters for the H2 TCP server. Defaults to blank. |
The H2 web console
Section titled “The H2 web console”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.
Backup, restore and migration
Section titled “Backup, restore and migration”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 zipTo 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 zipWhen 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:
-
Stop Para.
-
Open a terminal in the
para_folder/datadirectory. -
Download the H2 JARs and back up the
paradatabase:Terminal window $ java -cp h2-{OLD_H2_VERSION}.jar org.h2.tools.Script -url jdbc:h2:./para -user para -password secret -script para.sql -
Delete the old files and create a new
paradatabase using the Shell tool:Terminal window $ rm para.mv.db para.trace.db$ java -cp h2-{NEW_H2_VERSION}.jar org.h2.tools.Shell -
Restore the backup to the newly created
paradatabase:Terminal window $ java -cp h2-{NEW_H2_VERSION}.jar org.h2.tools.RunScript -url jdbc:h2:./para -user para -password secret -script para.sql -
Start Para again.