Cassandra DBA – Tricks and tips

Change replication factor for an existing keyspace

ALTER KEYSPACE acme WITH REPLICATION =  { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };

Drop a keyspace


Drop a column

ALTER TABLE person DROP mail;

Add a column

ALTER TABLE person ADD email text;

Counting keys (rows) in column. Here is a quick way to get an “estimated” count

nodetool cfstats acme.person

Command to check cluster / node status

nodetool status

Force restart of datastax agent

service datastax-agent force-reload

How to insert current date-time into a table using CQL?

This can be done using the now and dateof functions.

The now function takes no arguments and generates a new unique timeuuid (at the time where the statement using it is executed).

The dateof function takes a timeuuid argument and extracts the embedded timestamp.

INSERT INTO account (name, created) VALUES ('acme', dateof(now()));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s