|
| 1 | +--- |
| 2 | +title: Change Partition Key |
| 3 | +titleSuffix: Azure Cosmos DB |
| 4 | +description: Change partition key in Azure Cosmos DB for NOSQL API. |
| 5 | +author: richagaur |
| 6 | +ms.author: richagaur |
| 7 | +ms.service: cosmos-db |
| 8 | +ms.topic: conceptual |
| 9 | +--- |
| 10 | +# Changing the Partition Key in Azure Cosmos DB (Preview) |
| 11 | + |
| 12 | +[!INCLUDE[NoSQL](includes/appliesto-nosql.md)] |
| 13 | + |
| 14 | +In the realm of database management, it is not uncommon for the initially chosen partition key for a container to become inadequate as applications evolve. This can result in suboptimal performance and increased costs for the container. Several factors contributing to this situation include: |
| 15 | + |
| 16 | +- [Cross partition queries](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-query-container#avoid-cross-partition-queries) |
| 17 | +- [Hot partitions](https://learn.microsoft.com/azure/cosmos-db/nosql/troubleshoot-request-rate-too-large?tabs=resource-specific#how-to-identify-the-hot-partition) |
| 18 | + |
| 19 | +To address these issues, Azure Cosmos DB offers the ability to seamlessly change the partition key using the Azure Portal. |
| 20 | + |
| 21 | +## Getting Started |
| 22 | + |
| 23 | +To change the partition key of a container in Azure Cosmos DB for the NoSQL API using the Azure Portal, follow these steps: |
| 24 | + |
| 25 | +1. Navigate to the **Data Explorer** in the Azure Cosmos DB portal and select the container for which you need to change the partition key. |
| 26 | +2. Proceed to the **Scale & Settings** option and choose the **Partition Keys** tab. |
| 27 | +3. Select the **Change** button to initiate the partition key change process. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +## How the Change Partition Key Works |
| 32 | + |
| 33 | +Changing the partition key entails creating a new destination container or selecting an existing destination container within the same database. |
| 34 | + |
| 35 | +If creating a new container using the Azure portal while changing the partition key, all configurations except for the partition key and unique keys are replicated to the destination container. |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +Subsequently, data is copied from the source container to the destination container in an offline manner utilizing the [Intra-account container copy](https://learn.microsoft.com/azure/cosmos-db/container-copy#how-does-container-copy-work) job. |
| 40 | + |
| 41 | +>[!Note] |
| 42 | +> It is recommended to stop all updates on the source container before proceeding to change the partition key of the container for entire duration of copy process to maintain data integrity. |
| 43 | +
|
| 44 | +Once the copy is complete, you can start using the new container with desired partition key and optionally delete the old container. |
| 45 | + |
| 46 | +## Next Steps |
| 47 | + |
| 48 | +- Explore more about [container copy jobs](https://learn.microsoft.com/azure/cosmos-db/container-copy). |
| 49 | +- Learn further about [how to choose a partition key](https://learn.microsoft.com/azure/cosmos-db/partitioning-overview#choose-partitionkey). |
0 commit comments