Install CockroachDB on Debian 11

This article is going to take you through how to install CockroachDB on Debian 11. CockroachDB is a cloud-based serverless distributed SQL database for developing, scaling, and maintaining modern, data-intensive applications. It’s built on a transactional and highly consistent key-value store. It scales horizontally, survives disk, machine, rack, and even data center failures with minimal latency and no user intervention, supports strongly-consistent ACID transactions, and provides a familiar SQL API for data organization, manipulation, and querying.

How to Install CockroachDB on Debian 11

  • To obtain the most recent download link, navigate to the CockroachDB website. Then use the example command below to download and extract it.
curl https://binaries.cockroachdb.com/cockroach-v22.1.0.linux-amd64.tgz | tar -xz && sudo cp -i cockroach-v22.1.0.linux-amd64/cockroach /usr/local/bin/
  • After that, copy the CockroachDB executable file to /usr/local/lib/cockroach. First, create the directory with the command below.
sudo mkdir -p /usr/local/lib/cockroach
  • Next, copy the library files to the directory created.
sudo cp -i cockroach-v22.1.0.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/

sudo cp -i cockroach-v22.1.0.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/
  • Use the command below to verify that the copied binary is working.
which cockroach

Sample output

/usr/local/bin/cockroach
  • Check CockroachDB version installed.
cockroach version

Sample output

Build Tag:        v22.1.0
Build Time:       2022/05/23 16:27:47
Distribution:     CCL
Platform:         linux amd64 (x86_64-pc-linux-gnu)
Go Version:       go1.17.6
C Compiler:       gcc 6.5.0
Build Commit ID:  5b78463ed2e7106a8477b63fa837564ad02bb510
Build Type:       release

Start single node CockroachDB cluster on Debian 11

  • Create a single node cluster demo using the following commands.
cockroach start-single-node \
    --insecure \
    --store=commerce_database \
    --listen-addr=localhost:26257 \
    --http-addr=localhost:8080 \
    --background
  • Then start CockroachDB shell.
cockroach sql --insecure --host=localhost:26257
  • Next, let us create a demo user using the query below.
CREATE USER itnixpro;
  • Create a demo database using the following query.
CREATE DATABASE demo_db;
  • Set demo_db as the default database.
SET DATABASE = demo_db;
  • Grant all privileges to itnixpro user using the following query.
GRANT ALL ON DATABASE demo_db TO itnixpro;
  • Run the following command to list created database.
SHOW database;
  • Use the command below to exit the shell.
\q

Sample output

#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v22.1.0 (x86_64-pc-linux-gnu, built 2022/05/23 16:27:47, go1.17.6) (same version as client)
# Cluster ID: 44fe25a1-3fe9-4dce-a406-07179eaba4d1
No entry for terminal type "xterm-256color";
using dumb terminal settings.
#
# Enter \? for a brief introduction.
#
root@localhost:26257/defaultdb> CREATE USER itnixpro;
CREATE ROLE


Time: 95ms total (execution 94ms / network 0ms)

root@localhost:26257/defaultdb> CREATE DATABASE demo_db;
CREATE DATABASE


Time: 19ms total (execution 19ms / network 1ms)

root@localhost:26257/defaultdb> SET DATABASE = demo_db;
SET


Time: 5ms total (execution 5ms / network 0ms)

root@localhost:26257/demo_db> GRANT ALL ON DATABASE demo_db TO itnixpro;
NOTICE: grant options were automatically applied but this behavior is deprecated
HINT: please use WITH GRANT OPTION
GRANT


Time: 72ms total (execution 72ms / network 0ms)

root@localhost:26257/demo_db> SHOW database;
  database
------------
  demo_db
(1 row)


Time: 2ms total (execution 1ms / network 0ms)

root@localhost:26257/demo_db> \q

Access CockroachDB Web Interface

  • Open your favorite web browser and enter your server/domain name followed by port 8080 e.g. server-IP:8080 or localhost:8080 as shown below.

The web interface can now be used to monitor your database. Note that the web interface cannot be used to create databases.

  • To monitor the metrics, go to metrics and choose a certain module and time.
  • Check your SQL activity by clicking on the SQL Activity option.
  • Click on Jobs to see running jobs.
  • It’s a warp! You have made it to the end of our article, Cheers! You have gone through how to install CockroachDB on Debian 11.

Read more on CockroachDB Documentation

Other Tutorials

Install MariaDB 10.7 on CentOS 7

Install MongoDB compass GUI on Ubuntu 22.04

Install DBeaver on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment