Cleaning up and reduce the size of the TFS database

If you don’t need the data of a project any more, you can choose among various tools to delete it from the Team Foundation Server:

  • There is a Delete button on the Team Projects tab in the TFS Administration Console.
  • You can run the tf.exe with the delete switch, which runs fast, but it only sets a flag to mark deleted files, so you can restore them later using the undelete command.
  • The destroy switch of tf.exe permanently deletes the items, so you cannot restore them later. Unfortunately it can only delete items from the version control database.
  • The TFSDeleteProject.exe is another command line tool which can delete not only from the TFS database, but also from the reporting and SharePoint databases.

Whichever method you choose, you may notice that the size of the database is not reduced immediately right after you deleted large amount of data. This is because all of the above methods leave some orphan data behind, which is deleted later by a job ran by the TFS Background Job Agent. However this job runs only once a day!

If you don’t want to wait that much, you can run tf destroy with the /startcleanup switch which immediately kicks off the cleanup job.

Another option is to dive deep into the database, and run the cleanup stored procedures manually. If your Content table is large:

EXEC prc_DeleteUnusedContent 1

If your Files table is large:

EXEC prc_DeleteUnusedFiles 1, 0, 1000

This second sproc may run for a long time, that’s why it has the third parameter which defines the batch size. You should run this sprocs multiple times, or if it completes quickly, you can increase the chunk size.

Obviously, this is not supported, but worked on my machine.



2 thoughts on “Cleaning up and reduce the size of the TFS database

  1. Prashant Gaikwad

    Hi György,

    tf destroy with the /startcleanup switch
    Is not working in my case.

    And even not reducing the size of .MDF file using following commands.
    EXEC prc_DeleteUnusedContent 1
    EXEC prc_DeleteUnusedFiles 1, 0, 1000

    Is there any other way out.

    Thank you,
    Prashant Gaikwad


Leave a Reply

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

You are commenting using your 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