11.4. Database Management

11.4.1. Creating a database

This will create a database with 3 replicas and 8 shards.

curl -X PUT "http://xxx.xxx.xxx.xxx:5984/database-name?n=3&q=8" --user admin-user

The database is in data/shards. Look around on all the nodes and you will find all the parts.

If you do not specify n and q the default will be used. The default is 3 replicas and 8 shards.

11.4.2. Deleteing a database

curl -X DELETE "http://xxx.xxx.xxx.xxx:5984/database-name --user admin-user

11.4.3. Placing a database on specific nodes

In BigCouch, the predecessor to CouchDB 2.0’s clustering functionality, there was the concept of zones. CouchDB 2.0 carries this forward with cluster placement rules.

First, each node must be labelled with a zone attribute. This defines which zone each node is in. You do this by editing the node’s document in the /nodes database, which is accessed through the “back-door” (5986) port. Add a key value pair of the form:

"zone": "metro-dc-a"

Do this for all of the nodes in your cluster.

In your config file (local.ini or default.ini) on each node, define a consistent cluster-wide setting like:

placement = metro-dc-a:2,metro-dc-b:1

In this example, it will ensure that two replicas for a shard will be hosted on nodes with the zone attribute set to metro-dc-a and one replica will be hosted on a new wiht the zone attribute set to metro-dc-b.

Note that you can also use this system to ensure certain nodes in the cluster do not host any replicas for newly created databases, by giving them a zone attribute that does not appear in the [cluster] placement string.