“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:
An example is as shown:
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:
For example, to show all the available keyspaces, run:
The resulting output is as shown:
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:
To gather detailed information about a keyspace, you can run the command:
For example, to show information about the system_auth keyspace, we can run the query:
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.