Remove a Specific Process by Process Instance ID

Symptoms

In some unusual cases, a process may reach a non-recoverable corrupted state or it is simply no longer needed in the database so that the system admin may want to remove the process and its related data completely from the database. It will be nice to have SQL script to assist this operation.

Cause

QA or Corrupted process

Resolution

To delete a specific process by its process instance ID (in this example, the process instance ID is '22105101f9fd45f39b277cabea77d247'):

delete WF_EVENTS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_AUTO_WORKITEMS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_MANUAL_WORKITEMS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_ACTIVITY_INSTS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_CUSTOM_ATTRS where CUSTOM_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_CUSTOM_ATTRS where CUSTOM_ID = ( 
    select WORK_OBJECT_ID from WF_PROC_INSTS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247')
    
delete WF_PROC_TRACKINGS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_LARGE_TEXTS where TEXT_ID = 
    '22105101f9fd45f39b277cabea77d247'
delete WF_MAIL_DELIVERABLES where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'
    
delete WF_PROC_INSTS where PROC_INST_ID = 
    '22105101f9fd45f39b277cabea77d247'.