How to rename a CouchDB database?

tephyr picture tephyr · Jul 21, 2012 · Viewed 8.4k times · Source

I don't see an API for renaming a CouchDB database, or an option in Futon to do the same.

Short of replicating to another database and then deleting the original, is there a one-step way to rename a database?

Answer

smathy picture smathy · Jul 22, 2012

Adding to what Dominic and PPPaul said...

Renaming the file is absolutely the way to go (make sure you rename it as the same user, not accidentally change the ownership to root or something).

This is perfectly safe to do in a full running production environment, yes. One of the many advantages of an HTTP/REST API is that there are no adapters with stateful connections to the DB. Each request is a new request. So basically the first request to CouchDB after the rename is complete will be able to use the new name.

But wait, there's more!

One really cool thing is that even after the rename, the CouchDB server still has an open file-handle to the file itself (which isn't affected by renaming the inode), so until the CouchDB server is actually restarted you'll still be able to access the DB using the old name too.

Update

Great observation by ATfPT in the comments, apparently the DB name needs to start with a lower case letter, otherwise it doesn't show up in Futon.

Update

Another thing I remembered: to find out where the DB files are, run this: couch-config --db-dir