How to Alter Keyspace in Cassandra by using CQL
To create the Keyspace in Cassandra Query Language we use "Create Keyspace Keyspace_Name with options". To Alter existing Keyspace in Cassandra , we can use "Alter Keyspace Keyspace_Name with Options".Let's say we have created TechBrothersTutorials keyspace by using below script.
CQLSH:techbrotherstutorials> CREATE keyspace techbrotherstutorials
WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'DC1' : 2, 'DC2' : 1}
AND durable_writes = false;
AND durable_writes = false;
Let's check if TechbrothersTutorial Keyspace is created successfully.
CQLSH:techbrotherstutorials>SELECT * FROM system_schema.keyspaces;
Figure 1- CQL Tutorial - Check the definition of keyspace by using system_schema.keyspaces in CQL
Now if we would like to Alter TechBrothersTutorials keyspace from Replication Strategy "NetworkTopologyStrategy" to "SimpleStrategy" ,replication factor=3 and DURABLE_WRITES = true, we can use below statement.
CQLSH:techbrotherstutorials> ALTER keyspace techbrotherstutorials
WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor' : 3}
AND durable_writes = true;
AND durable_writes = true;
Let's check the definition of TechBrothersTutorials keyspace after executing above script to verification changes are completed successfully.
CQLSH:techbrotherstutorials>SELECT * FROM system_schema.keyspaces;
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.