WSO2 Governance Registry - Setting up Database - H2 [ Documentation Index ]

WSO2 Governance Registry - Setting up with H2 Database (Embedded and Remote)

Table of Contents

Setting up with remote H2 Database

Preparing the remote H2 DB.

Below are the steps for configuring WSO2 Governance Registry with H2 remote database.
  1. Download and install H2 DB in you computer, if it is not already done. You can find H2 installation guide from here.
  2. Goto the $H2_HOME/bin directory and run the h2 network server starting script. $H2_HOME is the installation directory of H2
  3. Run H2 database server with following commands. $ ./h2.sh $ h2.bat The script will start the database engine and bring up a pop up window with start browse button. "Start Browser" button will open a web browser containing a client application using which you can connect to a database. h2 will automatically create a database, if a database does not exist by the name you provide in the 'JDBC URL' text box.

Setup Configuration Files

  1. Edit the $CARBON_HOME/con/registry.xml file, where CARBON_HOME is the installation directory of the registry distribution. note the highlighted configurations, You may use your own database name, username and password
    <currentDBConfig>h2-db</currentDBConfig>
            <dbConfig name="h2-db">
                <url>jdbc:h2:tcp://localhost/~/registryDB</url>
                <userName>regadmin</userName>
                <password>regadmin</password>
                <driverName>org.h2.Driver</driverName>
                <maxActive>80</maxActive>
                <maxWait>6000</maxWait>
                <minIdle>5</minIdle>
           </dbConfig>
    
    Explanation of the database configuration options.
    • url: The URL of the database
    • userName: The name of the database user
    • password: The password of the database user
    • maxActive: The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
    • maxWait: The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.
    • minIdle: The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.
  2. Edit the $CARBON_HOME/conf/user-mgt.xml file as below (Note that you have to replace these settings with your custom values).
        <Database>
             <URL>jdbc:h2:tcp://localhost/~/registryDB</URL>
             <UserName>regadmin</UserName>
             <Password>regadmin</Password>
             <Dialect>H2</Dialect>
             <Driver>org.h2.Driver</Driver>
        </Database>
    

Setup Drivers

  1. Copy H2 database driver (org.h2.Driver) to $CARBON_HOME/repository/components/lib. One could find the required driver jar in $H2_HOME/bin/h2-*.jar

Create Database

Automatic Database Creation

  1. Next at the first time you start the registry, run with the -Dsetup option, so it will create the H2 database with all the underlying tables. sh wso2server.sh -Dsetup wso2server.bat -Dsetup

Manual Table Creation using scripts

  1. Tables can be manually created by logging into created database and running and following script in H2 shell or web console. CARBON_HOME/dbscripts/h2.sql
  2. After setting up the registry DB tables. start the server with below commands. sh wso2server.sh wso2server.bat

Setting up with embedded H2 Database

Preparing the Embedded H2 Database

Below are the steps for configuring WSO2 Governance Registry with H2 embedded database.
  1. Download and install H2 DB in you computer, if it is not already done. You can find H2 installation guide from here.

Setup configuration Files

  1. Edit the $CARBON_HOME/con/registry.xml file, where CARBON_HOME is the installation directory of the registry distribution. note the highlighted configurations, You may use your own database name, username and password.
        <currentDBConfig>h2-db</currentDBConfig>
            <dbConfig name="h2-db">
                <url>jdbc:h2:/path/to/db/registryDB</url>
                <userName>regadmin</userName>
                <password>regadmin</password>
                <driverName>org.h2.Driver</driverName>
                <maxActive>80</maxActive>
                <maxWait>6000</maxWait>
                <minIdle>5</minIdle>
           </dbConfig>
    
    Explanation of the database configuration options.
    • url: The URL of the database
    • userName: The name of the database user
    • password: The password of the database user
    • maxActive: The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
    • maxWait: The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.
    • minIdle: The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.
  2. Edit the $CARBON_HOME/conf/user-mgt.xml file as below (Note that you have to replace these settings with your custom values).
        <Database>
             <URL>jdbc:h2:/path/to/db/registryDB</URL>
             <UserName>regadmin</UserName>
             <Password>regadmin</Password>
             <Dialect>H2</Dialect>
             <Driver>org.h2.Driver</Driver>
         </Database>
    

Setup Drivers

  1. Copy H2 database driver (org.h2.Driver) to $CARBON_HOME/repository/components/lib. One could find the required driver jar in $H2_HOME/bin/h2-*.jar

Create Database

Automatic Database Creation

  1. Next at the first time you start the registry, run with the -Dsetup option, so it will create the H2 database with all the underlying tables. sh wso2server.sh -Dsetup wso2server.bat -Dsetup

Manual Table Creation using scripts

  1. Tables can be manually created by logging into created database and running and following script in H2 shell or web console. CARBON_HOME/dbscripts/h2.sql
  2. After setting up the registry DB tables. start the server with below commands. sh wso2server.sh wso2server.bat