Last week, during performance tuning consultancy, I faced a very interesting situation when customer’s Microsoft Dynamics CRM was extremely slow. After quickly researched we found that they have a very high number of Mass Waiting Task Workflows in the system. They honestly did not care about those anymore as they were stuck there waiting for over a year and have no meaning at this point of time.
Due to the high number of waiting workflows, data their insert, update and delete in their CRM system was getting extremely slow. After quickly researching online we figured out a way to delete all the waiting task workflow from MSCRM database. Please note that this is not official advice from Microsoft or even not something I they support. This is absolutely from what I have seen in the real world and how I fixed them.
I strongly recommend that you take a full database backup of your MSCRM system before you do following task. However, once deleted all the waiting workflows from MSCRM, the queries which were taking over 10 minutes, started to take less than 10 seconds.
Here is the script which you should run against your MSCRM database.
DELETE FROM workflowwaitsubscriptionbase WHERE asyncoperationid in (SELECT asyncoperationid FROM asyncoperationbase WHERE StateCode = 1) GO DELETE FROM workflowlogbase WHERE asyncoperationid in (SELECT asyncoperationid FROM asyncoperationbase WHERE StateCode = 1) GO DELETE FROM asyncoperationbase WHERE StateCode = 1 GO
Reference: Pinal Dave (http://blog.sqlauthority.com)
First appeared on SQL SERVER – Delete All Waiting Workflows in MSCRM to Speed Up Microsoft Dynamics