Hello,
first, backup your database.
RU in the names of the tables comes from “runtime” means the process instance is in active state, HI is for “history”. Only running instances are in RU tables because of the performance, but they also mirror in HI. When the process instance is finished, everything is written in HI only.
Your SQL is not bad, but its a matter of precedence, some tables needs to be deleted before others, and there is a thing with ACT_RU_IDENTITYLINK entries where you also need to delete based on ACT_RU_TASK.ID_ not just general PROC_INST_ID_ , like this:
DELETE FROM ACT_HI_IDENTITYLINK WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_HI_DETAIL WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_HI_ATTACHMENT WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_HI_TASKINST WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_HI_ACTINST WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_HI_VARINST WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_HI_PROCINST WHERE ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_RU_IDENTITYLINK WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_RU_VARIABLE WHERE EXECUTION_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_RU_EVENT_SUBSCR WHERE EXECUTION_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_RU_IDENTITYLINK
WHERE TASK_ID_ IN (
SELECT ID_
FROM ACT_RU_TASK
WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec'
);
DELETE FROM ACT_RU_TASK WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
DELETE FROM ACT_RU_EXECUTION WHERE PROC_INST_ID_ = 'dea46cf9-742e-11ef-9377-00ff19afe8ec';
Test this thoroughly.
These SQL commands are good when performing large bulk deletes, such as cleaning the database or externally deleting records via SQL, otherwise Flowable REST API or Java API can be used.
Look for
runtimeService.deleteProcessInstance
runtimeService.bulkDeleteProcessInstance (list of instances to delete)
Kind regards,
Mladen