Skip to content

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

nodetool enableautocompaction

Re-enables automatic compaction for specified keyspaces and tables.


Terminal window
nodetool [connection_options] enableautocompaction [--] [<keyspace> <tables>...]

See connection options for connection options.

nodetool enableautocompaction restores automatic compaction behavior for one or more tables after it was temporarily disabled with disableautocompaction. When auto-compaction is enabled, Cassandra's compaction strategy continuously evaluates SSTables and triggers compaction operations based on configured thresholds and policies.

Automatic compaction is essential for:

  • Maintaining read performance - Merging SSTables reduces the number of files to scan
  • Reclaiming disk space - Removing tombstones and expired data
  • Data consistency - Ensuring deleted data is eventually purged
  • Preventing SSTable proliferation - Keeping file counts manageable

Default State

Auto-compaction is enabled by default on all tables. This command is only needed after explicitly disabling it with disableautocompaction.


ArgumentDescription
keyspaceTarget keyspace name. If omitted, applies to all keyspaces
tablesSpace-separated list of table names. If omitted, applies to all tables in the keyspace

Terminal window
# Re-enable compaction cluster-wide on this node
nodetool enableautocompaction
Terminal window
# Re-enable for all tables in a keyspace
nodetool enableautocompaction my_keyspace
Terminal window
# Re-enable for specific tables only
nodetool enableautocompaction my_keyspace users orders products
Terminal window
# Enable and verify
nodetool enableautocompaction my_keyspace my_table
nodetool statusautocompaction my_keyspace my_table
# Expected: running=true

Re-enable compaction after loading large amounts of data:

Terminal window
# 1. Disable compaction before bulk load
nodetool disableautocompaction my_keyspace my_table
# 2. Load data (sstableloader, COPY, etc.)
sstableloader -d node1,node2 /path/to/sstables/
# 3. Re-enable compaction
nodetool enableautocompaction my_keyspace my_table
# 4. Optionally force immediate compaction
nodetool compact my_keyspace my_table

Restore normal operation after maintenance:

Terminal window
# After repair or other maintenance
nodetool enableautocompaction my_keyspace
# Monitor compaction activity
watch nodetool compactionstats

When compaction was disabled to investigate issues:

Terminal window
# Issue identified and resolved
nodetool enableautocompaction
# Verify compaction resumes
nodetool compactionstats

When bringing a node back to normal operation:

Terminal window
# Node recovered, restore full functionality
nodetool enableautocompaction
# Check for compaction backlog
nodetool compactionstats

  1. The table is marked as eligible for automatic compaction
  2. The compaction strategy begins evaluating SSTables
  3. Compaction tasks are scheduled based on strategy rules
  4. Pending compaction backlog begins processing

The enabled auto-compaction respects the table's configured compaction strategy:

StrategyBehavior After Enable
SizeTieredCompactionStrategy (STCS)Compacts SSTables of similar sizes
LeveledCompactionStrategy (LCS)Promotes SSTables through levels
TimeWindowCompactionStrategy (TWCS)Compacts within time windows
UnifiedCompactionStrategy (UCS)Adaptive compaction (Cassandra 5.0+)

AspectImpact
Compaction schedulingResumes immediately
Disk I/OMay increase as backlog processes
CPU usageCompaction threads become active
Pending tasksBegin processing
AspectImpact
SSTable countBegins decreasing
Read latencyImproves as SSTables merge
Disk usageMay spike during compaction
Write amplificationNormal levels resume

Compaction Backlog

If auto-compaction was disabled for an extended period, there may be a significant backlog. Monitor disk space and I/O during catch-up.


