Rebuild database indexes

Overview

Rebuilding a database index consists in dropping and re-creating the index. This operation removes fragmentation, and reclaims disk space. It compacts the pages based on the specified fill factor setting (if a fill factor is not specified, the default one is used), and reorders the index rows in contiguous pages.

Rebuild your Sitefinity CMS database indexes is an operation that is external from the Sitefinity CMS application, and must be by running your own custom script via the SQL Server Agent. , You can run the optimization scripts manually, or choose the regularity to do that and schedule a procedure.

NOTE: You should rebuild indexes when the site is not under heavy use, since this can result in timeouts and exceptions for your current web site users. Preferably run the script during the night hours or weekends, depending on the business intensive hours. The rebuild times usually should last less than 10 minutes, but depends on the database size. The index rebuild is atomic operation that is not considered a data corruption threat.

When you create or rebuild an index, you can specify a fill factor, which is the amount the data pages in the index that are filled. A fill factor of 100 means that each index page is 100% full.

RECOMMENDATION: To avoid fragmentation of the index each time a new record is inserted in the database and needs to be put between existing records, we recommend to specify a fill factor lower than 100%.

If you run the rebuild scripts on a regular basis and your application is not updated heavily with new data, you can use a fill factor of 90%. This should leave enough empty space on the database index pages for new records until the next rebuild. In addition, not too much empty space on the hard drive will be left unused.

The following sections demonstrate how you get report of the current database fragmentation and then rebuild the indexes.

Get report of the current fragmentation of indexes

You can use this report to adjust how often you need to run the indexes rebuild operation, depending on how often and how much your website data is changed (added, updated, deleted).

A couple of points to consider:

  • Pay attention to the results for big indexes only that have page count of >100.
  • If you have a lot of big indexes with fragmentation of more than 10%, then you need to run the index rebuild. After the first run of the script, you can check again in a week whether fragmentation is high, so that you run the script once again. It is possible that you need to run the script just once in a month.

Run the following script to get statistics and report of the current database fragmentation:

Rebuild database indexes

Run the following script to go over all the Sitefinity CMS database indexes and rebuild them with fill factor of 90%:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?