How to install TimescaleDB on Ubuntu 20.04

If you are looking for a database for analyzing time series data, TimescaleDB might be the best option. TimescaleDB is based on PostgreSQL, but is tuned for speed and scalability when it comes to analyze time series data. It is an open source and free database system provided by the PostgreSQL developers. This database system is very useful when using a real-time monitoring system and a system that requires time series data. In this article we will learn how to install and configure TimescaleDB with PostgreSQL on Ubuntu 20.04.

Prerequisites

  1. Fresh installed Ubuntu 20.04
  2. Root privileged account
  3. Internet connection to install the packages

Install TimescaleDB on Ubuntu 20.04

To install and configure the TimescaleDB on Ubuntu 20.04, follow the steps below.

Update the system

Before starting the setup, update ubuntu using the following command

$ sudo apt update

Install PostgreSQL

Before installing the TimescaleDB, we need to install postgresql. TimescalDB supports postgresql 9.6 or later. In this example, postgresql-12 is being installed. You can change the version as per your requirement.

$ sudo apt install postgresql-12

Install PostgreSQL

To verify the installation, connect to the postgresql with the user postgres as:

$ sudo su - postgres

Install TimescaleDB

To install timescaledb, you need to add timescaledb-ppa in the apt repository.

$ sudo add-apt-repository ppa:timescale/timescaledb-ppa

Add TimescaleDB repository

Now update the system to reflect the changes

$ sudo apt-get update

Now it's time to install timescaledb. In this example, I have used postgresql-12 for demonstration. You can select the version of postgresql available on your system.

$ sudo apt install timescaledb-postgresql-12

Install TimescaleDB

One the installation is completed, postgresql configuration setting needs to be updated for TimeScaleDB. For the valid configuration settings, press ‘y’ and hit enter.

$ sudo timescaledb-tune --quiet --yes

Tune TimescaleDB

Restart the postgresql to reflect the changes.

$ sudo systemctl restart postgresql

If you want to make the configuration manually for TimescaleDB, edit the postgresql.conf file with an editor like vim.

$ sudo vim /etc/postgresql/12/main/postgresql.conf

Find the following line and make the changes as below.

shared_preload_libraries = ‘timescaledb’

Restart the postgresql service to update the changes.

$ sudo systemctl restart postgresql

Test the TimescaleDB

Now the TimescaleDB installation can be confirmed by creating a new database or by using the existing PostgreSQL database.

Connect to postgresql and enter the psql shell using the command below.

$ sudo su - postgres
$ psql

Create an empty postgresql database. In this example, vitux_test_db is being used for a time series database. You can select the db name accordingly.

CREATE database vitux_test_db;

Add the TimescaleDB

To add the TimescaleDB, connect to the database created previously.

postgres=# \c vitux_test_db

Now extend the postgreSQL database with TimescaleDB as:

CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

TimescaleDB

The output shows that the TimescaleDB has been installed and working fine.

Conclusion

In this article, we learned how to install and configure TimescaleDB with PostgreSQL for time series data. Thank you for reading.