bulk_load_with_compaction_control.sh
#!/bin/bash
KEYSPACE="my_keyspace"
TABLE="my_table"
DATA_PATH="/path/to/sstables"
echo "=== Bulk Load with Compaction Control ==="
# 1. Check current state
echo "1. Current compaction status:"
nodetool statusautocompaction $KEYSPACE $TABLE
# 2. Disable auto-compaction
echo "2. Disabling auto-compaction..."
nodetool disableautocompaction $KEYSPACE $TABLE
# 3. Verify disabled
echo "3. Verifying disabled:"
nodetool statusautocompaction $KEYSPACE $TABLE
# 4. Load data
echo "4. Loading data..."
sstableloader -d localhost $DATA_PATH
# 5. Re-enable auto-compaction
echo "5. Re-enabling auto-compaction..."
nodetool enableautocompaction $KEYSPACE $TABLE
# 6. Verify enabled
echo "6. Verifying enabled:"
nodetool statusautocompaction $KEYSPACE $TABLE
# 7. Check compaction activity
echo "7. Current compaction activity:"
nodetool compactionstats
echo "=== Complete ==="

Terminal window
# View active and pending compactions
nodetool compactionstats

Example output showing compaction resuming:

pending tasks: 15
- my_keyspace.my_table: 15
Active compaction remaining time : 0h00m45s
compaction type keyspace table completed total unit progress
Compaction my_keyspace my_table 524288000 1048576000 bytes 50.00%
Terminal window
# Watch compaction progress
watch -n 5 'nodetool compactionstats'
Terminal window
# Before re-enabling (many SSTables)
nodetool tablestats my_keyspace.my_table | grep "SSTable count"
# SSTable count: 47
# After compaction catches up (fewer SSTables)
nodetool tablestats my_keyspace.my_table | grep "SSTable count"
# SSTable count: 8

If compaction doesn't start after enabling:

Terminal window
# Verify status is enabled
nodetool statusautocompaction my_keyspace my_table
# Check for pending tasks
nodetool compactionstats
# If no pending tasks, may need to wait for strategy evaluation
# Or force compaction
nodetool compact my_keyspace my_table

If I/O is too high after enabling:

Terminal window
# Reduce compaction throughput temporarily
nodetool setcompactionthroughput 32
# Let backlog process gradually
watch nodetool compactionstats
# Restore normal throughput later
nodetool setcompactionthroughput 64

If disk space is critical:

Terminal window
# Check current usage
df -h /var/lib/cassandra
# May need to process compaction slowly
nodetool setcompactionthroughput 16
# Clear snapshots if needed
nodetool clearsnapshot --all

enable_autocompaction_cluster.sh
#!/bin/bash
KEYSPACE="my_keyspace"
TABLE="my_table"
# Get list of node IPs from local nodetool status
nodes=$(nodetool status | grep "^UN" | awk '{print $2}')
for node in $nodes; do
echo "Enabling auto-compaction on $node..."
ssh "$node" "nodetool enableautocompaction $KEYSPACE $TABLE"
done
echo "Verification:"
for node in $nodes; do
echo -n "$node: "
ssh "$node" "nodetool statusautocompaction $KEYSPACE $TABLE"
done

Auto-Compaction Guidelines

  1. Re-enable promptly - Don't leave auto-compaction disabled for extended periods
  2. Verify after enabling - Always check with statusautocompaction
  3. Monitor the backlog - Watch compactionstats for catch-up progress
  4. Control throughput - Adjust compaction throughput if I/O impact is too high
  5. Check disk space - Ensure sufficient space for compaction to proceed
  6. Document changes - Log when and why auto-compaction was disabled/enabled
  7. Apply consistently - Enable on all nodes if disabled cluster-wide

Long-term Disable Risks

Keeping auto-compaction disabled for extended periods causes:

  • SSTable proliferation (many small files)
  • Degraded read performance
  • Increased memory usage for bloom filters
  • Tombstone accumulation
  • Potential disk space issues

CommandRelationship
disableautocompactionDisable auto-compaction
statusautocompactionCheck auto-compaction status
compactForce manual compaction
compactionstatsView active compactions
setcompactionthroughputControl compaction rate
tablestatsView SSTable counts