12.3. Database Management
12.3.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 willfind all the parts.
If you do not specify n
and q
the default will be used. The default is3
replicas and 8
shards.
12.3.2. Deleting a database
- curl -X DELETE "http://xxx.xxx.xxx.xxx:5984/database-name --user admin-user
12.3.3. Placing a database on specific nodes
In BigCouch, the predecessor to CouchDB 2.0’s clustering functionality, therewas the concept of zones. CouchDB 2.0 carries this forward with clusterplacement rules.
First, each node must be labeled with a zone attribute. This defines whichzone 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 aconsistent cluster-wide setting like:
- [cluster]
- placement = metro-dc-a:2,metro-dc-b:1
In this example, it will ensure that two replicas for a shard will be hostedon nodes with the zone attribute set to metro-dc-a
and one replica willbe hosted on a new with the zone attribute set to metro-dc-b
.
Note that you can also use this system to ensure certain nodes in the clusterdo not host any replicas for newly created databases, by giving them a zoneattribute that does not appear in the [cluster]
placement string.
原文: http://docs.couchdb.org/en/stable/cluster/databases.html