Unable to Delete Search Service Application Databases

A while back I was working on a customer’s broken SharePoint farm (and trust me, this was not a healthy beast), and I ran into a situation where I couldn’t delete the Search Service Application (though I resolved that separately), and subsequently the associated databases. The databases were a huge PITA (Pain In The Arse) to try and get rid of, and the old Google on the Internet box didn’t give me a whole lot to go on.

Ultimately I was able to find various details online, and from that I was able to piece together the following.

In PowerShell, run the following:

Get-SPDatabase | where {$_.Type -notcontains “Content Database” -and $_.Type -notcontains “Configuration Database”} | sort Type | format-table –autosize

This will output a list of databases and from that you can then use the GUID of your troublesome database. Simply run the following:

$searchdb = Get-SPDatabase -Identity “GUID”
$searchdb

You can check the status using the following:

$searchdb.status

Normal it should be Online. If it’s not online, like mine wasn’t, then you may want to delete it.

To delete your search database, just run the following:

$searchdb.delete()

That’s all there is to it. On an important note, deleting the DB here will simply remove the entry in the Config DB, it will not delete the actual database in SQL. If you want to remove the DB in SQL, you’ll then need to go into your SQL server, and either delete the database in SQL, or unmount it from SQL and delete it from disk (manually).

As an extra special note, although I got all this to work, the farm was so hosed (hosed is a Canadian term for “screwed up”) that we ultimately had to rebuild the farm from scratch on a whole new set of servers and port over the content databases. The farm config was too far-gone to resurrect. Even MS support couldn’t get it back up and running.

Best wishes!