Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a CouchDB database?

Tags:

couchdb

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?

like image 685
tephyr Avatar asked Jul 21 '12 03:07

tephyr


2 Answers

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

like image 194
smathy Avatar answered Oct 14 '22 07:10

smathy


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.

like image 30
Dominic Barnes Avatar answered Oct 14 '22 08:10

Dominic Barnes