<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Cleanup of cases (and tasks) via an IVY Process causes to Database Deadlocks</title><link>https://answers.axonivy.com/questions/2683/cleanup-of-cases-and-tasks-via-an-ivy-process-causes-to-database-deadlocks</link><description>&lt;p&gt;I refer to the question # “478 - How to cleanup old Cases / Tasks?” with my questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;“Triggers in the XpertIvySystemDatabase”
Among other triggers there is a trigger when deleting cases and when deleting tasks.
Because the installing and setup of IVY was done many years ago by a former colleague so my first question is: Were all triggers delivered by AXONIVY?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;“Cleanup of old Cases and Tasks”
We use an timer triggered Ivy Process for the Cleanup with the sql-statement for deleting finished cases:
“DELETE FROM IWA_Case WHERE DATEDIFF(dd, EndTimestamp, GETDATE()) &amp;gt; in.TimestampString.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The Timestampstring contains the number of days the finished cases will be stored.&lt;/p&gt;
&lt;p&gt;For example: “DELETE FROM IWA_Case WHERE DATEDIFF(dd, EndTimestamp, GETDATE()) &amp;gt; 7” will delete all finished cases older than 7 days.&lt;/p&gt;
&lt;p&gt;As mentioned in my first question, all Delete-Statements in the CASE-DELETE-Trigger and all the nested Delete-Statements in the TASK-DELETE-Trigger will be executed automatically.&lt;/p&gt;
&lt;p&gt;This causes to Database-Deadlocks – see one Message of our Nagios tool:&lt;/p&gt;
&lt;p&gt;5 deadlocks detected on LUXDB004&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;spid status loginame hostname blk open_tran dbname cmd waittype waittime last_batch SQLStatement 
66 suspended sa_ivy LUXAS004 0 2 IvyDb DELETE 0044 6 Jun 6 2017 08:58:20:460PM DELETE IWA_TaskData FROM IWA_TaskData, deleted WHERE IWA_TaskData.TaskId = deleted.TaskId \n \n
66 suspended LUXAS004 0 0 IvyDb DELETE 00bb 76873 Jun 6 2017 08:58:20:460PM DELETE IWA_TaskData FROM IWA_TaskData, deleted WHERE IWA_TaskData.TaskId = deleted.TaskId \n \n
66 suspended LUXAS004 0 0 IvyDb DELETE 00bb 71822 Jun 6 2017 08:58:20:460PM DELETE IWA_TaskData FROM IWA_TaskData, deleted WHERE IWA_TaskData.TaskId = deleted.TaskId \n \n
66 suspended LUXAS004 0 0 IvyDb DELETE 00bb 49495 Jun 6 2017 08:58:20:460PM DELETE IWA_TaskData FROM IWA_TaskData, deleted WHERE IWA_TaskData.TaskId = deleted.TaskId \n \n
66 suspended LUXAS004 0 0 IvyDb DELETE 00bb 55455 Jun 6 2017 08:58:20:460PM DELETE IWA_TaskData FROM IWA_TaskData, deleted WHERE IWA_TaskData.TaskId = deleted.TaskId \n \n
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What is wrong? What must we do to avoid this deadlocks?&lt;/p&gt;
&lt;p&gt;Thanks in advance.
Dieter&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2683/cleanup-of-cases-and-tasks-via-an-ivy-process-causes-to-database-deadlocks" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 09 Jun 2017 05:28:58 -0400</lastBuildDate><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/2683/cleanup-of-cases-and-tasks-via-an-ivy-process-causes-to-database-deadlocks/2693</link><description>&lt;p&gt;Normally, a database detects deadlock itself and then throws an exception to one of the deadlock owners. Do you see such an deadlock error in your ivy logs too?&lt;/p&gt;
&lt;p&gt;How many cases are deleted? If there are many it may take some time to delete them on the database. Maybe that is why Nagios thinks its a deadlock. In this case try to reduce the amount of cases that are deleted in one statement. After one statement is executed commit the transaction. Then execute the next statement. This will reduce the the amount of memory and transaction log that is necessary to delete the cases. &lt;/p&gt;
&lt;p&gt;For example read the id's of the cases to delete. Then delete each case one after the other.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Fri, 09 Jun 2017 05:28:58 -0400</pubDate><guid>https://answers.axonivy.com/questions/2683/cleanup-of-cases-and-tasks-via-an-ivy-process-causes-to-database-deadlocks/2693</guid></item></channel></rss>