Skip to content
Related Articles

Related Articles

Modifying keyspace in Cassandra
  • Last Updated : 19 Dec, 2019

Prerequisite – Cassandra
In this article, we will discuss how we can modify the existing keyspace by using the ALTER KEYSPACE command. It is very helpful when we want to modify some properties such that the replication factor, data centre name, keyspace name, etc.

First, we need to create keyspace. Let’s consider cluster1 is the keyspace and we have strategy options like NetworkTopologyStrategy and data centers name east and west in which replication factor is 2 for both the data centers. Let’s have a look.

Creating an keyspace:

WITH REPLICATION = {'class' : 'SimpleStrategy', 
                    'replication_factor' : 3}; 

If we are using SimpleStrategy then we can use the following CQL query to modifying the existing keyspace.

WITH REPLICATION =  { 'class' : 'SimpleStrategy', 
                      'replication_factor' : 3 }; 

Changing the Replication Strategy:
In case of modifying we can set the RF (replication factor) and replication strategy at keyspace level. let’s understand this with an example.

WITH REPLICATION = {'class’: 'NetworkTopologyStrategy', 
                    'east1' : 3, 'west1' : 3}; 

Now, if we want to modify an existing keyspace in which we have restriction to change keyspace name. let’s have a look.

WITH REPLICATION = {'class’: 'NetworkTopologyStrategy', 
                    'east1' : 3, 'dc2' : 2}; 

Note: Datacenter names are case-sensitive. Verify the case of the datacenter name using a utility, such as dsetool status.
See Changing keyspace replication strategy.

dsetool status

Now, we can run a full repair to the keyspace when we are going to add data centers. let’s have a look.

nodetool repair --full keyspace_name
nodetool repair –full cluster1; 

Now, to verify the keyspace changes used the following CQL Query.

describe keyspace cluster1; 
My Personal Notes arrow_drop_up
Recommended Articles
Page :