How to convert H2 database to v2 format

How to convert H2 database to v2 format#

nJAMS Server 5.2 and 5.3 come with a new format of the internal H2 database. nJAMS installer will automatically migrate the H2 database format from v1 to v2, when an update is performed from nJAMS Server 5.1.

In case you prefer to install a new nJAMS Server instance in parallel to you existing instance and you want to manually switch from the old instance to the new instance, you have to manually convert the existing H2 database from v1 to v2. Or there might be case where the installer will reject to convert the database, if no sufficient space is available. You can then copy the old database to a system or drive with sufficient space and run the conversion there.

This chapter is about the instructions you have to follow to convert the internal nJAMS H2 database from v1 to v2.

Note

If you are using any other relational database system, such as Oracle, SQL Server, or PostgreSQL, these steps are NOT required. The migration is only required, if are on H2 database in format v1.

Introduction#

Starting with version 5.2 nJAMS Server introduced a new version of H2 database (v2), which is not compatible to its old format.

The actual conversion procedure is quite simple:

  1. Export the old database into a SQL script file

  2. Import the SQL script into the new database.

This approach is actually the same as when doing a full-rebuilding of the H2 in the maintenance case, except that the import is done with a different database version than the export.

Prerequisites#

Java needs to be installed and must be available on the search path. Otherwise you need to use the full Java executable path with the following commands.

Instructions#

  1. If applicable, copy the old H2 database file njams.mv.db from the nJAMS installation (typically .../njams/data/h2) into a work folder with the same amount of free space as the original database’s size.

  2. Copy both the old h2-1.4.193.jar and the new h2-2.1.210.jar H2 JDBC driver files into a work folder on the same drive as the database file from step 1.

  3. Run the export using the following command in the work folder containing the JDBC driver. Please note that this command uses the old (1.4.193) JDBC driver and references the original v1 database!

    java -cp h2-1.4.193.jar org.h2.tools.Script -url "jdbc:h2:file:/path/to/db/njams;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=FALSE;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=2" -user admin -password secret123 -script njams.sql.zip -options compression zip
    

    The command creates njams.sql.zip file as output.

  4. Run the import into the new database using the following command.

    Please note that this command uses the new (2.1.210) JDBC driver and the new database name (njams-v2) as well as a compatibility option that allows importing old format data.

    java -cp h2-2.1.210.jar org.h2.tools.RunScript -url "jdbc:h2:file:/path/to/db/njams-v2;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=FALSE;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=1" -user admin -password secret123 -script njams.sql.zip -options compression zip FROM_1X
    
  5. After that, the new v2 database file can found in the selected path: njams-v2.mv.db