Introducing crdbt

October 26, 2022 - Reading time: 5 minutes

It is no secret that I am both a fan and user of Cockroach DB. At Intergreatme we have it deployed as a clustered database for our main technology stack, but I have also made use of it as a standalone database on some of the smaller servers that I work with (predominately interfacing with PHP.)

That's one of the things I love about Cockroach DB: download an executable, and you're basically ready to go! It doesn't rely on a bunch of hidden files and configuration settings to operate, which simplifies the whole deployment model. Want it to run as a standalone instance? Sure, provide some basic configurations and you're ready to work. You can even deploy it in an insecure mode to make it even easier to get started.

But once Cockroach is running in production, it becomes a bit of a task to update it.

My current process is:

Download the latest version of Cockroach DB

curl | tar -xz

Stop Cockroach DB (assuming you are using systemd as described in Setting up Cockroach DB)

sudo systemctl stop cockroach

Replace the binary

sudo cp -i cockroach-v22.1.9.linux-amd64/cockroach /usr/local/bin/

If you are using the custom GEOS libraries, move them now:

sudo cp -i cockroach-v22.1.9.linux-amd64/lib/ /usr/local/lib/cockroach/
sudo cp -i cockroach-v22.1.9.linux-amd64/lib/ /usr/local/lib/cockroach/

Start Cockroach DB

sudo systemctl start cockroach

Check that everything is still works

sudo systemctl status cockroach

If you are working in a clustered environment, move to the next instance of Cockroach DB and repeat the process above... Or roll back by replacing the installed version with the previous version.

I have only had one instance that refused to upgrade before, and I had to use the awkward backup and restore methods to destroy the previous version of the database and recreate it in a new version.

Making thing easier for myself

As you can imagine, having to search for the resources to remind myself of the commands I need to enter becomes a bit tedious at times, not to mention the problems that can arise if you are working across different terminals and paste in the wrong command in the wrong sequence or order!

To solve for this, I wrote a simple bash script that effectively emulates the process above. I called it and it accepts the version as a command line argument to the version of Cockroach DB you want to use. Because of the simple deployment process, and that certain versions of Cockroach DB are by default backwards compatible, the script allows me to easily upgrade/roll back versions of Cockroach DB with nothing more than a simple command by specifying the particular version I want installed.

I then wrote a few other scripts to handle other use cases that I have with Cockroach DB: like easily accessing the SQL command line interface shell, or viewing the systemd status.

What is crdbt all about then?

I wanted something a bit more flexible than having a series of shell scripts to make interfacing with Cockroach DB a bit more elegant. So, I decided on creating crdbt (Cockroach DB Tools): a Go application that combines all the scripts I make use of in to a single application that is easy to deploy, and acts as a more powerful utility.

While the first version of this utility might seem pretty unordinary, I created crdbt around my existing use cases at Intergreatme, and hope that it provides other users of Cockroach DB a useful tool to help manage their database.

The source is located here, and you're able to download a precompiled binary for Linux here.