Installing TimescaleDB PostgreSQL Extension On Apple Silicon

ยท

4 min read

Timescale DB is a PostgreSQL extension that suitable for the time-series, event storing and data-aggregation workloads. This enable the PostgresSQL weaknesses on heavy query data read like an aggregation such as sum, avg, min, and max. Time-series database should be able to store all of the information with a frequent data updates. As an example, storing the sensor data for a certain time range. The frequency can be every minute, every hour, every day, every week, etc. In this article we will cover the TimescaleDB extension installation to the PostgreSQL.

Keep in mind that the official guides that can be accessed here. In a Mac with an Apple Silicon CPU, it is not work as intended from the official guide and the article will show the workaround of TimescaleDB extension installation.

Installing Homebrew

If you have installed the homebrew app, then you can skip this step. To install the latest homebrew, we can run the existing script that exist in their homepage.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After installing homebrew, you can go through the installation of the Timescale DB directly.

Installing TimescaleDB

Installing TimescaleDB need to use the custom third party repositories. To add the TimecaleDB custom third party repository (Tap) to the homebrew, we can use the command below.

brew tap timescale/tap

After adding the repository, we can continue to install the TimescaleDB directly using the brew install command.

brew install timescaledb

Installing TimescaleDB will takes some time, since it will two pakages that consists of PostgreSQL and TimescaleDB.

Setting Up TimescaleDB

By default, TimescaleDB will ship its binaries that can be used to configure the PostgreSQL extension installation. This is when the issue happened in the configuration stage. To configure a TimescaleDB extensions to a PostgreSQL app, we need to use the timescale-db tune command.

timescaledb-tune --quiet --yes

Running command above will resulting an error on Apple Silicon mac devices. This is expected because of the shipped binary from the TimescaleDB tap is compiled using the amd64 instruction sets, while the Apple Silicon mac expect of arm64 instruction.

To fix the error above, we need to recompile the binary into arm64 architecture. Since the TimescaleDB uses Golang and Bash script to setting up the database app instance, we can recompile the installation script to make them work in the arm64 machine. Both of the language are compatible to the arm64 architecture.

Installing Golang

Golang can be installed using this bash command.

brew install go

After go is installed, we can proceed to installing the timescaledb-tune application with the arm64 compatible binary. Thanks to golang that have simple binary compilation on the go using the based on the repository. To install it, the command should be as follow.

$ go install github.com/timescale/timescaledb-tune/cmd/timescaledb-tune@main

The command above will install the timescaledb-tune app into your $GOPATH/bin directory. In our case, because it is default so the expected app binary directory is in the ~/go directory. We will use the recent installation from source of timescaledb repository.

Configuring TimescaleDB

In this time, we will see what the timescaledb-tune bring into our existing PostgreSQL and TimescaleDB installation. Before running our installed timescaledb-tune we need to go into the GOPATH binary directory. In our case, it would be in the ~/go/bin directory. To get into the directory we can use this command below.

cd ~/go/bin
./timescaledb-tune --quiet --yes

The complete installation output can be seen in the picture below.

The result above indicates that our TimescaleDB and PostgreSQL are both installed and successfully configured.

Copying TimescaleDB lib into the PostgreSQL Installation

PostgreSQL and TimescaleDB are now successfully installed, but the extension is not enabled yet in the postgres. To load that, we need to execute the command below. Remember that the <VERSION> tag is replaceable based on the TimescaleDB extension you have installed.

cd /opt/homebrew/Cellar/timescaledb/<VERSION>/bin/

In our case, the <VERSION> tag would be 2.14.2, and the command should be like this.

cd /opt/homebrew/Cellar/timescaledb/2.14.2/bin/

After changing directory, we can procced to move the extensions and library file from TimescaleDB into the main PostgreSQL DB app by using the shipped bash script named timescaledb_move.sh that exist in the directory.

./timescaledb_move.sh

Let's run the script above.

The result shown on the picture above indicates that the script has not going through any failure again. At this point, we can create a PostgreSQL database that enable the TimescaleDB extension.

ย