# Delete process variables and history after process instance completed

**URL:** <https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [July 31, 2018, 10:13am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330 "2018-07-31T10:13:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aminmc](https://forum.camunda.io/user_avatar/forum.camunda.io/aminmc/32/3196_2.png) [@aminmc](https://forum.camunda.io/u/aminmc)\
**Post date:** [July 31, 2018, 10:13am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/1 "2018-07-31T10:13:41Z")

</div>

Hello

Can anyone recommend the best approach to delete process instance variables and associated history after the instance completes? My use case requires that the variable data exists only when the process instance is running. Once it completes I need to delete the variable data and all history. This doesn’t apply to all process definitions only a select few, so enabling this via configuration would be the best option.

Any help on this would be appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![Ingo\_Richtsmeier](https://forum.camunda.io/user_avatar/forum.camunda.io/ingo_richtsmeier/32/25968_2.png) [@Ingo\_Richtsmeier](https://forum.camunda.io/u/Ingo_Richtsmeier)\
**Post date:** [July 31, 2018, 10:57am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/2 "2018-07-31T10:57:05Z")

</div>

Hi @aminmc,

have a look into this snippet: [https://github.com/camunda-consulting/code/tree/master/snippets/change-history-output](https://github.com/camunda-consulting/code/tree/master/snippets/change-history-output). It supresses that some variables are written in the history at all.

Hope this helps, Ingo

---

<div class="post-metadata">

**Author:** ![aminmc](https://forum.camunda.io/user_avatar/forum.camunda.io/aminmc/32/3196_2.png) [@aminmc](https://forum.camunda.io/u/aminmc)\
**Post date:** [July 31, 2018, 11:43am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/3 "2018-07-31T11:43:52Z")

</div>

Thanks @Ingo_Richtsmeier. This helps a lot. once the process completes all its data is moved to the history tables so this should prevent the variables existing in the history.

Thanks

---

<div class="post-metadata">

**Author:** ![Yana](https://forum.camunda.io/user_avatar/forum.camunda.io/yana/32/28319_2.png) [@Yana](https://forum.camunda.io/u/Yana)\
**Post date:** [July 31, 2018, 3:42pm UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/4 "2018-07-31T15:42:44Z")

</div>

The History cleanup (1) is also an option.

(1): [https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#history-cleanup](https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#history-cleanup)

---

<div class="post-metadata">

**Author:** ![aminmc](https://forum.camunda.io/user_avatar/forum.camunda.io/aminmc/32/3196_2.png) [@aminmc](https://forum.camunda.io/u/aminmc)\
**Post date:** [August 1, 2018, 5:20am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/5 "2018-08-01T05:20:15Z")

</div>

Thanks @Yana. How do I trigger this clean up for as specific process definition after the completion of the instance? What’s the post completion hook I need to integrate in order to make sure the data is deleted without causing a transaction issue?

I can see I can use the HistoryService to delete the history data for a specific process instance but just not clear when is a good place to call this method, can it be used in an ExecutionListener? Don’t think I can as that’s part of the existing transaction which could have a strange effect?

---

<div class="post-metadata">

**Author:** ![Yana](https://forum.camunda.io/user_avatar/forum.camunda.io/yana/32/28319_2.png) [@Yana](https://forum.camunda.io/u/Yana)\
**Post date:** [August 2, 2018, 6:48am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/6 "2018-08-02T06:48:08Z")

</div>

Hi @aminmc,

You need to configure `historyTimeToLive` in the process definition (1) and then you can either trigger the history cleanup manually (2) or configure it to run all the time/specific times (3).

Setting historyTimeToLive=0 will mean the historic process instances (and their data) will be ready for delete after they finished.

(1): [https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#history-time-to-live](https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#history-time-to-live)  
(2): [https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#manual-run](https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#manual-run)  
(3): [https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#periodic-run](https://docs.camunda.org/manual/7.9/user-guide/process-engine/history/#periodic-run)

Best regards,  
Yana

---

<div class="post-metadata">

**Author:** ![aminmc](https://forum.camunda.io/user_avatar/forum.camunda.io/aminmc/32/3196_2.png) [@aminmc](https://forum.camunda.io/u/aminmc)\
**Post date:** [August 2, 2018, 2:27pm UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/7 "2018-08-02T14:27:03Z")

</div>

excellent thanks @Yana!

Cheers  
Amin

---

<div class="post-metadata">

**Author:** ![Vinit\_Kumar](https://forum.camunda.io/user_avatar/forum.camunda.io/vinit_kumar/32/7093_2.png) [@Vinit\_Kumar](https://forum.camunda.io/u/Vinit_Kumar)\
**Post date:** [January 13, 2020, 7:24am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/8 "2020-01-13T07:24:38Z")

</div>

Hi Ingo\_Richtsmeier,

> [@Ingo\_Richtsmeier](#):
>
> [https://github.com/camunda-consulting/code/tree/master/snippets/change-history-output](https://github.com/camunda-consulting/code/tree/master/snippets/change-history-output)

could you please share the same active link again. The link which you shared throwing 404.

Thanks & Regards,  
Vinit Kumar

---

<div class="post-metadata">

**Author:** ![Ingo\_Richtsmeier](https://forum.camunda.io/user_avatar/forum.camunda.io/ingo_richtsmeier/32/25968_2.png) [@Ingo\_Richtsmeier](https://forum.camunda.io/u/Ingo_Richtsmeier)\
**Post date:** [January 13, 2020, 8:49am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/9 "2020-01-13T08:49:25Z")

</div>

Hi @Vinit_Kumar,

as the option is now part of the product, you can find an example here: [https://github.com/camunda/camunda-bpm-examples/tree/master/process-engine-plugin/custom-history-level](https://github.com/camunda/camunda-bpm-examples/tree/master/process-engine-plugin/custom-history-level).

Hope this helps, Ingo

---

<div class="post-metadata">

**Author:** ![Vinit\_Kumar](https://forum.camunda.io/user_avatar/forum.camunda.io/vinit_kumar/32/7093_2.png) [@Vinit\_Kumar](https://forum.camunda.io/u/Vinit_Kumar)\
**Post date:** [January 14, 2020, 10:37am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/10 "2020-01-14T10:37:27Z")

</div>

Thanks @Ingo_Richtsmeier this help me to solve my issue.

Thanks & Regards,  
Vinit Kumar

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 11:19am UTC](https://forum.camunda.io/t/delete-process-variables-and-history-after-process-instance-completed/8330/11 "2024-01-30T11:19:37Z")

</div>

Closed on January 30, 2024, 11:19am UTC


