# Rename an xDB Collection database shard

Abstract

How to rename an xDB Collection database shard.

When you rename an xDB Collection shard, you must update references to that shard in several tables. You might rename a shard if you copy xDB Collection database between environments - for example, from your local developer environment to a QA environment. In this scenario you might want to rename a shard from brandlocaldev_Xdb.Collection.Shard1 to brandqa_Xdb.Collection.Shard1.

### Note

A shard is a database. The xDB Collection database is made up of multiple databases - a shard map manager and several shards.

To rename a shard:

1. Follow Microsoft's instructions to rename the shard (database). For example, you might rename foo_Xdb.Collection.Shard1 to bar_Xdb.Collection.Shard1.

2. For the database that you just renamed (now bar_Xdb.Collection.Shard1), locate the _ShardManagement.ShardsLocal table.

3. For each row in the _ShardManagement.ShardsLocal table, change the value of the DatabaseName field from the old database name (foo_Xdb.Collection.Shard1) to the new database name (bar_Xdb.Collection.Shard1).

4. Switch to the cluster's shard map manager database, for example, foo__Xdb.Collection.ShardMapManager.

5. In the _ShardManagement.ShardGlobal table, select all where the DatabaseName equals the old database name (foo_Xdb.Collection.Shard1). You will get three results - one for each shard map.

6. Change the value of the DatabaseName field from the old shard database name (foo_Xdb.Collection.Shard1) to the new shard database name (bar_Xdb.Collection.Shard1).

7. Restart all roles that reference the xDB Collection database. This includes:

### Note

If you do not restart before rebuilding the index, the old shard name might still be cached and the rebuild will fail.

8. When you have finished renaming all the shards that you intend to rename, rebuild the xDB search index.

### Note

If you rename the ShardMapManager, you must update the collection connection string of all roles that reference the xDB Collection database.