Use PostgreSQL with WildFly

Tested with WildFly 15 and PostgreSql 11

Use PostgreSQL with WildFly

Download the PostgreSQL driver:

Download a compatible drive with your instance:
e.g. PostgreSQL JDBC 4.2 Driver, 42.2.5

Add PostgreSQL to WildFly

In [WILDFLY_HOME]/modules
create the directory:
and copy the jdbc file.

Create the module in WildFly

In /org/postgresql/main
create the module.xml file

<?xml version='1.0' encoding='UTF-8'?> 
<module xmlns="urn:jboss:module:1.1" name="org.postgresql"> 
    <!--the name of your driver --> 
        <resource-root path="postgresql-42.2.5.jar"/> 
        <module name="javax.api"/> 
        <module name="javax.transaction.api"/> 
  • change the filename according to your jdbc driver

In alternative you can use the Wildfly CLI:
module add --name=org.postgresql --resources=[JDBC_FILE_PATH]postgresql-42.2.5.jar --dependencies=javax.api,javax.transaction.api

Add the datasource

In our case we use the standalone instance of WildFly.

  • Open [WILDFLY_HOME]/standalone/configuration/standalone.xml
  • Locate the existing datasources:
<subsystem xmlns="urn:jboss:domain:datasources:5.0"> 
  • add the postgresql datasource, update according to your configuration
    <driver name="postgresql" module="org.postgresql"> 
    <!-- 1. chose your connection driver --> 
<!-- 2. use your configuration --> 
<datasource jndi-name="java:/PostgresDS" pool-name="PostgresDS"> 

In the section <datasources><drivers> add

 <driver name="org.postgresql" module="org.postgresql"/> 

Restart the server and enjoy!

As alternative you can use the WildFly UI:

  • add your user to your instance

Add the Datasource in:


WFLYJCA0047: Connection is not valid

The inclusion of the datasource-class in your configuration e.g.


could throw the following error: WFLYJCA0047: Connection is not valid

here some references about this problem: