Last Updated: February 25, 2016
· vjt

Compact your CouchDB databases and views

CouchDB will keep updated and deleted documents in old revisions. On heavily-written databases this will cause their size to grow up with time.

You can use this script using cron to periodically compact your databases:

Assuming you saved it in /usr/local/sbin and chmod 755 it, you can cron it like this:

@weekly /usr/local/sbin/couchdb-compact.rb >> /var/log/couchdb/compaction.log

to also keep an activity log of the process.

Please keep in mind that you should attempt compaction of heavily-written databases during off-peak hours, or the compaction won't be able to catch-up with the writes. More information here: