Take the 2-minute tour ×

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?

share|improve this question

3 Answers 3

up vote 13 down vote accepted

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.


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.


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

share|improve this answer
Thanks for that little extra note. :) –  Octavian Damiean Jul 22 '12 at 8:32
It's too bad there's no API call for this. If you don't have full access to your CouchDB server then this solution is unavailable to you. It seems you would have to replicate and delete, which DOES indeed have the side effect of loosing revision and view index data. –  fet Nov 19 '12 at 18:45
The databases no longer are listed in Futon using this method, do you have any idea how this could be remedied? EDIT: ignore this, i had renamed them with a capital letter prefix, they must start lowercase. –  ATfPT Jan 30 at 12:05
Great observation though, thanks. –  smathy Feb 1 at 3:43

Assuming you don't want to corrupt your databases, rename the .couch files when CouchDB is not running.

share|improve this answer
Actually this isn't a problem, due to CouchDB's append-only design. You can rename and/or copy while CouchDB is running without corruption. (This assumes that your application can tolerate non-atomic writes, of course. But if it couldn't tolerate non-atomic writes, then you shouldn't be using CouchDB in the first place.) –  mehaase Aug 12 '13 at 20:24
Not safely, couchdb will have an open file descriptor to the file and be unaware of the rename. –  Robert Newson Oct 18 '13 at 17:34

If you have access to the database file itself, (located in /var/lib/couchdb depending on your installation) you can simply rename it.

To my knowledge, that will effectively "rename" the database. I would make sure the server is not running when you perform this operation, just in case.

share|improve this answer
Is this safe? I mean doesn't that have some side effects? –  Octavian Damiean Jul 21 '12 at 14:51
Honestly, I'm not entirely sure as I've never done this myself in production. But I do know for a fact that simply copying the database files is sufficient for a backup/restore, so a rename is probably safe too. –  Dominic Barnes Jul 21 '12 at 15:00
Makes sense, I'll try this out just to make sure. ;) –  Octavian Damiean Jul 21 '12 at 15:18

Your Answer


