PostgreSQL is a fully SQL-Compliant relational database you can usewith Payara Server and with no commercial licensing requirements it is well suited for production environments.This blog will show you how to set up a new PostgreSQL installation on Ubuntu and connect to it from Payara Server.
To install PostgreSQL on Ubuntu based distributions:
Login to Postgres with the default account byrunning the commands:
sudo -i -u postgres
psql
You now need to set a password for the PostgreSQL user on the database. Do so with:
password postgres
and then enter the new password when prompted.
For full functionality of PostgreSQL, server instrumentation must be enabled, you do this by running the command in Postgres
CREATE EXTENSION adminpack;
You will notice there are two pools already.These are the default server pools and are not recommended for production usage.A new connection pool is needed forPostgreSQL, which you can create by clicking theNew button.
Now to create a connection pool. For this tutorial the admin console will be used, but this can be done using asadmin commands or web.xml. The pool name is how the connection pool is to bereferred to within Payara Server,for this tutorial I will call itpostgresqlpool. Set the resource type tojavax.sql.DataSourceand the database driver vendor to PostgreSQL. Then click Next.
On the nextpage,scroll down to the bottomwhere there is the additional properties table.There you must setthe following properties in order to be able to connect:
serverName– this is the location of the PostgreSQL server. Put in localhost.
User– the username for the database. In this case the default account which we edited earlier, postgres.
password–thepassword that you specified earlier. In production environments it is recommended that you use an alias. See Payara Documentationfor more details.
You can leave the rest of the fields blank for now.
You can test the connection byclicking the ping buttononce the pool has been created. For more information on connection pools see the blog post here.
Then go toResources → JDBC → JDBC Resourcesand click onNew.
Enter theJNDI namethat you wish tousewithin your applications and set the pool name to be that of the poolset up in the previous step.
Now, you can inject a reference to a datasource for the PostgreSQL database inside a managed component like this:
@Resource(lookup = "jdbc/postgrespool")
DataSource ds;
Note that you can only use resources in a web container or a managed bean (i.e. CDI beans,EJBs etc.).
adminpack offers capabilities for reading and writing files to and from the server. The most notable use case is PgAdmin. I’d suspect it doesn’t add any valuable function in the context of running a Payara connected to a PostgreSQL database server.
Hello, in case the payara and the postgres are on different hosts, what should be put in the ServerName field? the name of the postgres host or the IP of the postgres host
Goodbye Payara Community 6, on to the next chapter with Payara Community 7
With the November 2025 release, Payara community reached an important milestone. Payara Platform Community 6 received its final update […]
5 minutes
Cloud & Microservices
Patrik Duditš
14 Nov 2025
Devoxx BE 2025: It Only Starts with a Container & How Abstraction Becomes Reality
At Devoxx Belgium 2025, I was able to talk about what happens after you build your container. In theory, […]
5 minutes
Community
Luqman Saeed
12 Nov 2025
What’s New In The Payara Platform November 2025 Release?
The November 2025 release brings significant milestones across the Payara Platform family. This month includes Payara Platform Community 6.2025.11, […]
Can you say a little more about why “for full functionality server instrumentation must be enabled” with adminpack?
This refers to PostgreSQL advanced features, for more information see the PostgreSQL documentation at https://www.postgresql.org/docs/10/static/index.html.
Oh, so it’s not for a Payara feature?
No, its for PostgreSQL and is not a Payara feature. See the documentation link I posted before.
adminpack offers capabilities for reading and writing files to and from the server. The most notable use case is PgAdmin. I’d suspect it doesn’t add any valuable function in the context of running a Payara connected to a PostgreSQL database server.
Hello, in case the payara and the postgres are on different hosts, what should be put in the ServerName field? the name of the postgres host or the IP of the postgres host
Either will work. The ServerName can be the IP address, or a name that can resolved either by the hosts file or a DNS lookup.