As you probably know CouchDB will not automatically reclaim unused space, nor compact or clean up its views during normal operation. Instead these processes are meant to be run at optimal times (ie; off peak hours) so they do not affect user performance during critical periods.
Over time this obviously means that any CouchDB can grow to be huge unless it is tended to.
This script is designed to be run from a scheduler (like cron) and target a CouchDB instance/URL. It first fetches all the DBs inside it (except the special _underscore ones) and then trigger a DB compaction. For each DB all the views inside are given the cleanup (for old versions of views) and a compaction commands as well. To my knowledge this is all of the compaction/cleanup processes CouchDB does.
Note: The script will exit fairly quickly because CouchDB will simply acknowledge the commands and then go off and process the requests (which can take some time). Just because the script finished does not indicate that the compaction has completed.
Feel free to post questions or report problems in the comments!
We’ve created a Github project for this: ateamsystems/ateam_couchdb_compact
Grab it via GitHub:
git clone https://github.com/ateamsystems/ateam_couchdb_compact.git
Excellent script, thanks for sharing!
This is a great script. What License are your releasing this under?
Hey Mark, good question! BSD license, I’ve moved this into our Github space as well and made that clear.
Thanks, I’m going to use this on our Couch server!