CockroachDB is an open-source, distributed SQL database developed by former Google engineers at Cockroach Labs. Designed to run in the cloud, and is known for this resilience and scalability.
The CockroachDB can run in a single machine or can be scaled to hundreds and thousands of servers. Because of this, CockroachDB is the best option for the cloud. It grows as the organizations need to succeed.
Some aspects of CockroachDB were inspired by Spanner – Google’s globally-distributed database offering.
Access CockroachDB for more informations!
Designed to be highly compatible with PostgreSQL, this is an important point and nos just because it means that the users do not have to learn as many new things only to work with CockroachDB.
Note, this means many apps that were designed to work with PostgreSQL can be migrated to work with CockroachDB with no changes necessary. It also means that you can use a wide variety of existing PostgreSQL client drivers to talk to CockroachDB. It’s been tested from diverse languages, including:
- Python
- Ruby
- Java
- Go
- PHP
- Node.js
- C and C++
- Rust
- Clojure
While there’s no doubt that CockroachDB is a smart choice for a wide variety of applications, there are certain use cases that the product is especially well-suited for, such as:
- Multi-datacenter deployments
- Cloud migrations
- Replicated or distributed online transaction processing
When you need response times in the milliseconds regardless of scale, combined with available, reliable data, CockroachDB is a viable solution. However, the product isn’t the best choice for heavy analytics.
Now we runs the CockroachDB with Docker Compose in your local machine, you can clone the git url below.
$ git clone https://github.com/lhsribas/cockroachdb-docker-compose.git
The command docker network create creates a specific network to run the CockroachDB.
$ docker network create -d bridge network_cockroachdb
The command bellow start the cluster with two nodes, and the flag --build Build images before starting containers.
$ docker-compose up --build
Since the containers are running in the foreground, you’ll need to open another tab or terminal window and use the following command to list the nodes’ containers:
$ docker ps
If you encounter a port conflict, you can try to stop and remove the containers for the nodes using docker stop and docker rm. You can also use lsof to look for the processes using the 26257 Cockroach port as seen below:
$ lsof -i -sTCP:LISTEN | grep 26257
You can use the following command to initialize your cluster if needed:
$ docker exec -it node_1 ./cockroach init --insecure
We’ll use the docker exec command to connect and interact with the node_1 container by taking advantage of the -it interactive options:
$ docker exec -it node_1 /bin/bash
Once you’re inside the container, use the ./cockroach sql command to enter the SQL interactive shell for the CockroachDB node:
$ ./cockroach sql --insecure
$ CREATE DATABASE some_db;