How to delete history process instance at the end of the process?

To reduce the load on the db as much as possible, I would like to delete the history of the process instance from the database immediately after the process ends, for both the cases either the process has successfully ended or is closed by an incident handler.
I know one way to delete the history for a sync process is:

historyService.deleteHistoricProcessInstance(execution.getProcessInstanceId());

In case the process instance is executing in async mode, the above wouldn’t work when we get the control either in ExecutionListener(for end event) or IncidentHandler.

Process instance is still running, cannot delete historic process instance

I tried the strategy suggested by @Yana in this discussion. The two issues with it are:

  1. It didn’t delete the process instance history which were closed by an IncidentHandler.
  2. It doesn’t look like an optimal way to delete the history when we know the exact process instance id for which we want to clean up.

Hi @rushang7,

what about setting the history time to live to 1 day and delete by history cleanup?

Or don’t store any history at all and use another history level?

Hope this helps, Ingo

Thank you @Ingo_Richtsmeier
I am interested in the idea of not storing the history at all. Could you please guide me on how can I implement it in code or by setting some configuration?
P.S.: I have already set the historyTimeToLive: P0D, and I am frequently calling the function processEngine.getHistoryService().cleanUpHistoryAsync(true); to cleanup the history as early as possible.

Hi @rushang7,

in this case, you should use history level NONE: History and Audit Event Log | docs.camunda.org

Hope this helps, Ingo

1 Like