Apache Cassandra

Cassandra List Available Keyspaces

“In Apache Cassandra, a keyspace refers to an object or container that holds the data together. Think of it as a database in the context of relational databases. A Cassandra can contain one keyspace per node depending on the requirements and system resources.”

This article will discover how you can get the list of available keyspaces within your cluster.

Method 1 – Query System_Schema Keyspace

The Apache Cassandra cluster includes a system keyspace that holds tables about various objects and cluster configuration information.

By default, Cassandra will create a table containing the available keyspaces within the cluster. Therefore, we can query this keyspace for that specific table to view all the keyspaces.

The query syntax is as shown:

SELECT column_name FROM system_schema.keyspaces;

 
An example is as shown:

cassandra@cqlsh> select * from system_schema.keyspaces;

 
The query above should return all the available keyspaces.


The output above shows that the cluster contains five key spaces: system_auth, system_schema, system_distributed, system, and system_traces.

Method 2 – Using the Describe Command

If you do not have permission to access the system_schema keyspace, you can use the DESCRIBE KEYSPACE command, which allows you to list all the keyspaces in the cluster.

The query syntax is as shown:

DESCRIBE KEYSPACES | KEYSPACE keyspace_name

 
For example, to show all the available keyspaces, run:

cassandra@cqlsh> describe keyspaces;

 
The resulting output is as shown:

system       system_distributed  system_traces  system_virtual_schema
system_auth  system_schema       system_views

 
This will only return the names of the keyspaces in the cluster.

You can also use the short version of the command:

cassandra@cqlsh> desc keyspaces;

 
To gather detailed information about a keyspace, you can run the command:

DESC keyspace <keyspace_name>

 
For example, to show information about the system_auth keyspace, we can run the query:

cassandra@cqlsh> desc keyspace system_auth

 
Remember that this will return detailed information about the keyspace, including the table structure, data types, etc.

Conclusion

In this article, you learned two main methods for viewing your Cassandra cluster’s available keyspaces.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list