Documentation Home

Switch to PostgreSQL Tutorial

This tutorial will detail how to set up PostgreSQL for use with Broadleaf. By the end of this tutorial you will have completed:

  • PostgreSQL running locally on your development machine
  • Heat Clinic demo data loaded into PostgreSQL
  • Some idea of tooling around how to view the Heat Clinic data in PostgreSQL

Broadleaf works with a minimum PostgreSQL version of 9.2. We recommend using the latest version.

Download and install PostgreSQL


  1. Download the PostgreSQL installer from
  2. Execute the installer. As apart of setup, take note of the password for the postgres user that is created and the port number PostgreSQL listens on (the default is 5432)
  3. At the end, the installer will prompt you to run Stackbuilder. This is not a required step but will allow you to install additional tools

To verify the installation, open the pgadmin3 application and connect to the database with the postgres user and the previously-set password. Once you have logged in, you can add an additional login user to the database for Broadleaf to use.


The easiest way is to use Homebrew. After Homebrew is installed, you can install PostgreSQL by opening a Terminal and executing:

brew install postgresql
brew tap homebrew/services
brew services restart postgresql

The last 2 commands install the Homebrew services module that allows for easier manipulation of the Postgresql daemon.

To verify the installation, download and install the latest pgAdmin3 GUI. You can connect to the running PostgreSQL database with your OSX user and password. Once you login, you can modify the "Login roles" to change the password associated with your user, or create a new user for Broadleaf.


Use your favorite package installer to install PostgreSQL e.g.

apt-get install postgresql postgresql-contrib

After installation, the server should already be started up and able to be manipulated as a service (e.g. sudo service postgresql restart). No password is set by default, so run this command to connect to the server as the postgres user with sudo -u postgres psql postgres and change the password with \password postgres, entering it when prompted. For example:

ยป sudo -u postgres psql postgres
psql (9.4.7)
Type "help" for help.

postgres=# \password postgres
Enter new password:
Enter it again:

Create a new database schema

Create a new schema in the database (e.g. broadleaf). This is not required, you can also use the default public schema.

Add the MySQL client driver dependency

In your root pom.xml, find the following in the <dependencies> section under the <plugin> with <groupId>org.apache.tomcat.maven</groupId>


and replace it with


Remove the HSQLDB startup execution

Since you will no longer be using HSQLDB, in the root pom.xml file, you can remove the task definitions that start and shutdown HSQLDB. Look for <id>hsqldb-start</id> and <id>hsqldb-stop</id>. Delete both of those executions.

Also, if you are using the commands in the site and admin projects, you should delete the antrun:run@hsqldb-start section. For instance, given the line that looks like:

MAVEN_OPTS="$MAVEN_OPTS $BROADLEAF_OPTS" mvn antrun:run@hsqldb-start tomcat7:run-war

Replace it with:


Update the Hibernate dialect

Add the following dialect definitions to core/src/main/resource/runtime-properties/ to use the correct dialect for PostgreSQL


Enterprise and Multi-Tenant

You will need to update a 4th location:


Use the correct Heat Clinic demo SQL extractor

  1. In order to correctly import the Heat Clinic demo data, you will need to add a special extractor that ensures compatibility with Postgres in the demo SQL imports. Add this property to core/src/main/resources/runtim-properties/

Enterprise and Multi-Tenant


Update the database connection properties

Update your to connect to your MySQL database. In, you will want to update the following:

# your local database username, just a user that has readwrite permissions
# local database password
# this connection URL assumes that it is connecting to a schema called broadleaf

Note: database.driver and database.url have been changed from HSQLDB to PostgreSQL.
Note: this assumes that you are using the default postgres database. Make sure you use your database name in the url if it is different.

Update runtime properties to create the initial schema

It is likely that you will still need to initialize and seed the new MySQL schema. Ensure that these properties are set in either site/src/main/resources/runtime-properties/

After starting up the site project once, you can change all of these back to update so that any data changes stay intact.

And that's it! You should now be up and running with PostgreSQL.


I cannot connect to PostgreSQL with pgAdmin

Check the log files in to see if there are any errors.

- Windows - C:\Program Files\PostgreSQL\9.5\data\pg_log
- OSX - /usr/local/var/postgres/server.log
- Linux - /var/log/postgresql

I get an error in my PostgreSQL logs FATAL: database files are incompatible with server

If you still need the data in this directory, you will need to use the pg_upgrade utility to upgrade your data. If you do not care about the data in the PostgreSQL data directory, remove it with rm -rf /usr/local/var/postgres/*. Then, initialize the data with initdb /usr/local/var/postgres.