47

What cqlsh command can I use to quickly see the keyspaces in a cluster? cqlsh does not provide show keyspaces and describe cluster isn't as concise as I want.


I'm working using the following specifications:

cqlsh 2.2.0, Cassandra 1.1.10, CQL spec 2.0.0, Thrift protocol 19.33.0

Crowie
  • 3,220
  • 7
  • 28
  • 48

4 Answers4

107

Very simple. Just enter this command in your cqlsh shell and enjoy

 select * from system.schema_keyspaces;

In C*3.x, we can simply use

 describe keyspaces
abhi
  • 4,762
  • 4
  • 29
  • 49
  • Found that instruction listed at the bottom of this: http://www.datastax.com/docs/1.1/dml/using_cql – Crowie Jan 29 '14 at 20:07
  • 5
    The system.schema_keyspaces table seem to have been removed from c* 3.x series – BSB Feb 03 '16 at 16:06
47

Just try this:

describe keyspaces


However you may need specs of approximately the following (rather than those mentioned by yourself Crowie)

[cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1 | Thrift protocol 19.39.0]

Community
  • 1
  • 1
Peter Kipping
  • 623
  • 6
  • 12
13
cqlsh> select * from system_schema.keyspaces;

 keyspace_name      | durable_writes | replication
--------------------+----------------+-------------------------------------------------------------------------------------
        system_auth |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}
      system_schema |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
 system_distributed |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'}
             system |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
      system_traces |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '2'}
Gabriel Wu
  • 1,938
  • 18
  • 30
  • 3
    **Note**: This works with `Cassandra 3.0`. You can verify your version using the following query: `SELECT release_version from system.local;` Refer: [Querying from system.schema_keyspaces generates code=2200](https://dba.stackexchange.com/a/151415) – benSooraj Jul 18 '18 at 03:06
4

The correct way with C* 3.x series is:

List<KeyspaceMetadata> keyspaces = Cluster.getMetadata().getKeyspaces()

Then use getName() on the KeyspaceMetadata instances.

BSB
  • 1,516
  • 13
  • 14
  • 1
    Hey Bsb. I think this answer relates only to when you want to get this information in Java. Is that correct? My question aims to be focussed on cqlsh console queries. Apologies if I seem a bit off... obviously asked this question years ago and not using C* myself now. Asking so that I may improve your answer with edit or perhaps upvote and improve other answers the m – Crowie Mar 27 '18 at 18:54