# Set up TimescaleDB on Arm64

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/)
- [Get started with TimescaleDB on Google Axion C4A](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/background/)
- [Create a firewall rule for Grafana/TimescaleDB](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/firewall-setup/)
- [Create a Google Axion C4A Arm virtual machine on GCP](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/instance/)
- [Set up TimescaleDB on Arm64](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/setup-timescaledb/)
- [Ingest real-time sensor data on Arm64](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/sensor-data-ingestion/)
- [Install Grafana and configure the TimescaleDB data source](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/grafana-timescaledb-setup/)
- [Build a live sensor temperature dashboard](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/live-sensor-dashboard/)
- [Next Steps](https://learn.arm.com/learning-paths/servers-and-cloud-computing/timescaledb-on-gcp/_next-steps/)

## Set up the TimescaleDB environment
In this section, you prepare an Arm64-based SUSE Linux Enterprise Server (SLES) virtual machine and install TimescaleDB by building it from source. Building from source ensures the database extension is fully optimized for Arm64, which is especially important for high-ingest and time-series workloads.

## Architecture overview
```
Linux Arm64 VM (SUSE)
        |
        v
PostgreSQL 15
        |
        v
TimescaleDB 2.25.0 Extension
```
TimescaleDB provides time-series optimizations on top of PostgreSQL, making it ideal for high-ingest sensor workloads.

## Install build dependencies
TimescaleDB must be compiled against PostgreSQL, so development headers and build tools are required.
```
sudo zypper refresh
```
```
sudo zypper install \
  cmake \
  gcc gcc-c++ make \
  git \
  libopenssl-devel \
  postgresql15 \
  postgresql15-server \
  postgresql15-server-devel \
  postgresql15-devel
```
**Note**: If you are prompted about `readline-devel`, choose **Solution 1 (vendor change/downgrade)**. This avoids dependency conflicts on SUSE and ensures compatibility with PostgreSQL development libraries.

## Initialize PostgreSQL
Before using PostgreSQL, its data directory must be initialized. The following command runs as the `postgres` system user to create the data directory, initialize system tables, and set default configurations:
```
sudo -u postgres initdb -D /var/lib/pgsql/data
```
Enable and start PostgreSQL:
```
sudo systemctl enable postgresql
sudo systemctl start postgresql
```
Verify PostgreSQL is running:
```
psql --version
```
The output is similar to:
```
__output__ 
psql (PostgreSQL) 15.10
```

## Build TimescaleDB from source
Building TimescaleDB from source ensures native Arm64 compilation and optimal performance.

### Clone the repository
Download the official TimescaleDB source code and check out version 2.25.0 to ensure version consistency throughout this Learning Path:
```
git clone https://github.com/timescale/timescaledb.git
cd timescaledb
git checkout 2.25.0
```
**Note**: According to the [release notes](https://github.com/timescale/timescaledb/releases/tag/2.16.0), TimescaleDB 2.16.0 introduces performance optimizations for DML on compressed chunks, improving upsert operations by **100×** and update/delete operations by **1000×** in some cases. The [Arm Ecosystem Dashboard](https://developer.arm.com/ecosystem-dashboard/) recommends **TimescaleDB 2.16.0** or higher for Arm platforms.

### Bootstrap the configuration
```
./bootstrap
```

### Invoke the build
```
cd build
make -j$(nproc)
sudo make install
```
This compiles TimescaleDB natively for Arm64.

## Enable TimescaleDB in PostgreSQL
TimescaleDB must be preloaded when PostgreSQL starts.

### Edit PostgreSQL configuration and add the timescaledb library
Using a suitable editor and `sudo`, edit `/var/lib/pgsql/data/postgresql.conf` and add the following line:
```
shared_preload_libraries = 'timescaledb'
```
This update:
- Ensures TimescaleDB is loaded when PostgreSQL starts.
- Required for advanced TimescaleDB features like background workers and compression.

### Restart PostgreSQL
```
sudo systemctl restart postgresql
```

## Create a database and enable the extension
Enable TimescaleDB at the database level by creating the `sensors` database and loading the extension:
```
sudo -u postgres psql
```
```
CREATE DATABASE sensors;
\c sensors
CREATE EXTENSION IF NOT EXISTS timescaledb;
```
Verify the installed version:
```
SELECT extversion FROM pg_extension WHERE extname='timescaledb';
```
The output is similar to:
```
__output__ 
sensors=# SELECT extversion FROM pg_extension WHERE extname='timescaledb';
__output__ 
 extversion
------------
 2.25.0
(1 row)
```
Press Ctrl+D to exit.

This confirms that TimescaleDB is installed correctly and the expected version is active.

## What you’ve accomplished and what’s next
You’ve successfully:
- Installed PostgreSQL 15 on SUSE Arm64
- Built TimescaleDB 2.25.0 from source for optimal Arm64 performance
- Enabled TimescaleDB at the database level and verified the installation

Next, you’ll create a real-time sensor data ingestion pipeline using Python to continuously insert time-series data into TimescaleDB.
