Adding PostgreSQL 9.5 datasources to WildFly 10

In my current project I intend to use PostgreSQL 9.5 as a datasource for my Java EE Application that will be running in the WildFly 10.0.0.Final Application Server. In my scenario both PostgreSQL and WildFly are installed and running on an Ubuntu server on my LAN. This server has no GUI. I have posted my install notes for both PostgreSQL 9.5 and WildFly 10 on an Ubuntu 15.10 server here:

These install notes presume you have followed my directions in the URIs above.

In these install notes I’d like to connect my WildFly server to my PostgreSQL database so that my application can make use of the database via the datasources exposed in the WildFly application server. Or, put another way, I’d like to “wire up” my WildFly server to use my PostgreSQL database.

My WildFly is installed at /srv/wildfly. We’ll create the base database “module” there. In this case a module is just an xml file and associated jar file in a proper location in the wildfly directory tree.

cd /srv/wildfly/modules

mkdir -p org/postgres/main

cd org/postgres/main

Get the JDBC driver from

wget –tries=0 –continue

Create the module.xml file:

vi module.xml

Add these contents to the module.xml file:

<?xml version=”1.0″ ?>

<module xmlns=”urn:jboss:module:1.1″ name=”org.postgres”>

<resource-root path=”postgresql-9.4.1207.jar”/>

<module name=”javax.api”/>
<module name=”javax.transaction.api”/>
<module name=”javax.servlet.api” optional=”true”/>

In the above module setup the name of the jdbc jar file in the resource-root element of the module.xml file (postgresql-9.4.1207.jar in this case) must match the exact name of the jar file you downloaded from in case you have to upgrade the jdbc driver later.

NOTE (Alternate way to create this module): –>  Creating the org.postgres module as above may not be the preferred way to install a module/driver in the future. There is an alternate way using the program found in the bin directory of your WildFly installation:

# cd /temp
# wget –tries=0 –continue
# cd /srv/wildfly/bin
# ./
[disconnect] connect
[yourhost:9990] module add –name=org.postgres –resources=/tmp/postgresql-9.4.1207.jar –dependencies=javax.api,javax.transaction.api
[yourhost:9990] /subsystem=datasources/jdbc-driver=postgres:add(driver-name=”postgres”,driver-module-name=”org.postgres”,driver-class-name=org.postgresql.Driver)
[yourhost:9990] \q


Make sure all the files associated with the WildFly server (espcially the new module we just created) belong the wildfly user:

chown -R wildfly.wildfly /srv/wildfly*

Now we need to make some edits to our standalone-full.xml file:

cd /srv/wildfly/standalone/configuration

cp standalone-full.xml standalone-full.xml.backup

Copy this snippet into the <datasources><drivers> section of standalone-full.xml:

<driver name=”postgres” module=”org.postgres”>

Copy this snippet into the <datasources> section of standalone-full.xml:

<datasource jndi-name=”java:jboss/datasources/PgDsWildflyDb” pool-name=”PgDsWildflyDb” enabled=”true” use-java-context=”true”>

<xa-datasource jndi-name=”java:jboss/datasources/PgDsXaWildFlyDb” pool-name=”PgDsXaWildflyDb” enabled=”true”

<xa-datasource-property name=”ServerName”>localhost</xa-datasource-property>
<xa-datasource-property name=”PortNumber”>5432</xa-datasource-property>
<xa-datasource-property name=”DatabaseName”>wildflyDb</xa-datasource-property>

<exception-sorter class-name=”org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter”>

Save your changes and restart the server and now your web application can make use of these datasources. My guess is that your application will most likely use the regular datasource but I’ve also added the xa-datasource as I have application where this is handy.

2 thoughts on “Adding PostgreSQL 9.5 datasources to WildFly 10

Comments are closed.