Skip to Content

Automatically compact CouchDB databases in version 0.11.x

CouchDB databases on version 0.11.x swell very fast. They should be compacted daily for best performance and space usage. Here is my script that could be run in cron and will compact all databases:

#!/bin/bash
IP="10.0.0.121"
DBS=`curl -sS -X GET http://$IP:5984/_all_dbs | sed -r "s/([,\"[])|(\])+/ /g"`

for d in $DBS;
do
    curl -H "Content-Type: application/json" -X POST http://$IP:5984/$d/_compact
done

More informations about compacting could be found here (also for version 1.2.x).