Subscribe to the Timescale Newsletter

By submitting you acknowledge Timescale's  Privacy Policy.

How to Install TimescaleDB on AWS

How to Install TimescaleDB on AWS

TimescaleDB is a powerful, open-source database built on top of PostgreSQL to efficiently manage time-series data, events, and analytics. Optimized for fast ingest and complex queries, it speaks “full SQL” and is correspondingly easy to use like a traditional relational database, yet scales in ways previously reserved for NoSQL databases. 

This guide will walk you through setting up TimescaleDB on Amazon Web Services (AWS), ensuring you have a scalable and high-performance database ready to handle your time-series data needs.

What you'll learn:

  • How to get started with AWS
  • Setting up your EC2 instance
  • Installing TimescaleDB
  • Configuring PostgreSQL
  • Using TimescaleDB

Getting Started With AWS and TimescaleDB

First, head over to AWS and create your AWS account. Once you've logged into the AWS console, you'll see a dashboard similar to this:

AWS dashboard

Launching an EC2 instance

1. Navigate to EC2: Click on the 'Services' tab in the top left corner and select 'EC2' from the panel of AWS services.

Console page that lists AWS services

2. Launch instance: Click on 'Launch Instance' to open the Amazon Machine Image (AMI) selection page.

The AWS EC2 dashboard page with the button 'Launch instance' framed by a green box

3. Choose an AMI: Begin by setting up the OS Image you're going to use. In this case, select the 'Ubuntu Server 20.04 LTS' image, as TimescaleDB supports this version.

The 'Launch an instance' page with a green frame about Ubuntu and the Amazon Machine Image options

Setting up your instance

For this tutorial, we will use a minimal configuration for simplicity, but for production, consider using a r5.4xlarge instance with the following EBS volumes:

  • WAL: gp2, 350 GB (higher IOPS recommended)
  • Data: gp2, 5 TB

1. Instance type: Select the t2.micro instance type.

The instance dropdown menu on the AWS console

2. Key pair: Create a new key pair named timescale or use an existing one. Download the key pair and save it securely. The file extension should be .pem.

3. Launch instance: Finally, click on ‘Launch Instance’.

4. Instance status: Wait for the instance to initialize. Click on the instance ID to view its details.

A yellow frame around the instance ID in AWS's Instances page

Connecting to your EC2 instance

1. Select your instance, and click on the Connect button. A dialog will open.

2. SSH command: Head to the "SSH client" tab. Follow the instructions there. Find the command in the details and copy it to your clipboard. In this case, my full command is: 

ssh -i "timescale.pem" [email protected]
The Connect to instance page

3. Set file permissions: On your local machine, navigate to the directory containing the .pem file and set the correct permissions:   

sudo chmod 400 timescale.pem

4. Connect via SSH: Use the copied SSH command to connect to your instance.

ssh -i "timescale.pem" [email protected]
The command output

Installing TimescaleDB

1. Add TimescaleDB PPA:

sudo apt install gnupg postgresql-common apt-transport-https lsb-release wget

sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

echo "deb https://packagecloud.io/timescale/timescaledb/ubuntu/ $(lsb_release -c -s) main" | sudo tee /etc/apt/sources.list.d/timescaledb.list

wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg

sudo apt update
The command output

2. Install TimescaleDB:

sudo apt install timescaledb-2-postgresql-16 postgresql-client

Configuring PostgreSQL

1. Check the PostgreSQL version (ensure it shows psql (PostgreSQL) 16.x):

psql --version

The command output

2. Modify configuration:

cd /etc/postgresql/16/main
sudo chmod 644 postgresql.conf
nano postgresql.conf
The command output

3. Update postgresql.conf:

Set listen_addresses to '*':

listen_addresses = '*'

Set shared_preload_libraries to timescaledb:

shared_preload_libraries = 'timescaledb'

Save and exit the editor.

The command output
  1. Tune PostgreSQL:
sudo timescaledb-tune
The command output


5. Restart PostgreSQL:

sudo systemctl restart postgresql

6. Switch to PostgreSQL user:

sudo su - postgres

Using TimescaleDB

1. Access PostgreSQL:

psql -U postgres

2. Create database:

CREATE DATABASE tutorial;

3. Connect to the database:

\c tutorial

4. Initialize TimescaleDB extension:

CREATE EXTENSION IF NOT EXISTS timescaledb;

5. Create a hypertable:

CREATE TABLE conditions (
    time        TIMESTAMPTZ       NOT NULL,
    location    TEXT              NOT NULL,
    temperature DOUBLE PRECISION  NULL,
    humidity    DOUBLE PRECISION  NULL
);
SELECT create_hypertable('conditions', 'time');

6. Insert data:

INSERT INTO conditions(time, location, temperature, humidity)
VALUES (NOW(), 'office', 70.0, 50.0);

7. Query data:

SELECT * FROM conditions ORDER BY time DESC LIMIT 100;
The command output

And you're set up for success!

Next Steps

You now have TimescaleDB up and running on AWS. Explore more with sample datasets and advanced tutorials available in the TimescaleDB documentation. If you have any questions, feel free to join our Slack community or check out our GitHub repository (GitHub ⭐ are welcome!). 

For smaller teams wanting to focus on application development and not their database or enterprises looking for scale, cost-effectiveness, and the peace of mind of a managed solution (with one-click high availability, forking, connection pooling, a low-cost storage tier for older data, SOC 2 Type 2 compliance, and much more), try Timescale Cloud. It’s free for 30 days (no credit card required).  

Ingest and query in milliseconds, even at terabyte scale.
This post was written by
5 min read
Tutorials & How-tos
Contributors

Related posts