- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 07:54 PM
Hello. How do I reconstruct the ServiceNow table in a script? After executing the deletion script in the following job schedule I want to add the process of rebuilding the table. Is it possible to optimize table with ServiceNow script?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 01:21 AM
Yuki,
Check Mwatkins's reply in the following thread.
The thread is a little bit old but the following statement should still hold true.
Generally ServiceNow does not expose this layer of database administration because we don't want our customers to have to worry about it.
Not sure if the followings still hold but may be worth a try.
If you wanted to force reorganization on a certain table you could create a meaningless, hidden, custom field on that table. Then next time you want to reorganize the table you could remove said field.
Another way to force a table reorganization is to add an index to the table. Each time an index is added we do the same online alter operation that totally re-creates the table.
Following article by ServiceNow suggests using table cleaner. Check warning about performance before using it on production instance.
Following Now Support page has instructions on how to use table cleaner.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694151

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 10:07 PM
Hi Yuki,
The provided script will delete records in the table.
>I want to add the process of rebuilding the table.
Not understanding what is to be rebuilt. The table will still be intact. Is there a need to insert some records into the table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 10:18 PM
Hello.
The presented script is a script that deletes the already stored records. When I used this script to delete a large number of records, fragmentation occurred and I'm having a problem with ServiceNow running out of space.
Therefore, we are considering a method to eliminate fragmentation.
I would like to know if it is possible to incorporate the process of optimizing with a script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 11:31 PM
Hi, if you are having issues with your production instance(s) running out of space, then regardless of the circumstances/cause you need to log a high priority case with ServiceNow Support for assistance in identifying and resolving the cause of this issue. It sounds like you should also raise a case for support with your ‘fragmentation’ , I am also interested in an explanation as to how you have identified this in your instance?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 01:21 AM
Yuki,
Check Mwatkins's reply in the following thread.
The thread is a little bit old but the following statement should still hold true.
Generally ServiceNow does not expose this layer of database administration because we don't want our customers to have to worry about it.
Not sure if the followings still hold but may be worth a try.
If you wanted to force reorganization on a certain table you could create a meaningless, hidden, custom field on that table. Then next time you want to reorganize the table you could remove said field.
Another way to force a table reorganization is to add an index to the table. Each time an index is added we do the same online alter operation that totally re-creates the table.
Following article by ServiceNow suggests using table cleaner. Check warning about performance before using it on production instance.
Following Now Support page has instructions on how to use table cleaner.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694151
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 10:37 PM
Did you try running the above script in fix script and in background?
I would suggest you try it once
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader