Manage keyspaces

A keyspace is the top-level database object that controls the replication for the object it contains at each datacenter in the cluster. Keyspaces contain tables, materialized views and user-defined types, functions, and aggregates. Typically, a cluster has one keyspace per application. Because replication is controlled on a per-keyspace basis, store data with different replication requirements in the same region in different keyspaces. Keyspaces are not a significant map layer within the data model.

The following information is provided for informational purposes for Astra DB users. Astra DB uses the NetworkTopologyStrategy, which is controlled by Astra DB and cannot be modified.

Replication strategy and factor

In Astra, keyspaces hold the datacenter names associated with your Astra regions and defines the replication factor (3 for writes in LOCAL_QUORUM) for each datacenter. A replication factor of 3 ensures against losing your data. You can create keyspaces in the Astra Portal or with the DevOps API.

When you create or modify a keyspace, the SimpleStrategy replication strategy class is automatically assigned.

SimpleStrategy class is intended for evaluating DataStax Enterprise. For production use or for use with mixed workloads, use the NetworkTopologyStrategy class.

You can also use NetworkTopologyStrategy for evaluation purposes by changing the default snitch, SimpleSnitch, to a network-aware snitch. Choose a snitch and define one or more datacenter names in the snitch properties file, and then use the datacenter name(s) to set the keyspace replication factor. For example, if the cluster uses the GossipingPropertyFileSnitch, create the keyspace using the user-defined datacenter and rack names in the cassandra-rackdc.properties file. If the cluster uses the Configuring the Amazon EC2 single-region snitch, create the keyspace using EC2 datacenter and rack names. If the cluster uses the Configuring the Google Cloud Platform snitch, create the keyspace using GoogleCloud datacenter and rack names.

Show the keyspace details

In cqlsh, the DESCRIBE KEYSPACE command outputs the full details of the keyspace, including all database objects the keyspace contains. Use the output from the DESCRIBE command to recreate the keyspace and all its components.

The output includes all settings for tables and other objects including the default settings. When recreating a keyspace in another environment, verify that the settings are compatible, such as the keyspace replication factor datacenter names.

Add a keyspace

Creating a database with multiple keyspaces allows you to create different data models for each keyspace or store unique data in unique keyspaces. Multiple keyspaces within a single region allows for an application built on a per-keyspace data model.

  1. In the Astra Portal, go to Databases, and click your database’s name.

  2. Click Add Keyspace.

  3. Enter a keyspace name that meets the following requirements:

    • No empty spaces or null

    • A maximum of 48 characters

    • Only alphanumeric characters and underscores

  4. Click Save.

Delete a keyspace

If you delete a keyspace, all data in that keyspace is removed and can’t be recovered.

  1. In the Astra Portal, go to Databases, and click your database’s name.

  2. Locate the keyspace that you want to delete, click more_vertMore, and then click Delete.

  3. To confirm deletion, enter the keyspace name, and then click Delete Keyspace.

The keyspace and all of its data are permanently deleted.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com