nodetool compactionhistory
Displays the history of completed compaction operations.
Synopsis
Section titled “Synopsis”nodetool [connection_options] compactionhistorySee connection options for connection options.
Description
Section titled “Description”nodetool compactionhistory shows information about previously completed compactions. This helps analyze compaction patterns, identify problematic tables, and understand historical compaction behavior.
Output Format
Section titled “Output Format”Compaction History:id keyspace_name columnfamily_name compacted_at bytes_in bytes_out rows_merged compaction_propertiesabc12345-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-...}Output Fields
Section titled “Output Fields”| Field | Description |
|---|---|
id | Unique compaction ID |
keyspace_name | Keyspace containing the table |
columnfamily_name | Table name |
compacted_at | Timestamp of compaction completion |
bytes_in | Total bytes read from input SSTables |
bytes_out | Total bytes written to output SSTable |
rows_merged | Distribution of rows merged per SSTable |
compaction_properties | Additional compaction metadata (strategy-specific properties) |
Examples
Section titled “Examples”View All Compaction History
Section titled “View All Compaction History”nodetool compactionhistoryFilter by Keyspace
Section titled “Filter by Keyspace”nodetool compactionhistory | grep my_keyspaceFilter by Table
Section titled “Filter by Table”nodetool compactionhistory | grep my_tableRecent Compactions Only
Section titled “Recent Compactions Only”nodetool compactionhistory | head -20Understanding the Output
Section titled “Understanding the Output”Bytes In vs Bytes Out
Section titled “Bytes In vs Bytes Out”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
Section titled “Rows Merged”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.
Analysis Use Cases
Section titled “Analysis Use Cases”Check Compaction Efficiency
Section titled “Check Compaction Efficiency”# Calculate compression ratio for recent compactionsnodetool compactionhistory | awk 'NR>2 { if ($5 > 0) { ratio = $6 / $5 printf "%s.%s: %.2f\n", $2, $3, ratio }}' | head -10Ratio close to 1.0 = little benefit; lower ratio = good compaction.
Find Tables with Most Compactions
Section titled “Find Tables with Most Compactions”nodetool compactionhistory | awk 'NR>2 {print $2"."$3}' | sort | uniq -c | sort -rn | head -10Check Compaction Timestamps
Section titled “Check Compaction Timestamps”# See when compactions occurrednodetool compactionhistory | awk 'NR>2 {print $4}' | cut -dT -f1 | sort | uniq -cTroubleshooting with Compaction History
Section titled “Troubleshooting with Compaction History”Frequent Small Compactions
Section titled “Frequent Small Compactions”If seeing many small compactions:
nodetool compactionhistory | awk 'NR>2 && $5 < 100000000 {print}' | wc -lMany small compactions may indicate:
- High write rate
- STCS with small sstable_size_in_mb
- Need to tune compaction settings
Large Compactions Taking Too Long
Section titled “Large Compactions Taking Too Long”# Find largest compactionsnodetool compactionhistory | awk 'NR>2 {print $5, $2"."$3}' | sort -rn | head -5Consider:
- LCS for more predictable compaction sizes
- Increasing compaction throughput
- Adding more compaction threads
No Recent Compactions
Section titled “No Recent Compactions”If compactionhistory shows old entries only:
# Check if compactions are runningnodetool compactionstats
# Check if auto-compaction is enablednodetool statusautocompaction my_keyspace my_tableMonitoring Compaction Patterns
Section titled “Monitoring Compaction Patterns”Daily Compaction Volume
Section titled “Daily Compaction Volume”#!/bin/bashecho "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 }}' | sortTable-Level Analysis
Section titled “Table-Level Analysis”#!/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 -rnHistory Retention
Section titled “History Retention”Compaction history is stored in system.compaction_history table:
SELECT * FROM system.compaction_history LIMIT 10;History Retention (7 Days Default)
- The
system.compaction_historytable 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
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| compactionstats | Current compaction status |
| tablestats | Table statistics including SSTable count |
| compact | Force compaction |
| setcompactionthroughput | Control compaction speed |