Configuring JBoss to use PostgreSQL

These notes are based on JBoss 3.0.8 and PostgreSQL 7.4 running on Mandrake Linux 9.2.

For JBoss 3.2.6 see JbossPostgreSql32

  • I'm not sure which items are case-significant. Play safe and assume they all are!

  • Refer to the instructions at http://www.postgresql.org/docs/7.4/static/jdbc.html for details on obtaining the PostgreSQL JDBC driver.

  • Copy the appropriate JDBC driver to (e.g. pg74.1jdbc3.jar) to jboss/server/xxx/lib

  • Copy jboss/docs/examples/jca/postgres-service.xml to jboss/server/xxx/deploy directory

In the PostgreSQL data directory, amend postgresql.conf file to enable TCP/IP connections.

  • tcpip_socket = true

Also in the PostgreSQL directory, amend pg_hba.conf file to allow TCP/IP connections from the local host. (Note: This isn't secure. Read the very good PostgreSQL documentation.

  • host all all 127.0.0.1/32 trust

Make sure both these files have the correct ownership, otherwise the PostgreSQL server will fail to run. Owner should probably be something like postgres. Restart the PostgreSQL server.

Copy jboss/docs/examples/jca/postgres-service.xml to jboss/server/xxx/deploy directory

In the copied file, uncomment the line

  • <attribute name="SecurityDomainJndiName">PostgresDbRealm</attribute>

Amend the line containing the connection url to reflect your setup

  • <config-property name="ConnectionURL" type="java.lang.String">jdbc:postgresql://localhost:5432/tulip</config-property>

  • edit jboss/server/xxx/conf/login-config.xml as follows:

     <application-policy name = "PostgresDbRealm">
         <authentication>
             <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
                 <module-option name = "principal">yourprincipal</module-option>
                 <module-option name = "userName">yourusername</module-option>
                 <module-option name = "password">yourpassword</module-option>
                 <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=PostgresDS</module-option>
             </login-module>
         </authentication>
     </application-policy>
    

For a typical PostgreSQL setup, you probably only need to set the correct username.


Note: These instructions will leave JBoss using Hypersonic for the jbossmq persistence manager. Options to consider persuing are:

  • Change the "jdbc2" mq persistence manager to use the PostgreSQL datasource

  • Change jbossmq to use a non-jdbc persistence manager

  • Rename or copy the PostgreSQL datasource to DefaultDS


See also PostgreSQL, MySql, JbossHintsAndTips, JbossMySql

-- Frank Dean - 26 Sep 2004