Simple setup for testing - shesse/h2ha GitHub Wiki

H2HA achieves high availability by running two connected servers on separate hardware. If one fails, the other takes over.

However, for testing it makes some sense, to run both server processes on the same hardware. To do so, we need:

  • separate database port numbers for the two servers - we will use 9093 and 9094

  • separate HA control ports for the two servers - we will use 8235 and 8236

  • separate directories for storing H2 database files - we will use 'dbdir-a' and 'dbdir-b'

  • two console windows to run the two servers - we will name them 'A' and 'B'

  • create the DB directories:
    mkdir dbdir-a dbdir-b

  • start the first server within console window 'A':

    java -Dstderr.threshold=INFO -jar h2ha-server-*.one-jar.jar server
    -haBaseDir dbdir-a -haListenPort 8235 -haPeerHost localhost -haPeerPort 8236 -tcpPort 9093

  • start the second server within console window 'B':

    java -Dstderr.threshold=INFO -jar h2ha-server-*.one-jar.jar server
    -haBaseDir dbdir-b -haListenPort 8236 -haPeerHost localhost -haPeerPort 8235 -tcpPort 9094`

That's it. You should see some messages on the console window indicating the operation of the HA system. Try stopping and starting on or the other server to watch it changing roles and maintaining a single active database server on one or the other side.

For creating a database on the new server see Creating a database. However, the command described there assumes that the server instances run on different hosts and use the same control port number. For the single host setup, you must use only one host name (localhost) and the port number of the master server:

java -jar h2ha-server-*.one-jar.jar create \
  -server localhost -database dbname -user sa -password sa -haControlPort 8235

For accessing the server see Using the database. The URL is
jdbc:h2ha:tcp://localhost:9093,localhost:9094/dbname and the JDBC driver is com.shesse.jdbcproxy.Driver.