Search code examples
cassandracql

How to flush data in all tables of keyspace in cassandra?


I am currently writing tests in golang and I want to get rid of all the data of tables after finishing tests. I was wondering if it is possible to flush the data of all tables in cassandra.

FYI: I am using 3.11 version of Cassandra.


Solution

  • The term "flush" is ambiguous in this case.

    In Cassandra, "flush" is an operation where data is "flushed" from memory and written to disk as SSTables. Flushing can happen automatically based on certain triggers or can be done manually with the nodetool flush command.

    However based on your description, what you want is to "truncate" the contents of tables. You can do this using the following CQL command:

    cqlsh> TRUNCATE ks_name.table_name
    

    You will need to iterate over each table in the keyspace. For more info, see the CQL TRUNCATE command. Cheers!