Every time I read an article about "10 Reasons You Should Start a Blog", there is always something about "learning new skills", and it sounds obvious but it's true. Lately, I'm always thinking about things to write about which makes me search more ... until I find something that gets my attention.

One of the things I discovered while searching for new articles for DBplatz is CockroachDB. (After all ... this is a database related blog).

White robot human features
Photo by Alex Knight / Unsplash

And after reading some articles I joined a webinar called "Deploy a Cloud-Native Database on Kubernetes With CockroachDB", which I actually enjoyed, and thought, well let's give it a try.

So I read the documentation and actually you can actually follow these steps on their website but this is one page - one node basic guide.

wget -qO- https://binaries.cockroachdb.com/cockroach-v19.2.5.linux-amd64.tgz | tar  xvz
cockroach-v19.2.5.linux-amd64/cockroach
Download and extract the binary
dbplatz@ubusrvroach:~
$ sudo cp -i cockroach-v19.2.5.linux-amd64/cockroach /usr/local/bin/
[sudo] password for dbplatz:
Copy the binary into PATH
dbplatz@ubusrvroach:/usr/local/bin
$ sudo cockroach start \
> --insecure \
> --store=node1 \
> --listen-addr=localhost:26257 \
> --http-addr=localhost:8080 \
> --join=localhost:26257,localhost:26258,localhost:26259 \
> --background
Start the cluster (insecure).
*
* WARNING: RUNNING IN INSECURE MODE!
*
* - Your cluster is open for any client that can access localhost.
* - Any user, even root, can log in without providing a password.
* - Any user, connecting as root, can read or write any data in your cluster.
* - There is no network encryption nor authentication, and thus no confidentiality.
*
* Check out how to secure your cluster: https://www.cockroachlabs.com/docs/v19.2/secure-a-cluster.html
*
*
* INFO: initial startup completed.
* Node will now attempt to join a running cluster, or wait for `cockroach init`.
* Client connections will be accepted after this completes successfully.
* Check the log file(s) for progress.
*
You will see this output
dbplatz@ubusrvroach:/usr/local/bin
$ cockroach init --insecure --host=localhost:26257

Cluster successfully initialized
Initialization of CockroachDB
dbplatz@ubusrvroach:/usr/local/bin$ cockroach sql --insecure --host=localhost:26257
 
So now we can connect to it
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v19.2.5 (x86_64-unknown-linux-gnu, built 2020/03/16 18:27:12, go1.12.12) (same version as client)
# Cluster ID: 49504dc9-1fea-4728-85e5-7825b24d657c
#
# Enter \? for a brief introduction.
#
root@localhost:26257/defaultdb> CREATE DATABASE bank;
CREATE DATABASE

Time: 17.402244ms

root@localhost:26257/defaultdb> CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
CREATE TABLE

Time: 64.715061ms

root@localhost:26257/defaultdb> INSERT INTO bank.accounts VALUES (1, 1000.50);
INSERT 1

Time: 18.856247ms

root@localhost:26257/defaultdb> SELECT * FROM bank.accounts;
  id | balance
+----+---------+
   1 | 1000.50
(1 row)

Time: 934.002┬Ás

root@localhost:26257/defaultdb> \q
and execute some basics commands.

According to the webinar it is really easy to add new nodes to the cluster so in the next post we will try that and more.