Deleting data from the database (entered by a specific user)

Good day Colleagues,

i need a quick guide on how to go about to delete specific datavalues entered by a specific user at a specific time.

username: training
has entered data on multiple forms for about 2 months, and this data this data needs to be cleaned.

Thanks for your help.

First it’s not an “easy task” , ideally for training it’s better/safer to have a separate server/instance and just “kill it” afterwards (or reset the db content)


  • Note that data modified by training or
  • Deleted by training
    will be fun harder to recover.

The procedure is should be adapted depending on the model used (tracker or aggregate, if you allowed user to add orgUnit/dataElements it will become much harder)

Before doing anything make a backup ! : you might delete things that are not supposed to be deleted
Then pick one of the 2 options :

  • via sql
    delete from datavalue where storedby = 'training' (you can add criterion on updated/created timestamp if needed, you might also join on _periodstructure to delete by dhis2 period)
  • via the api (generally soft delete)
    DELETE /api/events/THEID

Or a mix of the 2 find events created by the user via sql and delete the events via the api

if you go for the sql you might be inspired by this directory :