Hi everyone,
I’m working with a DHIS2 instance 2.40, using the standalone installation from the system administrator guide and need to completely remove all existing data and start fresh. I’m considering recreating the database from scratch using my standalone application.
Could you please advise on the best way to achieve this?
Specifically, I’m interested in:
Recommended methods for removing all data: Should I truncate database tables, or drop and recreate the entire database?
Are there any specific steps or configurations I should follow to ensure a clean and successful database recreation?
Any guidance or insights from the community would be greatly appreciated.
Thanks in advance!
Ulanbek
(Ulanbek)
12 December 2024 07:48
2
Hi @bencapriata
The best way will be following
Export your metadata
Create an empty database
Point dhis.conf to that database
Import the metadata
In case if you need some tracker data, create a list of data what you want to export to the new instance.
1 Like
Hey @Ulanbek , thanks for this. I just wanted to create a reply with the steps that worked for us for future reference.
Based on the DHIS2 system administrator guide;
Part 1: Creating an Empty Database
First, create a non-privileged database user called ‘dhis’ by executing this command:
sudo -u postgres createuser -SDRP dhis
You’ll be prompted to enter a secure password for this user.
Next, create the actual database with the following command:
sudo -u postgres createdb -O dhis dhis2
This creates a database named ‘dhis2’ owned by the ‘dhis’ user we just created.
Since DHIS2 requires PostGIS extension for GIS/mapping features, you need to create it with:
sudo -u postgres psql -c "create extension postgis;" dhis2
For DHIS2 version 2.38 and later, you also need to create two additional extensions:
sudo -u postgres psql -c "create extension btree_gin;" dhis2
sudo -u postgres psql -c "create extension pg_trgm;" dhis2
Part 2: Configuring dhis.conf
The guide specifies that you need to create a dhis.conf file in your DHIS2_HOME directory. Here’s how:
Create a configuration directory (the guide suggests this location):
mkdir /home/dhis/config
chown dhis:dhis /home/dhis/config
Create and edit the dhis.conf file in this location:
/home/dhis/config/dhis.conf
Add these required database connection properties to the file:
# Database connection configuration
connection.dialect = org.hibernate.dialect.PostgreSQLDialect
connection.driver_class = org.postgresql.Driver
connection.url = jdbc:postgresql:dhis2
connection.username = dhis
connection.password = YOUR_PASSWORD_HERE
Protect the configuration file since it contains sensitive information:
chmod 600 dhis.conf
After completing these steps, you’ll have an empty database created and properly configured for DHIS2 to use.
2 Likes
Gassim
(AL-Gassim Sharaf Addin)
1 January 2025 15:50
4
Thank you so much for being helpful and sharing this with the community.