Removing LinksStore Database in SP2013

When you create a new Search Service Application in SP2013, four databases are created - Search Administration, Analytics Reporting, Crawl, and Link Database.

If you want to remove the default/old LinksStore database, you will be using PowerShell cmdlet;

Remove-SPEnterpriseSearchLinksDatabase -Identity SearchDB_LinksStore -SearchApplication $SearchServiceApplication -Confirm:$false

SharePoint will not allow you to remove LinkDatabase when there is just one LinksStore database for your Search service application. In this case you will get an error;

“Remove-SPEnterpriseSearchLinksDatabase : Can't delete LinksStore 'SearchDB_LinksStore' with id '3d139e94-f9f5-4c4b-b7ed-81c56dd577b8' because it is used for query logging”

You will be able to remove Links DBs only after moving data across list of other links databases. Links DBs must be repartitioned in order not to use the old (default) DB, allowing it to be deleted. For this first you need to create a new LinksStore database using this cmdlet;

New-SPEnterpriseSearchLinksDatabase -DatabaseName SearchDB_NewLinksStore –SearchApplication $SearchServiceApplication

You can check all links store associated with that SSA using LinksStore property of Search Service Application.

image

Once new Links DB is created, move the data using Move-SPEnterpriseSearchLinksDatabases cmdlet.

Move-SPEnterpriseSearchLinksDatabases -SearchApplication $SearchServiceApplication -Confirm:$false

Even after running this cmdlet, you will still not be able to remove the old LinksStore DB as all currently existing links databases are used (includes the old Links DB).

To remove the old Links DB you will have to move the data completely to any other linksStore database. This can be done by specifying the TargetStores parameter in this cmdlet which specifies target list of databases. Once the move has started, the cmdlet will return RepartitioningId which can be used to retrigger if the current run fails. To move the data to new LinksStore database;

$oldLinksStoreDB = $SearchServiceApplication.LinksStores | select -last 1

$newLinksStoreDB = $SearchServiceApplication.LinksStores | select -first 1

Move-SPEnterpriseSearchLinksDatabases -SearchApplication $SearchServiceApplication -TargetStores @($newLinksStoreDB) -Confirm:$false

After the move has finished, the old Links DB can be removed.

Remove-SPEnterpriseSearchLinksDatabase -Identity SearchDB_LinksStore -SearchServiceApplication $SearchApplication -Confirm:$false

image