sstabledump
Exports SSTable contents as JSON for inspection, debugging, and data analysis.
Synopsis
Section titled “Synopsis”sstabledump [options] <sstable_file>Description
Section titled “Description”sstabledump reads an SSTable file and outputs its contents in JSON format. This tool is essential for:
- Debugging data issues - Inspect actual stored values
- Analyzing tombstones - Find deletion markers causing issues
- Examining partition structure - Understand data layout
- Data recovery - Extract data from corrupted or orphaned SSTables
- Schema change analysis - See how data was stored before schema changes
The output includes all rows, cells, tombstones, and TTL information stored in the SSTable.
Cassandra Must Be Stopped
For consistent results, Cassandra should be stopped before running sstabledump. The tool can run while Cassandra is active, but results may be inconsistent if compaction occurs.
How It Works
Section titled “How It Works”Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
sstable_file | Path to the SSTable Data.db file |
Options
Section titled “Options”| Option | Description |
|---|---|
-d | Output each row as a separate JSON object (JSONL format) |
-e | Only output keys (no values) |
-k <key> | Only output data for the specified partition key |
-x <key> | Exclude the specified partition key |
-t | Include only tombstones in output |
-l | Limit output to first N partitions |
Output Format
Section titled “Output Format”Standard JSON Output
Section titled “Standard JSON Output”[ { "partition" : { "key" : [ "user123" ], "position" : 0 }, "rows" : [ { "type" : "row", "position" : 48, "clustering" : [ "2024-01-15" ], "liveness_info" : { "tstamp" : "2024-01-15T10:30:00.000Z" }, "cells" : [ { "name" : "email", "value" : "user@example.com" }, { "name" : "name", "value" : "John Doe" }, { "name" : "status", "value" : "active" } ] } ] }]Row-per-Line Format (-d)
Section titled “Row-per-Line Format (-d)”{"partition":{"key":["user123"],"position":0},"rows":[...]}{"partition":{"key":["user456"],"position":512},"rows":[...]}{"partition":{"key":["user789"],"position":1024},"rows":[...]}Keys Only Format (-e)
Section titled “Keys Only Format (-e)”[ { "partition" : { "key" : [ "user123" ], "position" : 0 } }, { "partition" : { "key" : [ "user456" ], "position" : 512 } }]Examples
Section titled “Examples”Dump Entire SSTable
Section titled “Dump Entire SSTable”# Dump to stdoutsstabledump /var/lib/cassandra/data/my_keyspace/my_table-abc123/nb-1-big-Data.db
# Save to filesstabledump /var/lib/cassandra/data/my_keyspace/my_table-abc123/nb-1-big-Data.db > dump.jsonDump Specific Partition
Section titled “Dump Specific Partition”# Dump only data for partition key "user123"sstabledump -k "user123" /path/to/sstable-Data.db
# For composite partition keyssstabledump -k "region:us-east:tenant:acme" /path/to/sstable-Data.dbDump Keys Only
Section titled “Dump Keys Only”# List all partition keys in SSTablesstabledump -e /path/to/sstable-Data.db
# Count partitionssstabledump -e /path/to/sstable-Data.db | grep -c '"partition"'Dump Tombstones Only
Section titled “Dump Tombstones Only”# Find all tombstones (deletions) in SSTablesstabledump -t /path/to/sstable-Data.dbRow-per-Line for Processing
Section titled “Row-per-Line for Processing”# Output suitable for jq processingsstabledump -d /path/to/sstable-Data.db | jq '.partition.key'
# Count rows per partitionsstabledump -d /path/to/sstable-Data.db | jq '.rows | length'Limit Output Size
Section titled “Limit Output Size”# Dump only first 10 partitionssstabledump -l 10 /path/to/sstable-Data.dbExclude Specific Partition
Section titled “Exclude Specific Partition”# Dump all except partition "problem_key"sstabledump -x "problem_key" /path/to/sstable-Data.dbCommon Use Cases
Section titled “Common Use Cases”Finding Tombstones
Section titled “Finding Tombstones”#!/bin/bash# find_tombstones.sh - Identify tables with tombstone issues
DATA_DIR="/var/lib/cassandra/data"KEYSPACE="$1"TABLE="$2"
for sstable in ${DATA_DIR}/${KEYSPACE}/${TABLE}-*/*-Data.db; do tombstone_count=$(sstabledump -t "$sstable" 2>/dev/null | grep -c '"type" : "range_tombstone"') if [ "$tombstone_count" -gt 0 ]; then echo "$sstable: $tombstone_count tombstones" fidoneAnalyzing Partition Sizes
Section titled “Analyzing Partition Sizes”#!/bin/bash# partition_sizes.sh - Find large partitions
SSTABLE="$1"
sstabledump -d "$SSTABLE" | while read line; do key=$(echo "$line" | jq -r '.partition.key[0]') row_count=$(echo "$line" | jq '.rows | length') echo "$key: $row_count rows"done | sort -t: -k2 -n -r | head -20Data Recovery Script
Section titled “Data Recovery Script”#!/bin/bash# recover_partition.sh - Extract specific partition data
SSTABLE="$1"PARTITION_KEY="$2"OUTPUT_FILE="$3"
echo "Extracting partition '$PARTITION_KEY' from $SSTABLE"sstabledump -k "$PARTITION_KEY" "$SSTABLE" > "$OUTPUT_FILE"
if [ -s "$OUTPUT_FILE" ]; then echo "Data saved to $OUTPUT_FILE" rows=$(jq '.[0].rows | length' "$OUTPUT_FILE") echo "Found $rows rows"else echo "No data found for partition key '$PARTITION_KEY'"fiComparing SSTables
Section titled “Comparing SSTables”#!/bin/bash# compare_sstables.sh - Compare partition keys between SSTables
SSTABLE1="$1"SSTABLE2="$2"
# Extract keys from bothsstabledump -e "$SSTABLE1" | jq -r '.[].partition.key[0]' | sort > /tmp/keys1.txtsstabledump -e "$SSTABLE2" | jq -r '.[].partition.key[0]' | sort > /tmp/keys2.txt
echo "Keys only in first SSTable:"comm -23 /tmp/keys1.txt /tmp/keys2.txt
echo "Keys only in second SSTable:"comm -13 /tmp/keys1.txt /tmp/keys2.txt
echo "Keys in both:"comm -12 /tmp/keys1.txt /tmp/keys2.txt | wc -lUnderstanding Output Fields
Section titled “Understanding Output Fields”Partition Object
Section titled “Partition Object”{ "partition" : { "key" : [ "partition_key_value" ], "position" : 0, "deletion_info" : { // Present if partition deleted "marked_deleted" : "timestamp", "local_delete_time" : "timestamp" } }}Row Object
Section titled “Row Object”{ "type" : "row", "position" : 48, "clustering" : [ "clustering_value1", "clustering_value2" ], "liveness_info" : { "tstamp" : "2024-01-15T10:30:00.000Z", "ttl" : 86400, // TTL in seconds "expires_at" : "2024-01-16T10:30:00.000Z", "expired" : false }, "deletion_info" : { ... }, // Present if row deleted "cells" : [ ... ]}Cell Object
Section titled “Cell Object”{ "name" : "column_name", "value" : "cell_value", "tstamp" : "2024-01-15T10:30:00.000Z", "ttl" : 86400, // If TTL set "expires_at" : "2024-01-16T10:30:00.000Z", "deletion_info" : { ... } // If cell deleted}Tombstone Types
Section titled “Tombstone Types”// Cell tombstone{ "name" : "column_name", "deletion_info" : { "marked_deleted" : "2024-01-15T10:30:00.000Z", "local_delete_time" : "2024-01-15T10:30:00.000Z" }}
// Range tombstone{ "type" : "range_tombstone_bound", "start" : { "type" : "inclusive", "clustering" : [ "start_value" ] }, "end" : { "type" : "inclusive", "clustering" : [ "end_value" ] }, "deletion_info" : { ... }}
// Partition tombstone{ "partition" : { "key" : [ "partition_key" ], "deletion_info" : { "marked_deleted" : "timestamp", "local_delete_time" : "timestamp" } }}Output Processing with jq
Section titled “Output Processing with jq”Extract All Partition Keys
Section titled “Extract All Partition Keys”sstabledump /path/to/sstable-Data.db | jq -r '.[].partition.key[0]'Count Rows Per Partition
Section titled “Count Rows Per Partition”sstabledump /path/to/sstable-Data.db | jq '.[] | {key: .partition.key[0], rows: (.rows | length)}'Find Expired TTL Data
Section titled “Find Expired TTL Data”sstabledump /path/to/sstable-Data.db | jq '.[].rows[].cells[] | select(.expired == true)'Extract Specific Column Values
Section titled “Extract Specific Column Values”sstabledump /path/to/sstable-Data.db | jq '.[].rows[].cells[] | select(.name == "email") | .value'Find Large Partitions
Section titled “Find Large Partitions”sstabledump /path/to/sstable-Data.db | jq '[.[] | {key: .partition.key[0], rows: (.rows | length)}] | sort_by(.rows) | reverse | .[0:10]'Troubleshooting
Section titled “Troubleshooting”Out of Memory
Section titled “Out of Memory”# Large SSTables can exhaust memory
# Option 1: Increase heapexport JVM_OPTS="-Xmx8G"sstabledump /path/to/sstable-Data.db
# Option 2: Use streaming outputsstabledump -d /path/to/sstable-Data.db | head -100
# Option 3: Dump specific partition onlysstabledump -k "specific_key" /path/to/sstable-Data.dbPermission Denied
Section titled “Permission Denied”# Run as cassandra usersudo -u cassandra sstabledump /var/lib/cassandra/data/.../nb-1-big-Data.db"Unable to read SSTable" Error
Section titled “"Unable to read SSTable" Error”# SSTable may be corrupted - verify firstsstableverify keyspace table
# If corrupted, cannot dump - scrub firstsstablescrub keyspace tableComposite Key Formatting
Section titled “Composite Key Formatting”# For composite partition keys, use colon separator# Schema: PRIMARY KEY ((region, tenant), date)sstabledump -k "us-east:acme" /path/to/sstable-Data.db
# Check key format in output firstsstabledump -e -l 1 /path/to/sstable-Data.dbPerformance Considerations
Section titled “Performance Considerations”| SSTable Size | Approximate Time | Memory Usage |
|---|---|---|
| 100 MB | ~5 seconds | ~500 MB |
| 1 GB | ~30 seconds | ~2 GB |
| 10 GB | ~5 minutes | ~8 GB+ |
| 100 GB | Not recommended | Excessive |
For large SSTables, use:
-kto dump specific partitions-lto limit output-dfor streaming output-efor keys only
Best Practices
Section titled “Best Practices”sstabledump Guidelines
- Use
-dfor large files - Enables streaming processing - Target specific partitions - Use
-kwhen possible - Pipe to jq - Process JSON efficiently
- Redirect to file - Avoid terminal buffer issues
- Stop Cassandra - For consistent results
- Check memory - Large SSTables need significant heap
- Use for diagnostics - Not for bulk data export
Cautions
- Output can be very large (gigabytes)
- Memory usage scales with SSTable size
- Sensitive data will be exposed in output
- Not suitable for production data export
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| sstablemetadata | View SSTable statistics |
| sstablepartitions | Find large partitions |
| sstableexpiredblockers | Find tombstone blockers |
| sstableutil | List SSTable files |
| sstableverify | Verify SSTable before dump |