Manage keyspaces
Astra Managed Clusters databases organize data into tables, which exist inside keyspaces.
Each database must have at least one keyspace, and you can create more as needed. For example, you can categorize your data by data model or separate unique data from your other data. Typically, a cluster has one keyspace per application.
Keyspaces are like schemas in relational databases. They help keep related tables of information in a single place within your database.
User-defined types are also stored at the keyspace level.
The replication strategy and factor are managed by Astra.
Create a keyspace
A keyspace is a container for tables, similar to a schema in a relational database. Keyspaces help you organize related tables. For example, you can have different data models for each keyspace or store unique data in unique keyspaces.
You can use multiple keyspaces in a single region to build applications on a per-keyspace data model.
You can create keyspaces in the Astra Portal, with the DevOps API, or with the Astra CLI.
Astra DB doesn’t support the CQL CREATE KEYSPACE command.
- Use the Astra Portal
-
-
In the Astra Portal, click Managed clusters, and then click the name of the database that you want to modify.
-
Click Add Keyspace.
-
Enter a keyspace name.
Keyspace names must follow these rules:
-
Must start with a letter or number
-
Can contain letters, numbers, and underscores
-
Cannot exceed 48 characters.
-
Cannot be the reserved words
dseorsystem -
Must be unique within the database
-
-
Click Save.
-
- Use the DevOps API
-
To create a keyspace with the DevOps API, use
POST /v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME:curl -sS -L -X POST "https://api.astra.datastax.com/v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME" \ --header "Authorization: Bearer APPLICATION_TOKEN" \ --header "Content-Type: application/json"Replace the following:
-
DATABASE_ID: The database ID. -
KEYSPACE_NAME: The name of the keyspace to create. Keyspace names must follow these rules:-
Must start with a letter or number
-
Can contain letters, numbers, and underscores
-
Cannot exceed 48 characters.
-
Cannot be the reserved words
dseorsystem -
Must be unique within the database
-
-
APPLICATION_TOKEN: An application token with the Database Administrator role.
-
- Use the Astra CLI
-
Use the
astra db create-keyspacecommand.
The database enters Maintenance status while it creates the keyspace. When the database returns to Active status, you can use the new keyspace. For example, you can create a table and load data into the keyspace.
Get keyspace details
Use the CQL DESCRIBE KEYSPACE command to get the full details of a keyspace, including all database objects the keyspace contains.
You can use the output from a DESCRIBE command to re-create the keyspace and all its components in another database.
The output includes all settings for tables and other objects including the default settings. When re-creating a keyspace in another environment, verify that the settings are compatible, such as the keyspace replication factor datacenter names.
Alter keyspace to enable Graph engine
For a Tier E Astra Managed Clusters database, you can use the DevOps API to enable Graph engine support on an existing keyspace:
curl -sS -L -X POST "https://api.astra.datastax.com/v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME/actions/alterWithEngine" \
--header "Authorization: Bearer APPLICATION_TOKEN" \
--header "Content-Type: application/json"
Replace the following:
-
DATABASE_ID: The database ID. -
KEYSPACE_NAME: The name of the keyspace to alter. -
APPLICATION_TOKEN: An application token with the Database Administrator role.
Delete a keyspace
|
Deleting a keyspace permanently deletes all tables and data in the keyspace. |
You can delete keyspaces in the Astra Portal, with the DevOps API, or with the Astra CLI.
Astra DB doesn’t support the CQL DROP KEYSPACE command.
- Use the Astra Portal
-
-
In the Astra Portal, click Managed clusters, and then click the name of the database that you want to modify.
-
In the Keyspaces section, find the keyspace you want to delete, click More, and then click Delete.
-
In the Delete Keyspace dialog, enter the keyspace name, and then click Delete Keyspace.
-
- Use the DevOps API
-
To delete a keyspace with the DevOps API, use
DELETE /v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME:curl -sS -L -X DELETE "https://api.astra.datastax.com/v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME" \ --header "Authorization: Bearer APPLICATION_TOKEN" \ --header "Content-Type: application/json"Replace the following:
-
DATABASE_ID: The database ID. -
KEYSPACE_NAME: The name of the keyspace to delete. -
APPLICATION_TOKEN: An application token with the Database Administrator role.
-
- Use the Astra CLI
-
Use the
astra db delete-keyspacecommand.
The database enters Maintenance status while it deletes the keyspace, its tables, and any data within those tables.
Create a table
You can use the CQL console (embedded CQL shell) in the Astra Portal, a standalone CQL shell installation, or a Cassandra driver. For more information, see Cassandra Query Language (CQL) for Astra DB.
The following steps explain how to create a table with the CQL console:
-
In the Astra Portal, click Managed clusters, and then click the name of the database that you want to modify.
-
In the Keyspaces section, note the name of the keyspace where you want to create the table.
-
Click CQL console, and then wait for the
token@cqlsh>prompt to appear. -
Select the keyspace that you want to create the table in:
use KEYSPACE_NAME; -
Create the table:
CREATE TABLE users ( firstname text, lastname text, email text, "favorite color" text, PRIMARY KEY (firstname, lastname) ) WITH CLUSTERING ORDER BY (lastname ASC);
After you create a table, load data into the table.
Create a Solr index for a table
For a Tier E Astra Managed Clusters database, you can use the DevOps API to create a Solr index on an existing table:
curl -sS -L -X POST "https://api.astra.datastax.com/v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME/tables/TABLE_NAME/solr/createCorewithconfigs?QUERY_PARAMETERS" \
--header "Authorization: Bearer APPLICATION_TOKEN" \
--header "Content-Type: application/json"
Replace the following:
-
DATABASE_ID: The database ID. -
KEYSPACE_NAME: The keyspace where you want to create the Solr index. -
TABLE_NAME: The table to use for the Solr index. -
QUERY_PARAMETERS: Optional query parameters to configure the Solr index:-
generateResources: Whether to generate the Solr index using the existing CQL table metadata.If
true(default), the Solr index is created using the existing CQL table metadata.If
false, you must provide the Solr schema and Solr config files inschemaandsolrconfig. -
schema: The path to the Solr schema file to use when creating the Solr index ifgenerateResourcesisfalse. For example,?schema=@/path/to/schema.xml. -
solrconfig: The path to the Solr config file to use when creating the Solr index ifgenerateResourcesisfalse. For example,?solrconfig=@/path/to/solrconfig.xml.
-
Delete a table
You can use the CQL console (embedded CQL shell) in the Astra Portal, a standalone CQL shell installation, or a Cassandra driver. For more information, see Cassandra Query Language (CQL) for Astra DB.
|
Deleting a table permanently deletes all data in the table. |
The following steps explain how to delete a table with the CQL console:
-
In the Astra Portal, click Managed clusters, and then click the name of the database that you want to modify.
-
In the Keyspaces section, note the name of the keyspace that contains the table you want to delete.
-
Click CQL console, and then wait for the
token@cqlsh>prompt to appear. -
Select the keyspace that contains the table you want to delete:
use KEYSPACE_NAME; -
Get a list of all tables in the keyspace:
desc tables; -
Delete the table and all of its data:
drop table TABLE_NAME;
The table and its data are deleted.