PostgreSQL Support in the OpenMRS Setup Wizard
This guide walks you through setting up OpenMRS with a PostgreSQL database. It includes prerequisites, installation steps for PostgreSQL, configuration for OpenMRS, and cleanup procedures.
- 1 Prerequisites
- 2 Step 1: Install PostgreSQL
- 3 Step 2: Deploy OpenMRS
- 3.1 As an Implementer
- 3.2 As a Developer
- 4 Step 3: Configure OpenMRS for PostgreSQL
- 4.1 Simple Setup
- 5 video showing simple setup using postgres
- 5.1 Advanced Setup
- 5.1.1 Step 1: Database Setup
- 5.1.2 Step 2: Table/User Setup
- 5.1 Advanced Setup
- 6 video showing advanced setup using postgres
- 7 Cleanup Procedures
- 7.1 Steps:
- 7.1.1 Reassign Ownership
- 7.1.2 Drop Owned Objects
- 7.1.3 Drop the User
- 7.1.4 Drop the Database
- 7.1.5 Verify Cleanup
- 7.1 Steps:
Prerequisites
Before setting up OpenMRS with PostgreSQL, ensure the following tools are installed:
Firefox or Google Chrome – See instructions here
Java – See instructions here
Apache Tomcat – See instructions here
Once these are installed, continue with the PostgreSQL setup.
Step 1: Install PostgreSQL
Recommended version: PostgreSQL 16
Windows and MacOs
Download Installer: Open source PostgreSQL packages and installers from EDB
Run the PostgreSQL Installer: Run the PostgreSQL installer, accept the license, choose the installation and data directories, and select PostgreSQL Server, pgAdmin 4, and Command Line Tools. Set the superuser password (
postgres
), use port5432
, and leave the remaining options as default.Finish Installation
Verify Installation
Use psql
to connect to the PostgreSQL server:
# Open psql from Start Menu and enter:
Server: localhost
Database: postgres
Port: 5432
Username: postgres
Password: <your-password>
Once connected, run:
SELECT version();
Debian/Debian-based Distributions
Install PostgreSQL:
sudo apt-get install postgresql-12
Set Superuser Password:
sudo -u postgres psql
At the prompt: \password
Enter and confirm your password for postgres
.
Verify Installation
sudo -u postgres psql
SELECT version();
Step 2: Deploy OpenMRS
As an Implementer
Use the OpenMRS SDK or follow deployment instructions here.
As a Developer
Clone the OpenMRS Core Repository
git clone https://github.com/openmrs/openmrs-core.git
cd openmrs-core
Build the Project
mvn clean install
Run the Web Application
cd webapp
mvn jetty:run
Launch OpenMRS
Open your browser and go to:
http://localhost:8080/openmrs
Follow the Setup Wizard instructions.
Step 3: Configure OpenMRS for PostgreSQL
Follow these steps in the Setup Wizard to configure PostgreSQL as your database: OpenMRS offers two installation paths: Simple Setup and Advanced Setup.
Simple Setup
A quick setup path ideal for most users.
Select Database Type
Choose PostgreSQL in the setup wizard.Provide Connection Details: Database Name: e.g.,
openmrs
Username: PostgreSQL super user e.g
postgres
Password: Your password
video showing simple setup using postgres
Advanced Setup
More control over database and user configuration.
Step 1: Database Setup
Provide full JDBC URL:
jdbc:postgresql://localhost:5432/openmrs
Choose between:
Existing database (enter name)
New database (create and define credentials)
Step 2: Table/User Setup
Option to create new tables (recommended for fresh installs)
Configure database user:
Use an existing user or
Create a new user (will be granted necessary permissions)
video showing advanced setup using postgres
Cleanup Procedures
If you're using the Simple Setup option and want to drop the user/database:
⚠️ Warning: Do not drop production databases unintentionally.
Use Advanced Setup if you want more control over database naming.
Steps:
Reassign Ownership
REASSIGN OWNED BY openmrs_user TO dumprole;
Drop Owned Objects
DROP OWNED BY openmrs_user;
Drop the User
DROP ROLE openmrs_user;
Drop the Database
DROP DATABASE openmrs;
Verify Cleanup
\l -- List databases
\du -- List users