As you may know, deleting completed process instances is not really a out-of-the-box feature in K2. You only have the option to delete running process instances. The whole idea behind this is that for compliance reasons (e.g. SOX), process audit history is very important and should not be easily removed.
However in certain cases, it might be a good idea to remove certain processes from the K2 databases which are no longer needed. This helps to reduce the size of the K2 Log database when the obsolete processes are not needed. To achieve this end, I have written a simple stored procedure which allows you to remove all completed process instances from a K2 Log database. This is based on the native K2 functionality which deletes the log entries when deleting a running process instance.
This stored procedure does the following:
- Removes the completed process instances based on the full name of the process. e.g. "Finance\Purchase Request"
- Does a pre-check to ensure that there are no running process instances. As I said, this is for obsolete processes, so there should not be any running instances.
The stored procedures are attached in the zip file for this post and there are two versions. One for K2.net 2003 and one for K2 [blackpearl], the stored procedures have been tested on K2.net 2003 SP2a and K2 [blackpearl] SP1. They should work for later versions as long as there are no changes in the lProcInstRemove stored procedure which is found in the K2 Log database.
Although due diligence and testing has been done to ensure there Stored Procedures work as advertised but in any case please do the proper DB backups before executing this is a live environment.
Note: These stored procedures are not supported by K2 directly and if any damages arise out of their use or incorrect use, myself and K2 as a company are not liable for them. Usage of these stored procedures assumes that you have a certain level of SQL expertise so please don't cry over split milk if anything wrong occurs... :)
I would also recommend running this when the K2 servers are offline. This is especially true if the K2Log (K2.net 2003) or K2ServerLog (K2 [blackpearl] have a ton of records. Executing this stored procedure on a large set of instances while the K2 server is running might cause deadlocks or timeouts to occur.
You might want to also run a DBCC SHRINKDATABASE command to reclaim execessive unused space once the obsolete process instances are removed.
I hope some of you will find this useful. Cheers.
Posted
Tue, Apr 15 2008 2:37 PM
by
johnny