Configure H2 on a Remote Server

Last modified by Eleni Cojocariu on 2026/10/23 17:57

Steps

Warning

H2 is not one of the databases XWiki supports, and serving it over TCP adds a second risk: H2's own documentation says to pair -tcpAllowOthers, the flag that opens the server to other machines, with a firewall and a strong password. Keep the port reachable only from the XWiki machine.

To run H2 on a separate machine and have XWiki reach it over TCP, instead of the embedded database Configure H2 sets up:

  1. Set XWiki up for H2 as described there first. The H2 jar goes into WEB-INF/lib on the XWiki machine either way.
  2. On the database machine, download the same H2 version and create the database locally, in the directory you will serve from. H2 refuses to create a database over a remote connection.
    $ java -cp h2-*.jar org.h2.tools.Shell -url jdbc:h2:/var/spool/javadb/h2/xwiki -user sa
  3. Start the H2 server there, pointing -baseDir at the directory holding that database.
    $ java -cp h2-*.jar org.h2.tools.Server -tcp -tcpAllowOthers -baseDir /var/spool/javadb/h2
  4. On the XWiki machine, point hibernate.connection.url at the server instead of at a local path. The database name is resolved against the server's -baseDir, so this URL opens the database you created above.
        <property name="hibernate.connection.url">jdbc:h2:tcp://remotehost/xwiki</property>
  5. Restart the application server.
  6. Verify that XWiki serves its pages, and that the database file on the server has grown past the empty database you created.
    $ ls -l /var/spool/javadb/h2
    -rw-r--r-- 1 h2 h2 23068672 Oct 23 18:02 xwiki.mv.db

FAQ

What if the database does not exist on the server?

XWiki fails to start and H2 answers Database "..." not found, either pre-create it or allow remote database creation. Do not reach for the server's -ifNotExists flag, which H2 warns opens a remote security hole next to -tcpAllowOthers.

Does the H2 version have to be the same on both machines?

Use the same major version on both. H2 changed its file format in 2.0, and the jar in WEB-INF/lib speaks the protocol of the server it was built for.

Related

Get Connected