Couchbase is an open source, NoSQL distributed database where the data in JSON format is stored in documents. Unlike RDBMS there is buckets instead of tables. In buckets data is stored in key-value format.
Visit the following link to install couchbase on your machine
Here, I am going to give you a high level overview of Couchbase.
There are some fundamental services which must be running to get the Couchbase working.
1. Query – It is required to get the query executed. If this service is not working on
2. Index – It helps in creating index on keys to reduce the query execution time
3. Data – We use to store data.
Also there are some extra services in Couchbase –
These three fundamental services can be run on either one server and can be run on multiple servers.
We can create a couchbase cluster with more than one connected servers.
If more than one service are running on a single server then we call it single dimensional Couchbase server.
If on one server only one service is running then we call it multi dimensional Couchbase server(MDS).
Server option will give you a brief summary of your servers in the cluster. It gives you an overview of CPU utilisation, Ram usage, disk usage, number of items and replicas for each server. It also tells which service is running on a particular server.
To create Bucket simply click on ADD Bucket option.
Give bucket name and memory(Ram).
Select which type of bucket(Couchbase, Memcached or Ephemeral) you want.
Check on Replica Enable and enter number of copies of data you want.
Enable flush whenever you want to flush bucket.
In Security option you can create user with appropriate role to allow persons access your database.
Create User and Give Role
We use XDCR (Cross Replication Data Center) to replicate data from this cluster to another cluster (another data center) which might be working on different geographical region. XDCR is useful in disaster recovery.
We create Index to execute query in less time. Index in couchbase is same as index in books. Here indexes maintains, creates and stored a record of keys in advance. Query execution uses the indexes as hint and makes easy to find keys.
There are two types of indexes available:
Standard global secondary index
Memory-optimized global secondary index
The standard global secondary index stores uses the ForestDB storage engine to store the B-Tree index and keeps the optimal working set of data in the buffer. This means, the total size of the index can be much bigger than the amount of memory available in each index node.
A memory-optimised index uses a lock-free skip list to maintain the index and keeps all the index data in memory. A memory-optimised index has better latency for index scans and processes the mutations of the data much faster.
We can create index in two ways-
1. Primary index – If no specific index is covering your query then there must be a primary index which cover entire bucket documents. Whenever we execute a query and there is no secondary index for the query then primary index will help in query execution.
TO create a primary index(say indexName) on a bucket(say bucketName) you need to type following query on query execution field.
Create primary index indexName on bucketName
2. Secondary index – If your query is working on some specific keys then we can do indexing on those particular keys. So now instead of scanning entire keys on all documents, It will only scan those particular keys.
TO create a secondary index(say indexName) on a bucket(say bucketName) with key1 and key2 you need to type following query on query execution field.
Create index indexName on bucketName(key1, key2)
Create index indexName on bucketName(key1, key2) where key1=”someValue”
To read more about couchbase index visit – https://docs.couchbase.com/server/5.5/performance/indexing-and-query-perf.html
How Couchbase Works –
Whenever user executes a query, this query is sent to query node. During query execution, depending on the query, using applicable indexes, the Query node works with the Index and Data nodes to retrieve and perform the planned operations.
Applications and their drivers submit the N1QL query to one of the available query nodes. The Query node analyzes the query, uses meta data on underlying objects to figure out the optimal execution plan, which it then executes. During execution, depending on the query, using applicable indices, query node works with index and data nodes to retrieve and perform the select-join-project operations. Since, Couchbase is a clustered database, you scale out data, index and query nodes to fit your performance and availability goals.
N1QL analyzes the query and available access path options for each keyspace (table or bucket) in the query to create a query plan and execution infrastructure. The planner needs to first select the access path for each bucket, determine the join order and then determine the type of the join. Once the big decisions are made, planner then creates the infrastructure needed to execute the plan. Some operations like query parsing and planning is done serially, while other operations like fetch, join, sort are done in parallel.
Read more about how couchbase works –
There are multiple tools you can use to take backup and restore data.
There is also a utility cbbackupmgr which you can use to take backup and restore as well.