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

bernyalvarado
Mega Sage

Also, for some reason I prefer to delete rows using deleteRow() since it's my understanding that deleteMultiple() ignores some references to the records (like attachments).



Thanks,


Berny


santoshsahoonis
Kilo Guru

If you want to delete all data, then use TRUNCATE sql



1. Go to Background Script ot Fix Script


2. Execute this code: gs.sql( 'TRUNCATE TABLE cmdb_ci' );



Do this will all the tables related to it( for Cascade delete )



This will delete all the record in a second.



Even if you want to delete huge amount of data and preserve some data, you can export the data you want to preserver( Export XML) and the Truncate the wholte table, then re import the XML to get back the preserved data.


"TRUNCATE" is a bad idea when you have references you need to take care of, as you will be left with lots of orphaned records.



Plus, checking manually all the references is also not something you want to do.



Regards,


Sergiu


bernyalvarado
Mega Sage

Hi tommyjensen,



It appears you got a good set of recommendations from the community on this thread .



Do you believe we can close this thread by marking the responses as helpful/correct or do you have any further questions we can help with?



Thanks,


Berny


Yes indeed good suggestions however none that suits my needs.



However after the instance has been moved to an onpremise setup it runs a lot faster.