TimescaleDB is a time-series database designed to handle time-stamped data efficiently. Time-series data is indexed, listed, or graphed in time order. It’s often generated by sensors, IoT devices, or logging systems, where each data point is associated with a timestamp. TimescaleDB is a powerful solution for managing time-series data efficiently, offering scalability, performance, and flexibility for various use cases, such as IoT, financial data analysis, monitoring systems, and more.

In this tutorial, we will show you how to deploy TimescaleDB on Ubuntu 22.04.

Step 1 – Install PostgreSQL

TimescaleDB is an extension for PostgreSQL, so you need to have PostgreSQL installed.

First, add the PostgreSQL repository using the following command:

curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Then, update the repository index and install the latest version of PostgreSQL using the following command:

apt update -y
apt install postgresql-12 -y

Next, set the PostgreSQL password using the following command:

su - postgres
psql -c "alter user postgres with password 'password'"

Next, exit from the PostgreSQL shell.

exit

Step 2 – Install TimescaleDB

Before installing TimescaleDB, you will need to install the OpenSSL library to your system.

First, download the libssl Debian package.

wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.22_amd64.deb

Next, install the downloaded package file using the dpkg:

dpkg -i libssl1.1_1.1.1f-1ubuntu2.22_amd64.deb

Next, add the TimescaleDB GPG key.

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 55EE6BF7698E3D58D72C0DD9ECB3980CC59E610B

Next, create a TimescaleDB APT configuration file.

nano /etc/apt/sources.list.d/timescale-ubuntu-timescaledb-ppa-jammy.list

Add the TimescaleDB repository:

deb https://ppa.launchpadcontent.net/timescale/timescaledb-ppa/ubuntu/ focal main

Save and close the file, update the repository index, and install TimescaleDB with the following command:

apt update
apt install timescaledb-postgresql-12

Next, initialize TimescaleDB on your PostgreSQL instance:

timescaledb-tune --quiet --yes

Finally, restart the PostgreSQL service to apply the changes.

systemctl restart postgresql 

Step 3 – Enable TimescaleDB

To enable the TimescaleDB, edit the PostgreSQL main configuration file.

nano /etc/postgresql/12/main/postgresql.conf

Add the following line:

shared_preload_libraries = 'timescaledb'

Save and close the file, then restart the PostgreSQL service to apply the changes.

systemctl restart [email protected] 

Next, connect to the PostgreSQL shell:

su - postgres
psql

Then, create a database and enable the TimescaleDB extension:

CREATE database db1;
\c db1
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

Output:

WARNING:  
WELCOME TO
 _____ _                               _     ____________  
|_   _(_)                             | |    |  _  \ ___ \ 
  | |  _ _ __ ___   ___  ___  ___ __ _| | ___| | | | |_/ / 
  | | | |  _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \ 
  | | | | | | | | |  __/\__ \ (_| (_| | |  __/ |/ /| |_/ /
  |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
               Running version 1.7.5
For more information on TimescaleDB, please visit the following links:

 1. Getting started: https://docs.timescale.com/getting-started
 2. API reference documentation: https://docs.timescale.com/api
 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture

Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.

CREATE EXTENSION

You can verify that TimescaleDB is installed and functioning correctly by connecting to your database and checking its status:

psql -U postgres -h localhost -d db1

Output:

psql (12.18 (Ubuntu 12.18-1.pgdg22.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

db1=# 

Conclusion

In this guide, we explained how to deploy TimescaleDB on Ubuntu 22.04. Users opt for TimescaleDB for several compelling reasons. Its optimized architecture is specifically tailored for time-series data ensures superior performance and scalability compared to traditional relational databases. TimescaleDB’s ability to handle large volumes of data while maintaining fast query response times makes it an ideal choice for time-series workloads. You can deploy TimescaleDB on dedicated server hosting from Atlantic.Net!