# Cassandra Compaction

> Monitors and controls SSTable merging in Apache Cassandra: inspects compactionstats and history, triggers manual merges, stops runaway operations, and selects or tunes strategies (STCS, LCS, TWCS) for table behavior. Use when working with compaction status, manual compaction, strategy tuning, api or when the user mentions compaction status, manual compaction, strategy tuning, api.

- Skill: `opknock/cassandra-compaction` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/cassandra-compaction`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/cassandra-compaction/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/cassandra-compaction

---


Monitors and controls SSTable merging in Apache Cassandra: inspects compactionstats and history, triggers manual merges, stops runaway operations, and selects or tunes strategies (STCS, LCS, TWCS) for table behavior.

## Agentic Workflow: Read -> Reason -> Act (cassandra-compaction)

You are **Cassandra Compaction** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — api context for `cassandra-compaction`
- Domain: Monitors and controls SSTable merging in Apache Cassandra: inspects compactionstats and history, triggers manual merges, stops runaway operations, and selects or tunes strategies (STCS, LCS, TWCS) for
- **compaction-status**: Inspect compaction activity and history. — `nodetool compactionstats`
- **manual-compaction**: Trigger or stop compaction on tables. — `nodetool compact mykeyspace users`
- **strategy-tuning**: Set and tune compaction strategies. — `cqlsh -e "ALTER TABLE mykeyspace.users WITH compaction = {'class':'LeveledCompac`
- Check `knowledge` and `prerequisites: cqlsh, nodetool`

### 2. Reason — think for `cassandra-compaction`
- For `compaction-status`: Inspect compaction activity and history. — decide which checks to run
- For `manual-compaction`: Trigger or stop compaction on tables. — decide which checks to run
- For `strategy-tuning`: Set and tune compaction strategies. — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `cassandra-compaction` tools
- Tools: `Glob`, `Grep`, `Read`, `Nodetool`, `Cqlsh` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `cassandra-compaction:fae663f0`

# Cassandra Compaction

## What this skill does

Manages Cassandra compaction: monitoring activity with compactionstats, triggering manual compactions, stopping runaway compaction, and selecting/tuning strategies (STCS/LCS/TWCS).

## When to use

- Disk usage climbs due to many small SSTables
- Compaction is starving the cluster of I/O
- Choosing the right strategy for a table's workload

## Real commands

```bash
# Monitor
nodetool compactionstats
nodetool compactionhistory | tail -20

# Manual compaction
nodetool compact mykeyspace users

# Stop runaway compaction
nodetool stop compaction

# Flush memtables first if needed
nodetool flush mykeyspace users

# Set strategy via cqlsh
cqlsh -e "ALTER TABLE mykeyspace.users WITH compaction = {'class':'LeveledCompactionStrategy','sstable_size_in_mb':160}"

# Throttle
nodetool setcompactionthroughput 64
```

## Strategy guidance

- STCS: default; good for most workloads
- LCS: read-heavy, low-latency (better read amplification)
- TWCS: time-series with TTL data

## Testing

- Check compactionhistory for completed runs after manual compact
- Watch pending tasks in compactionstats

## Best practices

- Schedule major compactions in maintenance windows
- Throttle during peak traffic
- Use TWCS for time-series tables; never LCS+TWCS mix

## Capabilities

### compaction-status
Inspect compaction activity and history.

**Parameters:**
- `keyspace` (string): Keyspace name
- `table` (string): Table name

**Commands:**
- `nodetool compactionstats`
- `nodetool compactionhistory`
- `nodetool status`
- `nodetool cfstats mykeyspace`
- `nodetool tablestats mykeyspace.users`

**Examples:**
- nodetool compactionstats
- nodetool compactionhistory | tail -20
- nodetool tablestats mykeyspace.users | grep -E 'SSTable|pending'

### manual-compaction
Trigger or stop compaction on tables.

**Parameters:**
- `keyspace` (string): Keyspace to compact
- `table` (string): Table to compact

**Commands:**
- `nodetool compact mykeyspace users`
- `nodetool compact -- mykeyspace users`
- `nodetool stop compaction`
- `nodetool scrub mykeyspace users`
- `nodetool flush mykeyspace users`

**Examples:**
- nodetool compact mykeyspace users
- nodetool stop compaction
- nodetool flush mykeyspace users

### strategy-tuning
Set and tune compaction strategies.

**Parameters:**
- `strategy` (string): STCS, LCS, TWCS
- `throughput` (number): Compaction throughput MB/s

**Commands:**
- `cqlsh -e "ALTER TABLE mykeyspace.users WITH compaction = {'class':'LeveledCompactionStrategy','sstable_size_in_mb':160}"`
- `cqlsh -e "SELECT table_name, compaction FROM system_schema.tables WHERE keyspace_name='mykeyspace'"`
- `cqlsh -e "ALTER TABLE mykeyspace.users WITH compaction = {'class':'SizeTieredCompactionStrategy','min_threshold':4}"`
- `nodetool getcompactionthroughput`
- `nodetool setcompactionthroughput 64`

**Examples:**
- cqlsh -e "ALTER TABLE mykeyspace.users WITH compaction = {'class':'LeveledCompactionStrategy','sstable_size_in_mb':160}"
- cqlsh -e "SELECT table_name, compaction FROM system_schema.tables WHERE keyspace_name='mykeyspace'"
- nodetool setcompactionthroughput 64

## References
- [Cassandra Compaction](https://cassandra.apache.org/doc/latest/cassandra/operating/compaction/index.html)
- [nodetool Reference](https://cassandra.apache.org/doc/latest/cassandra/operating/nodetool/)

