Monday, April 7, 2014

Remove Site Collection and Reclaim Database Disk Space

Scenario
  • You need to remove a large site collection from your content database.
  • SharePoint 2010 or higher
Resolution
  • Use PowerShell after hours to remove the site collection:
     
    Remove-SPSite –Identity http://sitename
     
  • If you are on 2010 SP1 or later and if you used Central Admin or the SharePoint UI instead of the above PowerShell command or if you specified the -GradualDelete flag, then you must use PowerShell to remove the site collection from the recycle bin and then run the "Gradual Site Delete" timer job (or wait overnight for scheduled job), otherwise skip this step: 

    Get-SPDeletedSite -webapplication http://sitename | Remove-SPDeletedSite
     
  • Wait a few minutes for the database size to finish reducing (monitor via SQL Management Studio)
     
    Perform a FULL database backup on the content database (this will truncate the log files)
     
  • Then shrink the database via SQL command in SQL Management Studio:
     
    DBCC SHRINKDATABASE ('database_name' ,5 , NOTRUNCATE)
     
  • Then reorganize the indices (this should run automatically every day, but you can kick it off manually now):
     
    Run the following from Central Admin Health Analyzer (/Lists/HealthRules/AllItems.aspx) using Run Now:
     
    Databases used by SharePoint have fragmented indices