Auto-compaction Settings

Auto-compaction Settings

Auto-compaction settings trigger the compaction process. The process compacts databases and their respective view indexes when the following conditions are met. Full Administrators and Cluster Administrators can configure auto-compaction settings.

If you set the default auto-compaction settings for Couchbase Server, auto-compaction is automatically enabled for all Couchbase buckets. You can override all the auto-compaction settings except index fragmentation settings using per-bucket settings that are available when creating or editing data buckets.

You can provide a purge interval to remove the key and metadata for items that have been deleted or are expired, which is known as Tombstone purging.

The auto-compaction settings can also be modified using the REST API.

From the Couchbase Web Console > Settings > Auto-Compaction tab, you can set the following auto-compaction parameters:
Database Fragmentation
Sets the database fragmentation level that determines the point when compaction is triggered. You must specify either one or both parameters:
  • Percentage of fragmentation
  • Database size (in MB)
View Fragmentation
Sets the view fragmentation level that determines the point when compaction is triggered. You must specify either one or both parameters:
  • Percentage of fragmentation
  • View size (in MB)
Time Interval
Set the time interval when compaction is allowed to run

If selected, you must specify the start time (hh:mm), and end time (hh:mm) of the time period when compaction is allowed to run.

Abort compaction if run time exceeds the set time interval

When selected, if database compaction is running when the configured time period ends, the compaction process is terminated.

Compact Bucket and Views Index in parallel

When selected, database and view compaction is executed simultaneously, implying a heavier processing and disk I/O load during the compaction process.

Index Fragmentation
Sets the write strategy and trigger point when compaction is triggered. This option only applies when "Standard Global Secondary Index" storage option is selected for indexes. Write mode and compaction strategy does not apply to memory-optimized global secondary indexes. You can select one of the following options:
  • Append-only writes with index fragmentation level to trigger compaction

    When you upgrade a cluster (with the indexing service enabled) from version 4.0 or 4.1, this option is selected by default. The option turns on append only writes for index storage and triggers the compaction job based on the fragmentation level of each index file.

  • Use writes with circular reuse with time interval to trigger compaction

    For new clusters created with version 4.5, this option is selected by default.

    The option turns on writes with circular reuse for index storage and triggers compaction job based on time interval. You must specify the days of the week and the start time (hh:mm) when compaction is allowed to run and optionally set an end time (hh:mm) of the time period when compaction is aborted.

    Abort compaction if run time exceeds the set time interval

    When selected, if database compaction is running when the configured time period ends, the compaction process is terminated.

Whenever you change the compaction settings for the index, the system starts the global secondary index process on all the nodes.

When you switch from append-only writes with percent-fragmentation based trigger to circular reuse with time-based trigger, the setting may not take effect immediately after upgrading from 4.1 or 4.0 to version 4.5. To see when the circular reuse option takes effect, ensure that compaction has completed on all the indexes on all nodes with global indexes.

Note: Index compaction settings cannot be overridden at the bucket level.
Metadata Purge Interval
Sets the frequency of metadata purge interval. The default value is three days.

Tombstones are records of expired or deleted items, and they include the key and metadata. Tombstones are used in Couchbase Server to provide eventual consistency of data between clusters. The auto-compaction process waits for the specified number of days before permanently deleting tombstones for expired or deleted items.

If you set this value too low, you may see more inconsistent results in views queries, such as deleted items in a result set. You may also see inconsistent items in clusters with XDCR set up between the clusters. If you set this value too high, it will delay the server from reclaiming disk space.