PostgreSQL Support in the OpenMRS Setup Wizard

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.

Prerequisites

Before setting up OpenMRS with PostgreSQL, ensure the following tools are installed:

Once these are installed, continue with the PostgreSQL setup.

Step 1: Install PostgreSQL

Recommended version: PostgreSQL 16

Windows and MacOs

  1. Download Installer: Open source PostgreSQL packages and installers from EDB

  2. 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 port 5432, and leave the remaining options as default.

  3. 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

  1. Install PostgreSQL: sudo apt-get install postgresql-12

  2. Set Superuser Password: sudo -u postgres psql

At the prompt: \password

Enter and confirm your password for postgres.

  1. 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

  1. Clone the OpenMRS Core Repository

git clone https://github.com/openmrs/openmrs-core.git cd openmrs-core
  1. Build the Project

mvn clean install
  1. Run the Web Application

cd webapp mvn jetty:run
  1. 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.

  1. Select Database Type
    Choose PostgreSQL in the setup wizard.

  2. Provide Connection Details: Database Name: e.g., openmrs

    1. Username: PostgreSQL super user e.g postgres

    2. Password: Your password

video showing simple setup using postgres

newsim.mov

 

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

advncedsetup.mov
advanced option using postgresql

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