Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool compactionhistory

Displays the history of completed compaction operations.


Terminal window
nodetool [connection_options] compactionhistory

See connection options for connection options.

nodetool compactionhistory shows information about previously completed compactions. This helps analyze compaction patterns, identify problematic tables, and understand historical compaction behavior.


Compaction History:
id keyspace_name columnfamily_name compacted_at bytes_in bytes_out rows_merged compaction_properties
abc12345-def6-7890-abcd-ef1234567890 my_keyspace my_table 2024-01-15T10:30:00 1073741824 536870912 {1:150, 2:50} {id:abc12345-...}
def67890-abcd-1234-ef56-7890abcdef12 my_keyspace my_table 2024-01-15T09:15:00 2147483648 1073741824 {1:300, 2:100} {id:def67890-...}

FieldDescription
idUnique compaction ID
keyspace_nameKeyspace containing the table
columnfamily_nameTable name
compacted_atTimestamp of compaction completion
bytes_inTotal bytes read from input SSTables
bytes_outTotal bytes written to output SSTable
rows_mergedDistribution of rows merged per SSTable
compaction_propertiesAdditional compaction metadata (strategy-specific properties)

Terminal window
nodetool compactionhistory
Terminal window
nodetool compactionhistory | grep my_keyspace
Terminal window
nodetool compactionhistory | grep my_table
Terminal window
nodetool compactionhistory | head -20

bytes_in: 1073741824 bytes_out: 536870912
  • bytes_in > bytes_out: Data was compacted (tombstones removed, duplicates merged)
  • bytes_in ≈ bytes_out: Little compaction benefit (fresh data)
  • High ratio indicates effective compaction
rows_merged: {1:150, 2:50}
  • 1:150 - 150 rows appeared in only 1 SSTable (no merging needed)
  • 2:50 - 50 rows appeared in 2 SSTables (were merged)

Higher numbers in the merge count indicate more overwrites or deletions being resolved.


Terminal window
# Calculate compression ratio for recent compactions
nodetool compactionhistory | awk 'NR>2 {
if ($5 > 0) {
ratio = $6 / $5
printf "%s.%s: %.2f\n", $2, $3, ratio
}
}' | head -10

Ratio close to 1.0 = little benefit; lower ratio = good compaction.

Terminal window
nodetool compactionhistory | awk 'NR>2 {print $2"."$3}' | sort | uniq -c | sort -rn | head -10
Terminal window
# See when compactions occurred
nodetool compactionhistory | awk 'NR>2 {print $4}' | cut -dT -f1 | sort | uniq -c

If seeing many small compactions:

Terminal window
nodetool compactionhistory | awk 'NR>2 && $5 < 100000000 {print}' | wc -l

Many small compactions may indicate:

  • High write rate
  • STCS with small sstable_size_in_mb
  • Need to tune compaction settings
Terminal window
# Find largest compactions
nodetool compactionhistory | awk 'NR>2 {print $5, $2"."$3}' | sort -rn | head -5

Consider:

  • LCS for more predictable compaction sizes
  • Increasing compaction throughput
  • Adding more compaction threads

If compactionhistory shows old entries only:

Terminal window
# Check if compactions are running
nodetool compactionstats
# Check if auto-compaction is enabled
nodetool statusautocompaction my_keyspace my_table

compaction_daily_stats.sh
#!/bin/bash
echo "Date,Compactions,BytesIn,BytesOut"
nodetool compactionhistory | awk 'NR>2 {
date = substr($4, 1, 10)
counts[date]++
bytes_in[date] += $5
bytes_out[date] += $6
}
END {
for (d in counts) {
printf "%s,%d,%.2fGB,%.2fGB\n", d, counts[d], bytes_in[d]/1073741824, bytes_out[d]/1073741824
}
}' | sort
#!/bin/bash
# Analyze compaction efficiency by table
echo "Table,Compactions,AvgRatio"
nodetool compactionhistory | awk 'NR>2 && $5 > 0 {
table = $2"."$3
counts[table]++
ratios[table] += $6/$5
}
END {
for (t in counts) {
printf "%s,%d,%.3f\n", t, counts[t], ratios[t]/counts[t]
}
}' | sort -t, -k2 -rn

Compaction history is stored in system.compaction_history table:

SELECT * FROM system.compaction_history LIMIT 10;

History Retention (7 Days Default)

  • The system.compaction_history table has a default TTL of 7 days
  • Entries are automatically removed after this retention period via TTL expiration, not compaction
  • For long-term analysis, export to external monitoring before entries expire

CommandRelationship
compactionstatsCurrent compaction status
tablestatsTable statistics including SSTable count
compactForce compaction
setcompactionthroughputControl compaction speed