ALTER KEYSPACE

When you alter a keyspace, you can modify the following options:

  • Replication strategy class

  • Replication factor

  • Durable writes for the commit log

You cannot change the keyspace name. If you need to change the keyspace name, you must create a new keyspace with the desired name and migrate the data accordingly.

Changing the replication factor of a keyspace impacts the distribution of replica nodes across the cluster. It can take time for data to redistribute to new nodes or for removed nodes to scale down.

Synopsis

ALTER KEYSPACE <keyspace_name>
  WITH REPLICATION = { <replication_map> }
  [ AND DURABLE_WRITES = ( true | false ) ];
Legend
Syntax conventions Description

UPPERCASE

Literal keyword.

Lowercase

Not literal.

< >

Variable value. Replace with a user-defined value.

[]

Optional. Square brackets ([]) surround optional command arguments. Do not type the square brackets.

( )

Group. Parentheses ( ( ) ) identify a group to choose from. Do not type the parentheses.

|

Or. A vertical bar (|) separates alternative elements. Type any one of the elements. Do not type the vertical bar.

...

Repeatable. An ellipsis ( ... ) indicates that you can repeat the syntax element as often as required.

'<Literal string>'

Single quotation (') marks must surround literal strings in CQL statements. Use single quotation marks to preserve upper case.

{ <key> : <value> }

Map collection. Braces ({ }) enclose map collections or key value pairs. A colon separates the key and the value.

<<datatype1>,<datatype2>>

Set, list, map, or tuple. Angle brackets ( < > ) enclose data types in a set, list, map, or tuple. Separate the data types with a comma.

<cql_statement>;

End CQL statement. A semicolon (;) terminates all CQL statements.

[--]

Separate the command line options from the command arguments with two hyphens ( -- ). This syntax is useful when arguments might be mistaken for command line options.

' <<schema\> ... </schema\>> '

Search CQL only: Single quotation marks (') surround an entire XML schema declaration.

@<xml_entity>='<xml_entity_type>'

Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files.

Options

Option Description Default

keyspace_name

Name of the keyspace to alter.

WITH REPLICATION

A map of settings for the replication strategy and factor.

The class key is required.

The SimpleStrategy class requires the replication_factor key. It must be a whole integer between 1 and the number of nodes in the cluster. Typically it is set to an odd number.

The NetworkTopologyStrategy class requires a comma-separated list of datacenter names and replication factors. Datacenter names are case sensitive and must match the snitch DC name.

For examples, see Examples.

DURABLE_WRITES

Non-default configuration not recommended.

If false, requests bypass the commit log when writing to the keyspace.

Never disable durable writes when using SimpleStrategy replication.

true

Examples

Use the SimpleStrategy class
ALTER KEYSPACE cycling
  WITH REPLICATION = {
    'class' : 'SimpleStrategy',
    'replication_factor' : 3
  };
Use the NetworkTopologyStrategy class

Switching from SimpleStrategy to NetworkTopologyStrategy is a common operation when moving from a single-datacenter setup to a multi-datacenter setup. With this strategy, you provide a list of datacenters with individual replication factors, instead of a single replication factor for the entire cluster.

You cannot insert data into a table in a keyspace that uses NetworkTopologyStrategy unless you define the datacenter names in the snitch properties file.

Altering the distribution of nodes within multiple datacenters when data is present can be accomplished by adding a datacenter. Then, send new writes to the nodes in the new datacenter, and remove nodes from the old datacenter. You must make this change on all affected nodes.

Verify the spelling of the datacenter name before using this command because datacenter names are case-sensitive and must match the names configured in the snitch properties file.

ALTER KEYSPACE cycling
  WITH REPLICATION = {
    'class' : 'NetworkTopologyStrategy',
    'DC1' : 3 [,
    'DC2' : 5 ]
  };

Run full repair

If you add datacenters or reduce the replication factor, you must run a full repair on the keyspace.

  1. Run a full repair of the altered keyspace on all nodes in the datacenters where you increased the replication factor, including new datacenters added to the replication strategy:

    nodetool repair --full -pr <keyspace_name>
  2. If you decreased the replication factor or removed datacenters from the replication strategy, run a cleanup of the keyspace on all nodes belonging to the relevant datacenters.

    This operation releases the space previously held by the now unused replicas.

    nodetool cleanup <keyspace_name>

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use |  Manage Privacy Choices

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: Contact IBM