This document describes various methods for CouchDB compaction.

Automatic Compaction

Since version 1.2 it's possible to automatically compact the database automatically.

Add these items to the /etc/couchdb/local.ini file.

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

Manual Compaction via Bash

#!/bin/bash
#
# Reset CouchDB to Default State
#

host="http://root:root@couch.domain.tld:5984/database"

# Compact Database
curl -H "Content-Type: application/json" -X POST "$host/_compact"
curl -X GET "$host"

# Compact a View
curl -H "Content-Type: application/json" -X POST "$host/_compact/view_name"
curl -H "Content-Type: application/json" -X POST "$host/_compact/customers"
curl -H "Content-Type: application/json" -X POST "$host/_compact/workorder"