nodetool forcecompact
Cassandra 5.0+
This command is available in Cassandra 5.0 and later.
Forces compaction of SSTables containing specified partition keys, ignoring gc_grace_seconds.
Synopsis
Section titled “Synopsis”nodetool [connection_options] forcecompact <keyspace> <table> <keys>...See connection options for connection options.
Description
Section titled “Description”nodetool forcecompact forces compaction of SSTables containing the specified partition keys. Unlike regular compaction, this command ignores gc_grace_seconds when purging tombstones, allowing immediate removal of deleted data for specific partitions.
Use With Caution
This command ignores gc_grace_seconds, which means tombstones may be removed before they have propagated to all replicas. Use only when you are certain all replicas have seen the deletions, or after running repair.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Target keyspace |
table | Target table |
keys | Partition keys to force compact |
Examples
Section titled “Examples”Force Compact Specific Partition Keys
Section titled “Force Compact Specific Partition Keys”nodetool forcecompact my_keyspace my_table user123 user456When to Use
Section titled “When to Use”Remove Tombstones Immediately
Section titled “Remove Tombstones Immediately”# After ensuring all replicas have seen deletionsnodetool repair my_keyspace my_table
# Force compact specific partitions to remove tombstonesnodetool forcecompact my_keyspace my_table partition_key_valueRelated Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| compact | General compaction |
| compactionstats | View compaction status |
| getsstables | List SSTables for key |