WSUS Server Cleanup Wizard hangs at “Deleting unused updates” stage

Last week i was checking some of my replica WSUS servers, and I discovered that some of them hadn’t synchronised with the upstream WSUS server for a few weeks. When looking in the synchronisation log I was presented with the following error message:

An error occurred with the server’s data store.

And when I clicked on “Details”, this message was displayed:

SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

As some of the WSUS servers had been synching OK with the upstream server I ruled out any corruption at that end. Apparently this error can occur if the server cleanup wizard has been run on the Master WSUS server, but not on the replica. As a result I decided to run the WSUS server cleanup wizard on each of the replica WSUS servers that were having problems synchronising with the master server. Most of these ran through fine, but a couple of the replica WSUS servers hung on the “Deleting unsused updates stage” and therefore the server cleanup wizard could not complete. I had seen this issue before while dealing with a different problem previously, and knew that it could be resolved by running the server cleanup wizard elements in a specific order, which is as follows:

Pass one:

Select option 2 only “Computers not contacting the server”

Pass two:

Select option 4 only “Expired updates”

Pass three:

Select option 5 only “Superseded updates”

Pass four:

Select option 3 only “Unneeded update files”

Pass 5:

Select option 1 only “Unused updates and update revisions”

Running the cleanup wizard with the options above fixed the issue and subsequently the replica servers happily synchronised with the master server once again. Please note even running the server cleanup wizard in this way, pass five can still take a considerable amount of time to run, but it has always succesfully completed for me. On one of the servers I even had to leave this running over night.