Clean Up History, PublishQueue, and EventQueue tables in Sitecore

Many of the Sitecore developers might have come across this scenario where the size of the History or EventQueue or PublishQueue will be growing super fast. As a result, the entire site might become slow or you might experience the super slow performance of the content editor and page editor. So in this scenario How do we Clean Up History, PublishQueue, and EventQueue tables in Sitecore? Let’s take a look into this in detail.

Symptoms

  • Slow performance during publishing.
  • Slow performance during indexing.

Clean Up History, PublishQueue, and EventQueue tables in Sitecore

You could manually run the Query to delete the unnecessary records that have been accumulated in the Database tables. Run the below query to delete the records of History, PublishQueue, and EventQueue tables.

USE [web] /* Repalce web with your DB name */
/* TRUNCATE History TABLE */
IF OBJECT_ID('History', 'U') IS NOT NULL
IF((SELECT COUNT(*) FROM [History]) > 1000)
BEGIN
TRUNCATE TABLE [History];
PRINT 'Truncated the History Table';
END
/* TRUNCATE EventQueue TABLE */
IF OBJECT_ID('EventQueue', 'U') IS NOT NULL
if((SELECT COUNT(*) FROM [EventQueue]) > 1000)
BEGIN
TRUNCATE TABLE [EventQueue];
PRINT 'Truncated the EventQueue Table';
END
/* TRUNCATE PublishQueue TABLE */
IF OBJECT_ID('PublishQueue', 'U') IS NOT NULL
IF((SELECT COUNT(*) FROM [PublishQueue]) > 1000)
BEGIN
TRUNCATE TABLE [PublishQueue];
PRINT 'Truncated the PublishQueue Table';
END

Sitecore recommends that the number of rows (entries) in the History, PublishQueue, and EventQueue tables be less than 1000. This prevents timeouts from occurring while the cleanup agents run.

Sitecore has a built in Scheduled Task which runs every 4 hours to clear the History, PublishQueue, and EventQueue tables automatically. If this setting is changed in web.config file then you could face this issue.

Verify the web.config file for the Default Settings

Open the web.config file and navigate to <configuration><sitecore><scheduling></scheduling> node.

<scheduling>
 <!-- Time between checking for scheduled tasks waiting to execute -->
 <frequency>00:05:00</frequency>

 <!-- Agent to clean up history data -->
 <agent type="Sitecore.Tasks.CleanupHistory" method="Run" interval="04:00:00"/>
 <!-- Agent to clean up publishing queue -->
 <agent type="Sitecore.Tasks.CleanupPublishQueue, Sitecore.Kernel" method="Run"
interval="04:00:00">
 <DaysToKeep>30</DaysToKeep>
 </agent>
 <!-- Agent to clean up the event queue -->
 <agent type="Sitecore.Tasks.CleanupEventQueue, Sitecore.Kernel" method="Run"
interval="04:00:00">
 <DaysToKeep>1</DaysToKeep>
 </agent>
  • Check that the is set to something other than 00:00:00 so that the agents are checked to see if they are ready to be executed.
  • Make sure that the interval for Sitecore.Tasks.CleanupHistory is greater than 00:00:00.
  • Check that the interval for Sitecore.Tasks.CleanupPublishQueue is greater than 00:00:00.
  • Check that the interval for Sitecore.Tasks.CleanupEventQueue is greater than 00:00:00.

If any of the values are set to 00:00:00 or changed to some other value then replace it with above default values. To improve the performance further, you could also reduce the DaysToKeep to 1 and interval to also.

0 Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like