Home » Java » Enterprise Java » PostgreSQL on Open Liberty

About Sebastian Daschner

Sebastian Daschner
Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.

PostgreSQL on Open Liberty

Open Liberty is an interesting new OSS Java EE application server that originated from WebSphere Liberty. You can configure Open Liberty to use PostgreSQL as its default data source as follows:

Add directives for <datasource>, <jdbcDriver>, and <library> to the server.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<server description="OpenLiberty Java EE 8 Server">


    <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443"/>
    <keyStore id="defaultKeyStore" password="Liberty"/>

    <!-- Postgres coffee-shop-db definition -->
    <dataSource id="DefaultDataSource"

        <properties serverName="coffee-shop-db"

    <jdbcDriver id="postgresql-driver"

    <library id="postgresql-library">
        <fileset id="PostgreSQLFileset" dir="/opt/ol/wlp/lib"


The database available via host coffee-shop-db will be accessed through the default Postgres port 5432 with postgres as database name, username and password.

The driver library, here postgresql-9.4-1201.jar, needs to reside in the lib/ directory of the server installation.

The default data source can be used transparently from a Java EE application. Only a single persistence unit needs to be specified in the persistence.xml file, similar to the following snippet:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"

    <persistence-unit name="prod" transaction-type="JTA"/>


If the application comprises multiple databases, the persistence units are required to specify the JNDI names of their corresponding data source.

Tested with the official Docker image open-liberty:javaee7.

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: PostgreSQL on Open Liberty

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments