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
Payara Cloud Is Now part of Payara Qube family of Unified Platforms for Enterprise Java
Payara Cloud is becoming part of Payara Qube family of Java application deployment runtimes. This move reflects how the […]
2 minutes
News
Chiara Civardi
21 Oct 2025
Enterprise Java Deployment Simplified with Payara Qube’s New, Unified Offering
Payara Services, a leading vendor of enterprise Java technologies, is aligning Payara Cloud with the Payara Qube Java application […]
3 minutes
Community
Luqman Saeed
15 Oct 2025
What’s New In The Payara Platform October 2025 Release?
The October 2025 release brings focused improvements across Payara Platform Community 6.2025.10 (download here), Payara Platform Enterprise 6.31.0 (download […]
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.