This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

The following sections describe how to replace the default H2 databases with PostgreSQL. 

Step 1: Setting up a PostgreSQL database

Follow the steps below to set up a PostgreSQL database.

  1. Install PostgreSQL on your computer as follows:
  2. Start the PostgreSQL service using the following command:
  3. Create a database and the login role from a GUI using the PGAdminIII tool.
  4. To connect PGAdminIII to a PostgreSQL database server, locate the server from the object browser, right-click the client, and click Connect. This will show you the databases, tablespaces, and login roles as follows:
  5. To create a database, click Databases in the tree (inside the object browser), and click New Database.
  6. In the New Database dialog box, give a name to the database (for example: gregdb) and click OK.
  7. To create a login role, click Login Roles in the tree (inside the object browser), and click New Login Role. Enter the role name and a password.

    These values will be used in the product configurations as described in the following sections. In the sample configuration, gregadmin will be used as both the role name and the password.

  8. Optionally enter other policies, such as the expiration time for the login and the connection limit.
  9. Click OK to finish creating the login role.

Step 2: Connecting the server to a PostgreSQL database

Once you have setup the physical database as explained in the previous step, the next step is to enable the connectivity between your MB server and the database. This can be done by simply copying the relevant database drivers to your server, and then configuring the datasources in MB to link to the new database. See the instructions given below.

Copying the database drivers

Download the PostgreSQL JDBC4 driver and copy it to the <MB_HOME>/repository/components/lib/ directory.

Setting up datasource configurations

The connection between physical databases and the server is established through datasources. The master-datasources.xml file (stored in the <MB_HOME>/repository/conf/datasources directory) is the default datasource configuration file that is shipped with WSO2 products. In the case of WSO2 MB, since we use two databases (Carbon database for registry/user management data and the MB-specific database for storing MB data), the master-datasources.xml file should contain two separate datasource configurations corresponding to the two databases.

If you check the default master-datasources.xml file in the product, you will see that the configurations point to the embedded H2 databases. The following instructions explain how you can divert the default configurations to point to the external PostgreSQL database you created in step 1.

Follow the steps given below to replace the MB-specific datasource configuration with a new connection to a PostgreSQL database:

  1. Open the <MB_HOME>/repository/conf/datasources/master-datasources.xml file. This is where datasources are configured to point to the databases used by the Message Broker. This file consists of commented out configurations for datasources. The datasource configuration for PostgreSQL is among these. The changes made to this file must be done in both broker nodes.

  2. Uncomment or add the following configuration into the master-datasources.xml file. Update the JDBC URL to correctly point to your database and enter the username and password for the PostgreSQL database user with the proper permissions.

    <datasource>
              <name>WSO2_MB_STORE_DB</name>
              <jndiConfig>
                  <name>WSO2MBStoreDB</name>
              </jndiConfig>
              <definition type="RDBMS">
              <configuration>
                      <url>jdbc:postgresql://localhost/wso2_mb</url>
                      <username>postgres</username>
                      <password>postgres</password>
                      <driverClassName>org.postgresql.Driver</driverClassName>
                      <validationQuery>SELECT 1</validationQuery>
                      <validationInterval>30000</validationInterval>
                      <defaultAutoCommit>false</defaultAutoCommit>
                  </configuration>
              </definition>
    </datasource>

    The elements in the above configuration are described below:

    ElementDescription
    urlThe URL of the database. The default port for a DB2 instance is 50000.
    username and passwordThe name and password of the database user.
    driverClassNameThe class name of the database driver.
    validationQueryThe SQL query that will be used to validate connections from this pool before returning them to the caller.
    validationInterval The indication to avoid excess validation, and only run validation at the most, at this frequency (time in milliseconds). If a connection is due for validation, but has been validated previously within this interval, it will not be validated again.
    defaultAutoCommitSpecifies whether each SQL statement should be automatically committed when it is completed. By default, this element is set to false.
  3. For more information on other parameters that can be defined in the <MB_HOME>/repository/conf/datasources/master-datasources.xml file, see Tomcat JDBC Connection Pool.
  4. Open the <MB_HOME>/repository/conf/broker.xml file. This is the root configuration file of WSO2 MB. The changes made to this file must be done in all the MB nodes.

  5. In the broker.xml file we need to use the PostgreSQL message store and Andes context store. To do this, uncomment or add the following configuration.

    ...
    <persistence>
      <messageStore class="org.wso2.andes.store.rdbms.RDBMSMessageStoreImpl">
            <property name="dataSource">WSO2MBStoreDB</property>
      </messageStore>
    
      <andesContextStore    class="org.wso2.andes.store.rdbms.RDBMSAndesContextStoreImpl">
            <property name="dataSource">WSO2MBStoreDB</property>
      </andesContextStore>
    ...
    </persistence> 

    The elements in the above configuration are described below.

    • The fully qualified name of the respective implementation class should be defined under the class attributes of messageStore and andesContextStore elements. This implementation class will be used by MB to persist relevant information.

    • The <property> elements are used to define different properties for each store. The minimal property for starting each store is the dataSource property. Depending on the implementation, the required properties may differ.

Step 3: Creating database tables

To create the database tables, connect to the database that you created earlier and run the following scripts:

  1. To create tables in the MB-specific database (WSO2_MB), use the below script: <PRODUCT_HOME>/dbscripts/postgresql.sql.

  2. Restart the server.

You can create database tables automatically when starting the product for the first time by using the -Dsetup parameter as follows:

  • For Windows: <MB_HOME>/bin/wso2server.bat -Dsetup

  • For Linux: <MB_HOME>/bin/wso2server.sh -Dsetup
  • No labels