PostgreSQL as DefaultDS Tutorial
dayjah Apr 7, 2005 2:41 AMHi,
I am relatively new to JBoss 4 and have been attempting to remove the HyperSonic DB dependance and use Postgres instead. There is a startling lack of documentation surrounding this in JBoss 4! I have just now sucessfully managed to do this and here is my step by step on doing it.
I assume that you have installed JBoss and PostgreSQL. For reference's sake I'm using
OS: Solaris 9
Postgres: 7.4
JBoss: 4.0.2RC1
Step 1 - prep the db
as your postgres user create a db.
bash-2.05$ createdb jboss CREATE DATABASE
then still as your postgres user create a db user
bash-2.05$ createuser -P -D -A jboss Enter password for new user: password Enter it again: password CREATE USER
add a pg_hba.conf entry here if needed. In my instance even with jboss and postgres on the same box I needed an entry for the connection coming in on the local IP:
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD host jboss jboss 192.168.0.1 255.255.255.255 trust
Step 2 - prep the instance and its deploy
now as your jboss user/owner
bash-2.05$ cd ${JBOSS_HOME}/server bash-2.05$ cp -R default postgres bash-2.05$ cd local/deploy bash-2.05$ rm hsqldb-ds.xml bash-2.05$ cp ${JBOSS_HOME}/docs/examples/jca/postgres-ds.xml ./
Change the new local copy of postgres-ds.xml to be like the following, replacing your hostname, username, password as appropriate:
<datasources> <local-tx-datasource> <jndi-name>DefaultDS</jndi-name> <connection-url>jdbc:postgresql://test-server/jboss</connection-url> <driver-class>org.postgresql.Driver</driver-class> <user-name>jboss</user-name> <password>tester</password> <!-- sql to call when connection is created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql to call on an existing pooled connection when it is obtained from pool <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> --> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>PostgreSQL</type-mapping> </metadata> </local-tx-datasource> </datasources>
Some changes are needed in the jms directory of the deploy directory
bash-2.05$ cd jms bash-2.05$ rm hsqldb-jdbc2-service.xml bash-2.05$ mv hsqldb-jdbc-state-service.xml postgres-jdbc-state-service.xml bash-2.05$ cp ../../../../docs/examples/jms/postgres-jdbc3-service.xml ./
Find the code below in the postgres-jdbc3-service.xml file:
optional-attribute-name="ConnectionManager">jboss.jca:service=DataSourceBinding,name=PostgresDS</depends>
and edit it to read:
optional-attribute-name="ConnectionManager">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
Renaming hsqldb-jdbc-state-service.xml to postgres-jdbc-state-service.xml is purely for asthetic reasons. In a weaker moment I may think "arrgh I though I got rid of all this Hypersonic suff!"
Step 3 - prep the core configurations
All core configurations for an instance of jboss are below the conf directory. These need to be changed to use the new DS.
bash-2.05$ cd ${JBOSS_HOME}/server/postgres/conf
The file standardjbosscmp-jdbc.xml should read
<jbosscmp-jdbc> <defaults> <datasource>java:/DefaultDS</datasource> <!-- optional since 4.0 <datasource-mapping>Hypersonic SQL</datasource-mapping> --> <datasource-mapping>PostgreSQL</datasource-mapping>
The file standardjaws.xml should read
<jaws> <datasource>java:/DefaultDS</datasource> <type-mapping>PostgreSQL</type-mapping> <debug>false</debug>
Step 4 - configuration of binaries
Ensure you have an up to date jdbc driver for your version of postgres. Below this will be refered to as $PGJAR.
bash-2.05$ cd ../conf bash-2.05$ rm rm hsqldb* bash-2.05$ cp $PGJAR ./
Step 5 - home straight
bash-2.05$ cd ${JBOSS_HOME}/bin bash-2.05$ ./run.sh -c postgres &
a \dt in the jboss database should show you the following.
jboss=> \dt List of relations Schema | Name | Type | Owner --------+---------------------+-------+------- public | hilosequences | table | jboss public | jms_message_log | table | jboss public | jms_reference_log | table | jboss public | jms_roles | table | jboss public | jms_subscriptions | table | jboss public | jms_transaction_log | table | jboss public | jms_users | table | jboss public | timers | table | jboss (8 rows)
Thats all folks!
--
dayjah