4.7. Compaction Configuration

4.7.1. Database Compaction Options

[database_compaction]
doc_buffer_size

Specifies the copy buffer’s maximum size in bytes:




  1. [database_compaction]
    doc_buffer_size = 524288



checkpoint_after

Triggers a checkpoint after the specified amount of bytes weresuccessfully copied to the compacted database:




  1. [database_compaction]
    checkpoint_after = 5242880



4.7.2. Compaction Daemon Rules

[compactions]

A list of rules to determine when to run automatic compaction. Thedaemons/compaction_daemon compacts databases and their respectiveview groups when all the condition parameters are satisfied. Configurationcan be per-database or global, and it has the following format:




  1. [compactions]
    databasename = [ {ParamName, ParamValue}, {ParamName, ParamValue}, ]
    _default = [ {ParamName, ParamValue}, {ParamName, ParamValue}, ]




For example:




  1. [compactions]
    _default = [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "23:00"}, {to, "04:00"}]




-
db_fragmentation: If the ratio of legacy data, including metadata, tocurrent data in the database file size is equal to or greater than thisvalue, this condition is satisfied. The percentage is expressed as aninteger percentage. This value is computed as:




  1. (file_size - data_size) / file_size 100




The data_size and file_size values can be obtained whenquerying GET /{db}.

-
view_fragmentation: If the ratio of legacy data, including metadata,to current data in a view index file size is equal to or greater thenthis value, this database compaction condition is satisfied. Thepercentage is expressed as an integer percentage. This value is computedas:




  1. (file_size - data_size) / file_size 100




The data_size and file_size values can be obtained when querying aview group’s information URI.

-
from and to: The period for which a database (and its view group)compaction is allowed. The value for these parameters must obey theformat:




  1. HH:MM - HH:MM (HH in [0..23], MM in [0..59])




-
strict_window: If a compaction is still running after the end of theallowed period, it will be canceled if this parameter is set to _true
.It defaults to false and is meaningful only if the period parameteris also specified.

-
parallelview_compaction: If set to _true, the database and itsviews are compacted in parallel. This is only useful on certain setups,like for example when the database and view index directories point todifferent disks. It defaults to false.

Before a compaction is triggered, an estimation of how much free disk spaceis needed is computed. This estimation corresponds to two times the datasize of the database or view index. When there’s not enough free disk spaceto compact a particular database or view index, a warning message islogged.

Examples:

-






  1. [{dbfragmentation, "70%"}, {view_fragmentation, "60%"}]








The _foo
database is compacted if its fragmentation is 70% or more. Anyview index of this database is compacted only if its fragmentation is60% or more.

-






  1. [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}]








Similar to the preceding example but a compaction (database or viewindex) is only triggered if the current time is between midnight and 4AM.

-






  1. [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}, {strict_window, true}]








Similar to the preceding example - a compaction (database or view index)is only triggered if the current time is between midnight and 4 AM. Ifat 4 AM the database or one of its views is still compacting, thecompaction process will be canceled.

-






  1. [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}, {strict_window, true}, {parallel_view_compaction, true}]








Similar to the preceding example, but a database and its views can becompacted in parallel.

4.7.3. Configuration of Compaction Daemon

[compaction_daemon]
check_interval

The delay, in seconds, between each check for which database and viewindexes need to be compacted:




  1. [compaction_daemon]
    check_interval = 300



min_file_size

If a database or view index file is smaller than this value (in bytes),compaction will not happen. Very small files always have highfragmentation, so compacting them is inefficient.




  1. [compaction_daemon]
    min_file_size = 131072



4.7.4. Views Compaction Options

[view_compaction]
keyvalue_buffer_size

Specifies maximum copy buffer size in bytes used during compaction:




  1. [view_compaction]
    keyvalue_buffer_size = 2097152



原文: http://docs.couchdb.org/en/stable/config/compaction.html