Sitecore History Table – how to control how long the entries are kept?

The following tables can contain a lot of data, especially if the website creates and or edits a lot of items, for the first 2 the tables it is very simple to define how many days to keep the data.

  • Publish Queue
  • Event Table
  • History Table

If there is to much data in any of the table it can causes the performance issues for Sitecore. By default Sitecore stores data for 30 days, which is too long.

Sitecore uses the following scheduled task to clean the database tables.

  1. Sitecore.Tasks.CleanupPublishQueue
  2. Sitecore.Tasks.CleanupEventQueue
  3. Sitecore.Tasks.CleanupHistory

Both CleanupPublishQueueCleanupEventQueue tasks provide the ability to specify the number of days to keep the entries (see below). Unfortunately in some cases 1 day is too long, but I will get back to that in another post.

days to keep

So why can’t you specify the number of days for the Sitecore.Tasks.CleanupHistory?

Just in case it was another undocumented feature, I opened up reflector and took a look at the Sitecore.Tasks.CleanupHistory implementation to see if it was possible or not to specify the period of time to keep entries in the history table – It wasn’t!

I continued my search and found that the SqlServerHistoryStorage.Cleanup() function (see image below) is responsible for cleaning the history table. The SQL statement uses the EntryLifeTime property to define the threshold (time-span) to keep the entries.

clean up function

 

Solution

With a bit more investigation I found that it was possible to define the EntryLifeTime value for each database in the web.config. It is possible to define the time-span using days, house, minutes s and even seconds 🙂

timespan

 

Hope this helps, Alan

4 thoughts on “Sitecore History Table – how to control how long the entries are kept?

  1. rene naplava

    Hi Alan. I’d like to ask you about the possibility how to decrease the time amount to less than 1 day in case of PublishQueue (or EventQueue). You’ve mentioned that it will be a subject of some next post :). Do you have any idea? As far as I saw the CleanupPublishQueue code, I would say “no way” except of the custom cleanup agent where a value of 0 is allowed as well…
    Thanks in advance, rene.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s