How to get list of all Keyspaces in Cassandra by using CQL - Cassandra / CQL Tutorial

How to get list of all Keyspaces in Cassandra by using CQL

Keyspaces table from system_schema keyspace can be used to get the list of all keyspaces in Cassandra.
Let's create couple of Keyspaces by using below scripts and then we will use Keyspaces table from system_schema keyspace to see the details of keyspaces.

CQLSH:techbrotherstutorials> CREATE keyspace tbs 
WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor' : 2}
AND durable_writes = true;

CQLSH:techbrotherstutorials> CREATE keyspace tbs1 
WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'DC1' : 2, 'DC2' : 1}
AND durable_writes = false;

Once you will run above statements, it will create two keyspaces TBS and TBS1.
Let's use the below statement to get information about all the Keyspaces.

 CQLSH:techbrotherstutorialsSELECT * FROM   system_schema.keyspaces;
By executing above statement in CQL shell, Keyspace Name, Is Duruable Write Enable or not and replication configuration information  will be shown.


2 comments: