Cleaning up the CMDB

Stijn Verhulst3
Kilo Guru

Hi,

 

what would be the best practice to cleanup an enitre CMDB? I've tried to do it via a script but unfortunately it didn't work out as the platform couldn't seem to process the deletion/removal for too much records at once.

 

Thank you in advance,

 

Stijn

1 ACCEPTED SOLUTION

aaron_damyen
Kilo Expert

I would recommend utilizing the TableCleaner.   It is used by the Import Sets to clean out old data periodically and with minimal impact to the system.   You can use it clean any table in your instance based on a condition.   There are some configuration options you can put on each table to control some behaviours of the cleaner (Dictionary Attributes - ServiceNow Wiki).



The cleaner will perform a 'less than' on the value specified with the field you specify, as in


GlideTableCleaner(tableName, value, field)



This makes it very easy to delete old data.   Deleting data where an equality is needed is not possible.   I run this from the Scripts - Background and then leave for the weekend or setup a scheduled job.   It's not fast, but it is also not intrusive.   The first run of this took 2 1/2 weeks to clear out 4 million records with a 25,000 records per hour inflow.   If speed is more important than performance, this may not be your answer.



Here's my example use of it as a scheduled job script:



var ageDays = 0.25; // (6 hours)


var tableName = "employee_hr_db";



gs.log("Beginning clean-up of table: " + tableName);


var cleaner = new GlideTableCleaner(tableName, Math.ceil(ageDays * 86400000), 'sys_updated_on');


cleaner.clean();


gs.log("Ending clean-up of table: " + tableName);


View solution in original post

14 REPLIES 14

Dex4
Tera Expert

Howdy Stijn,



My team is looking to do something similar.   We are evaluating changing classes and relationships for many configuration items and also changing our bottom up approach to be a Top down approach as we move to business services.   Have you made progress or any updates that you could share?


Bhavesh Jain1
Giga Guru

You could raise a ticket on HI Support for this.


In case you would like to do it yourself, go to background script and run below code:


gs.sql(TRUNCATE TABLE   cmdb_ci);



Note : This is not the prefered way though and it is good to contact SNC support.



Other approach is to write a   RUN ONCE script in sys_trigger table to delete all the records of cmdb_ci table.


Not exactly what I am looking for; although fully redoing the cmdb I am not starting from scratch.   70,000+ configuration items and 30,000 relationships that I need to export, modify and bring back.


I see...Simple


Use the new Import functionality added in Dublin release.



http://wiki.servicenow.com/index.php?title=Easy_Import