Configure compaction

The compaction process merges keys, combines columns, evicts tombstones, consolidates SSTables, and creates a new index in the merged SSTable.

In the cassandra.yaml file, you can configure the following global compaction parameters:

DataStax Enterprise (DSE) supports the following compaction strategies:

  • LeveledCompactionStrategy (LCS): The leveled compaction strategy creates SSTables of a fixed, relatively small size (160 MB by default) that are grouped into levels. Within each level, SSTables are guaranteed to be non-overlapping. Each level (L0, L1, L2 and so on) is 10 times as large as the previous. Disk I/O is more uniform and predictable on higher than on lower levels as SSTables are continuously being compacted into progressively larger levels. At each level, row keys are merged into non-overlapping SSTables in the next level. This process can improve performance for reads, because the database can determine which SSTables in each level to check for the existence of row key data. This compaction strategy is modeled after Google’s LevelDB implementation. Also see LCS compaction subproperties.

  • SizeTieredCompactionStrategy (STCS) (default): This strategy triggers a minor compaction when there are a number of similar sized SSTables on disk as configured by the table subproperty min_threshold. A minor compaction doesn’t involve all the tables in a keyspace. For more information, see STCS compaction subproperties.

  • TimeWindowCompactionStrategy (TWCS): This strategy is an alternative for time series data. TWCS compacts SSTables using a series of time windows. During a time window, TWCS compacts all SSTables flushed from memory into larger SSTables using STCS. At the end of the time window, all of these SSTables are compacted into a single SSTable. Then, the next time window starts and the process repeats. The duration of the time window is the only required setting. For more information, see TWCS compaction subproperties and How is data maintained?.

  • DateTieredCompactionStrategy (DTCS) (deprecated).

DSE provides a start-up option to test compaction strategies without affecting your production workloads.

Use CREATE TABLE and ALTER TABLE to configure compaction

To configure the compaction strategy property and CQL compaction subproperties, such as the maximum number of SSTables to compact and minimum SSTable size, use CREATE TABLE or ALTER TABLE.

For example:

  • Change a table’s compaction strategy using ALTER TABLE:

    ALTER TABLE users
      WITH compaction =
      { 'class' : 'LeveledCompactionStrategy' }
  • Change the compaction strategy property to SizeTieredCompactionStrategy, and specify the minimum number of SSTables to trigger a compaction using the CQL min_threshold attribute:

    ALTER TABLE users
      WITH compaction =
      {'class' : 'SizeTieredCompactionStrategy', 'min_threshold' : 6 }

Compaction metrics

You can monitor the results of your configuration using compaction metrics.

The following attributes are exposed through CompactionManagerMBean:

Compaction metrics
Attribute Description

BytesCompacted

Total number of bytes compacted since server start or restart.

CompletedTasks

Number of completed compactions since server start or restart.

PendingTasks

Estimated number of compactions remaining to perform.

TotalCompactionsCompleted

Total number of compactions since server start or restart.

For more information, see Monitor DataStax Enterprise (DSE) clusters.

Extended logging

DSE supports extended logging for compaction. This utility must be configured as part of the table configuration. The extended compaction logs are stored in a separate file. For details, see Enabling extended compaction logging.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM