nodetool garbagecollect
Removes deleted data (tombstones) from SSTables without full compaction.
Synopsis
Section titled “Synopsis”nodetool [connection_options] garbagecollect [options] [--] [keyspace [table ...]]See connection options for connection options.
Description
Section titled “Description”nodetool garbagecollect performs a targeted cleanup of tombstones and expired data without triggering a full compaction. This is lighter weight than compact and specifically targets garbage collection of deleted data.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Keyspace to garbage collect. If omitted, processes all keyspaces |
table | Specific table(s) to garbage collect |
Options
Section titled “Options”| Option | Description |
|---|---|
-g, --granularity | ROW or CELL level granularity |
-j, --jobs <jobs> | Number of concurrent jobs (default: 1, use 0 for all available compaction threads) |
Granularity Levels
Section titled “Granularity Levels”ROW Granularity (Default)
Section titled “ROW Granularity (Default)”nodetool garbagecollect -g ROW my_keyspace my_table- Removes entire rows that are fully deleted
- More efficient for row-level deletes
- Less I/O intensive
CELL Granularity
Section titled “CELL Granularity”nodetool garbagecollect -g CELL my_keyspace my_table- Removes individual deleted cells within rows
- More thorough cleanup
- Higher I/O cost
When to Use
Section titled “When to Use”After Bulk Deletes
Section titled “After Bulk Deletes”# After deleting many rowsDELETE FROM my_keyspace.my_table WHERE partition_key IN (...);
# Clean up tombstonesnodetool garbagecollect my_keyspace my_tableTTL-Heavy Tables
Section titled “TTL-Heavy Tables”For tables with many expiring rows:
nodetool garbagecollect my_keyspace ttl_tableInstead of Full Compaction
Section titled “Instead of Full Compaction”# Lighter alternative to:# nodetool compact my_keyspace my_table
# Use garbage collect for tombstone cleanup only:nodetool garbagecollect my_keyspace my_tableExamples
Section titled “Examples”Garbage Collect Specific Table
Section titled “Garbage Collect Specific Table”nodetool garbagecollect my_keyspace my_tableGarbage Collect All Tables in Keyspace
Section titled “Garbage Collect All Tables in Keyspace”nodetool garbagecollect my_keyspaceCell-Level Garbage Collection
Section titled “Cell-Level Garbage Collection”nodetool garbagecollect -g CELL my_keyspace my_tableParallel Garbage Collection
Section titled “Parallel Garbage Collection”nodetool garbagecollect -j 4 my_keyspaceTombstone Eligibility
Section titled “Tombstone Eligibility”Tombstones are only removed when:
- Age > gc_grace_seconds - Default 10 days
- All replicas have seen the tombstone - Via repair or normal writes
-- Check table's gc_grace_secondsSELECT gc_grace_seconds FROM system_schema.tablesWHERE keyspace_name = 'my_keyspace' AND table_name = 'my_table';gc_grace_seconds
Tombstones younger than gc_grace_seconds cannot be removed. Running garbage collect on fresh deletes has no effect.
Comparison with Compact
Section titled “Comparison with Compact”| Aspect | garbagecollect | compact |
|---|---|---|
| Purpose | Remove tombstones | Merge all SSTables |
| Scope | Targeted cleanup | Full rewrite |
| I/O Impact | Lower | Higher |
| Duration | Shorter | Longer |
| Space needed | Less | More |
Use garbagecollect when you only need tombstone cleanup.
Use compact when you need full SSTable consolidation.
Monitoring
Section titled “Monitoring”Check Progress
Section titled “Check Progress”nodetool compactionstatsGarbage collection appears as a compaction operation.
Check Tombstone Counts Before/After
Section titled “Check Tombstone Counts Before/After”# Beforenodetool tablestats my_keyspace.my_table | grep "tombstones"
# Run garbage collectnodetool garbagecollect my_keyspace my_table
# Afternodetool tablestats my_keyspace.my_table | grep "tombstones"Common Scenarios
Section titled “Common Scenarios”High Tombstone Warnings
Section titled “High Tombstone Warnings”If logs show tombstone warnings:
WARN Read 5000 live rows and 100000 tombstone cells# Clean up tombstones (after gc_grace_seconds has passed)nodetool garbagecollect my_keyspace problematic_tablePrepare for Major Compaction
Section titled “Prepare for Major Compaction”# Clean tombstones first (faster)nodetool garbagecollect my_keyspace
# Then compact if needednodetool compact my_keyspaceAfter Range Deletes
Section titled “After Range Deletes”Range deletes create many tombstones:
# Wait for gc_grace_seconds# Then clean upnodetool garbagecollect my_keyspace my_tableBest Practices
Section titled “Best Practices”Garbage Collection Guidelines
- Wait for gc_grace_seconds - Tombstones must be old enough
- Run repair first - Ensure tombstones propagated to all replicas
- Monitor disk space - Some temporary space needed
- Start with ROW granularity - Less I/O, often sufficient
- Use CELL for column deletes - When updating individual columns
Scripting Example
Section titled “Scripting Example”#!/bin/bash# Clean tombstones from tables with high tombstone counts
THRESHOLD=10000
for ks_table in $(nodetool tablestats 2>/dev/null | grep -B5 "Tombstones" | \ grep "Table:" | awk '{print $2}'); do
tombstones=$(nodetool tablestats $ks_table | grep "tombstones" | \ awk '{sum += $NF} END {print sum}')
if [ "$tombstones" -gt "$THRESHOLD" ]; then echo "Garbage collecting $ks_table (tombstones: $tombstones)" nodetool garbagecollect $ks_table fidoneRelated Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| compact | Full compaction (heavier) |
| tablestats | Check tombstone counts |
| scrub | Rebuild SSTables |
| cleanup | Remove non-local data |