Couchbase Server incorporates an automated compaction mechanism that can compact both data files and the view index files, based on triggers that measure the current fragmentation level within the database and view index data files.
Spatial indexes are not automatically compacted. Spatial indexes must be compacted manually. For more information, see Section 8.6.10, “Compacting Bucket Data and Indexes”.
Auto-compaction can be configured in two ways:
Default Auto-Compaction affects all the Couchbase Buckets within your Couchbase Server. If you set the default Auto-Compaction settings for your Couchbase server then auto-compaction is enabled for all Couchbase Buckets automatically. For more information, see Section 6.8, “Settings”.
Bucket Auto-Compaction can be set on individual Couchbase Buckets. The bucket-level compaction always overrides any default auto-compaction settings, including if you have not configured any default auto-compaction settings. You can choose to explicitly override the Couchbase Bucket specific settings when editing or creating a new Couchbase Bucket. See Section 6.3.1, “Creating and Editing Data Buckets”.
The available settings for both default Auto-Compaction and Couchbase Bucket specific settings are identical:
The primary setting is the percentage level within the database at which compaction occurs. The figure is expressed as a percentage of fragmentation for each item, and you can set the fragmentation level at which the compaction process will be triggered.
For example, if you set the fragmentation percentage at 10%, the moment the fragmentation level has been identified, the compaction process will be started, unless you have time limited auto-compaction. See Time Period.
The View Fragmentation specifies the percentage of fragmentation within all the view index files at which compaction will be triggered, expressed as a percentage.
To prevent auto compaction taking place when your database is in heavy use, you can configure a time during which compaction is allowed. This is expressed as the hour and minute combination between which compaction occurs. For example, you could configure compaction to take place between 01:00 and 06:00.
If compaction is identified as required outside of these hours, compaction will be delayed until the specified time period is reached.
The time period is applied every day while the Couchbase Server is active. The time period cannot be configured on a day-by-day basis.
The compaction process can be configured so that if the time period during which compaction is allowed ends while the compaction process is still completing, the entire compaction process will be terminated. This option affects the compaction process:
If this option is enabled, and compaction is running, the process will be stopped. The files generated during the compaction process will be kept, and compaction will be restarted when the next time period is reached.
This can be a useful setting if want to ensure the performance of your Couchbase Server during a specified time period, as this will ensure that compaction is never running outside of the specified time period.
If compaction is running when the time period ends, compaction will continue until the process has been completed.
Using this option can be useful if you want to ensure that the compaction process completes.
By default, compaction operates sequentially, executing first on the database and then the Views if both are configured for auto-compaction.
By enabling parallel compaction, both the databases and the views can be compacted at the same time. This requires more CPU and database activity for both to be processed simultaneously, but if you have CPU cores and disk I/O (for example, if the database and view index information is stored on different physical disk devices), the two can complete in a shorter time.
Configuration of auto-compaction is performed through the Couchbase Server Web Admin Console. For more information on the default settings, see Section 6.8, “Settings”. Information on per-bucket settings is through the Couchbase Bucket create/edit screen. See Section 6.3.1, “Creating and Editing Data Buckets”.