What is the fastest way to delete 1000000 records in cmdb (incl cascade deletes) ?

tommyjensen
Giga Expert

However some records should NOT be deleted?

Using a background script and deleting with deleteMultiple() runs 20 minutes to delete 100 records! It must be possible to do that faster even with cascade deletes.

24 REPLIES 24

Hi Oliver,



I followed the solution provided by you and the records deletion pace didn't change. I am deleting incident records from task table. so i have added the attributes to task table and written the below code in Fix scripts.



deleterecords();



function deleterecords(){


var Inc = new GlideRecord('task');


Inc.addEncodedQuery('numberSTARTSWITHINC^sys_updated_byISEMPTY^state=7');


Inc.setWorkflow(false);


//gs.addInfoMessage('count is'+Inc.getRowCount());


Inc.deleteMultiple();



before it was deleting 4-5 records per second and it is deleting the same now too. Due to this I have followed the same procedure of adding attributes to Incident table but was not   deleting   quickly.



Anything else you suggest to solve the issue. I need to delete around Hundred thousand records.


Have you tried using the scheduled job instead of a fix script?



Thanks,


Berny


Hi Berny,



Nope , I didn't use that. Will that help?


Hi Harish,



Indeed. As mentioned in a previous comment, a scheduled job is what consistently has work for me.



Thanks,


Berny


Adarsh Krishnam
ServiceNow Employee
ServiceNow Employee

Hello tommyjensen,

1)To make the deletion faster with a background script you can make setworkflow() to false so that the BRs would not be triggered and the deletion is faster.
2)If you are doing it from UI on which ever table you are trying perform a delete add the attribute values for the collection record in the sys_dictionary.

.)no_audit_delete=true,exclude_from_rollback=true which will avoid the pushing the data into the shadow tables.

3)Where condition I mean the filter columns of the table has to be indexed which will eventually make the deletion faster.