{"id":1771,"date":"2015-01-29T20:17:43","date_gmt":"2015-01-29T20:17:43","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1771"},"modified":"2015-01-29T20:17:43","modified_gmt":"2015-01-29T20:17:43","slug":"shrink-crawlstore-database","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2015\/01\/29\/shrink-crawlstore-database\/","title":{"rendered":"Shrink CrawlStore Database"},"content":{"rendered":"<p>A useful script for running on your dev\\uat environments to free valuable disk space.  The crawl store database can grow quite significantly over time.<\/p>\n<p>First of all, the PowerShell script:<\/p>\n<pre lang=\"powershell\">\r\n# Load the SharePoint assembly - change the version to 15.0.0.0 for SharePoint 2013\r\nAdd-Type -AssemblyName \"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\"\r\n\r\n# Reset the content index\r\n(Get-SPEnterpriseSearchServiceApplication).Reset($true,$true)\r\n\r\n# Get the database server for the default content service\r\n$dbServer = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DefaultDatabaseInstance.NormalizedDataSource\r\n\r\n# Get the SQL Management Object server for the content service retrieved above\r\n[System.Reflection.Assembly]::LoadWithPartialName(\"Microsoft.SqlServer.SMO\") | out-null\r\n$SMOserver = New-Object ('Microsoft.SqlServer.Management.Smo.Server') -argumentlist $dbServer\r\n\r\n# Get the search service application instance\r\n$searchServiceApp = (Get-SPEnterpriseSearchServiceApplication)\r\n\r\n# Iterate the crawl stores and for each database, shrink it in size by 20%\r\nforeach($crawlStore in $searchServiceApp.CrawlStores)\r\n{\t\t\r\n\t$dbName = $crawlStore.Name\t\r\n\t$db = $SMOserver.Databases[$dbName]\r\n\tif ($db -ne $null)  \r\n\t {  \r\n\t\t$db.Shrink(20, [Microsoft.SqlServer.Management.Smo.ShrinkMethod]'TruncateOnly')\r\n\t\tWrite-Host \"$dbName has been shrunk\"\r\n\t }\r\n\t else\r\n\t {\r\n\t\tWrite-Host \"$dbName does not exist\"\r\n\t }\r\n}\r\n<\/pre>\n<p>Comments in the script should make this one clear to understand, happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A useful script for running on your dev\\uat environments to free valuable disk space. The crawl store database can grow quite significantly over time. First of all, the PowerShell script: # Load the SharePoint assembly &#8211; change the version to &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2015\/01\/29\/shrink-crawlstore-database\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[3,25],"tags":[41,81,86],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-sz","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1771"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1771"}],"version-history":[{"count":2,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1771\/revisions"}],"predecessor-version":[{"id":1773,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1771\/revisions\/1773"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1771"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}