Get Size of a Table in Cassandra - Cassandra / CQL Tutorial

Get Size of a Table in Cassandra

If you need to know informaiton about table or tables you can use Nodetool cfstats command. 

Syntax:

If you will only provide the name of keyspace, it will provide stats for all the tables in that keyspace.

$ Nodetool cfstats KeyspaceName

To get the stats for single table , use below

$ Nodetool cfstats KeyspaceName.TableName 

Example:

Suppoe I have table employee in TechbrothersTutorials keyspace, to get the stats including size of table we can use below statement.

$ nodetool cfstats techbrotherstutorials.employee;

Output:

Keyspace : techbrotherstutorials
        Read Count: 0
        Read Latency: NaN ms.
        Write Count: 7
        Write Latency: 0.07385714285714286 ms.
        Pending Flushes: 0
                Table: employee
                SSTable count: 1

                Space used (live): 5227
                Space used (total): 5227

                Space used by snapshots (total): 0
                Off heap memory used (total): 54
                SSTable Compression Ratio: 1.1194029850746268
                Number of keys (estimate): 1
                Memtable cell count: 0
                Memtable data size: 0
                Memtable off heap memory used: 0
                Memtable switch count: 1
                Local read count: 0
                Local read latency: NaN ms
                Local write count: 1
                Local write latency: NaN ms
                Pending flushes: 0
                Percent repaired: 0.0
                Bloom filter false positives: 0
                Bloom filter false ratio: 0.00000
                Bloom filter space used: 16
                Bloom filter off heap memory used: 8
                Index summary off heap memory used: 38
                Compression metadata off heap memory used: 8
                Compacted partition minimum bytes: 61
                Compacted partition maximum bytes: 72
                Compacted partition mean bytes: 72
                Average live cells per slice (last five minutes): NaN
                Maximum live cells per slice (last five minutes): 0
                Average tombstones per slice (last five minutes): NaN
                Maximum tombstones per slice (last five minutes): 0
                Dropped Mutations: 0

 

Notice the Space Size in above output , that is space occupied by table in bytes. Sometime you might not see the correct size as the data is not flushed to disk from memtables. You can use "Nodetool flush KeyspaceName" to flush the data from memtables to disk and check the size of table/s again by using NodeTool cfstats command.