AlgoViz

TimescaleDB

medium 25 min

TimescaleDB is a PostgreSQL extension for time-series and event data.

Video lesson · Chapter 1 of 5

Where does yesterday's reading go?

0:00 / 3:41

TimescaleDB in 75 seconds

1:15Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

TimescaleDB adds a kind of table, the hypertable, to PostgreSQL. You insert and query it like any table. Behind it are chunks: ordinary tables that each hold one range of time, for example a week.

Around chunks it builds what time series need: a columnar format for old chunks, summaries that refresh themselves, functions such as time_bucket, and background jobs that compress and delete on a schedule.

Why it exists

Measurements arrive in time order and grow without end. Queries want recent ranges, and old data is deleted in bulk. In one huge table the indexes outgrow memory, inserts slow down and deleting a month leaves millions of dead rows.

A separate time-series product solves that and brings a second query language, a second backup and no joins with your customers. TimescaleDB keeps it in PostgreSQL. The price is that it inherits PostgreSQL's shape: one primary takes the writes.

A short history

  1. 2017

    The first beta releases are published on GitHub in March.

  2. 2018

    Timescale announces a source-available licence for newer features, beside the Apache 2.0 core.

  3. 2020

    Version 2.0.0 is released on 18 December.

  4. 2024

    Version 2.14 ends support for multi-node. Version 2.13 was the last to have it.

  5. 2025

    The company Timescale renames itself Tiger Data in June. The extension keeps the name TimescaleDB. Versions 2.18 and 2.20 introduce the columnstore policy and the CREATE TABLE form of hypertables.

Words to know

Hypertable
A table you use as one, partitioned automatically by time.
Chunk
One partition: a real table with rows of one time range.
Chunk exclusion
Leaving out chunks whose range cannot match the query.
Hypercore
The storage engine that keeps recent rows as rows and older ones as compressed columns.
Segment by
Columns whose equal values are compressed together, such as device.
Continuous aggregate
A summary table refreshed in the background for changed time ranges.
Real-time aggregate
A continuous aggregate that adds raw rows not yet summarised.
Retention policy
A job that drops chunks older than an age.

How it works

Step through the idea, or press Play.

Step 1 of 3

Write. Rows go to the chunk of their time, kept as rows

Understand it

Start here

The diary cut into weeks

Imagine a diary that has grown too thick to open. Its owner cuts it into one notebook per week. Today's notebook lies open, old ones are pressed flat, and very old ones are thrown away.

One notebook per week
All weeksOne thick diary

The summary still knows week 1, although its notebook is gone. That works only if the summary was made first and is kept.

The product

Names, editions and versions

Checked November 2026

TopicFact
CompanyTiger Data, called Timescale until June 2025
Managed serviceTiger Cloud, formerly Timescale Cloud
ExtensionTimescaleDB, release 2.32 in November 2026
PostgreSQL versions16, 17 and 18. Support for 15 ended with 2.29
Multi-nodeRemoved in 2.14. Scale with replicas and a bigger primary
Check your editionSHOW timescaledb.license answers timescale or apache

Two editions

Apache 2 EditionCommunity Edition (default)
LicenceApache 2.0Tiger Data License (TSL), source available
Hypertables, chunks, time_bucketYesYes
Columnstore (Hypercore)NoYes
Continuous aggregatesNoYes
Retention policies and jobsNo, but drop_chunks by handYes
Sell it as a hosted serviceAllowedNot allowed
This is why some cloud providers offer only the Apache edition. Ask before you design around compression.

Inside

Hypertables and chunks

SQL
CREATE EXTENSION IF NOT EXISTS timescaledb;CREATE TABLE readings (    time       timestamptz      NOT NULL,    device_id  bigint           NOT NULL,    celsius    double precision) WITH (    tsdb.hypertable,    tsdb.partition_column = 'time',    tsdb.chunk_interval   = '1 day',    tsdb.segmentby        = 'device_id',    tsdb.orderby          = 'time DESC');CREATE UNIQUE INDEX ON readings (device_id, time);
Since 2.20. Older versions call create_hypertable on an existing table. From 2.23 this form also creates a columnstore policy whose age equals the chunk interval. From 2.20 to 2.22 you add the policy yourself.

One server, three kinds of storage

Devices send readings to one PostgreSQL primary. New rows go to the newest chunk, kept as rows. With age they become columns in older chunks. A refresh fills a continuous aggregate with hourly rows, which a dashboard reads.
Every box inside the thick border is in one PostgreSQL server.

What happens on an insert

  1. 1

    Route

    The time value decides the chunk. A missing chunk is created.

  2. 2

    Write

    The row goes to that chunk's heap and indexes, with the usual WAL and MVCC.

  3. 3

    Late rows

    A row for an old time goes to its old chunk, even if that chunk is compressed.

  4. 4

    Uniqueness

    Enforced per chunk, so unique indexes must include the partitioning column.

How long should a chunk be?

index growth per day×days≤0.25×memory2 GB×7=14 GB≤16 GB\text{index growth per day} \times \text{days} \le 0.25 \times \text{memory} \qquad 2\,\text{GB} \times 7 = 14\,\text{GB} \le 16\,\text{GB}
The vendor's example for a machine with 64 GB. At 10 GB of index a day, one day per chunk fits. The default is 7 days. Indexes of every hypertable being written share that memory.

Good chunks

  • Indexes of active chunks fit in shared buffers
  • Hundreds of chunks, not tens of thousands
  • One interval that matches common queries and retention

Trouble

  • Hourly chunks kept for five years
  • A space dimension added without a test: it multiplies chunks
  • Expecting a new interval to resize old chunks

Reads

Filter on time, or read everything

How a query is planned

EXPLAIN (ANALYZE, BUFFERS) lists the chunks that were touched.
SQL
-- Five-minute averages for one device, last daySELECT time_bucket('5 minutes', time) AS bucket, avg(celsius)FROM readingsWHERE device_id = 42 AND time > now() - INTERVAL '1 day'GROUP BY bucket ORDER BY bucket;-- Newest value per deviceSELECT device_id, last(celsius, time) AS latestFROM readingsWHERE time > now() - INTERVAL '1 hour'GROUP BY device_id;-- Fill gaps with the last known valueSELECT time_bucket_gapfill('1 hour', time) AS hour,       locf(avg(celsius)) AS celsiusFROM readingsWHERE device_id = 42  AND time >= now() - INTERVAL '1 day' AND time < now()GROUP BY hour ORDER BY hour;
Say the time limit even when the answer would be the same: without it, chunks cannot be excluded. locf carries the last observation forward.

Storage

Hypercore: rows first, columns later

The newest chunks stay in the rowstore, where inserts and updates are cheap. A policy converts older chunks to the columnstore: many rows become one row of arrays, each array compressed for its type. The vendor states 90 to 98% savings. Measure yours, because it depends on the data and on the order.

Two choices that decide the result

SettingGood valueBad value
Segment byWhat you filter by with equality, many rows per value: device_idA value nearly unique per row: request_id
Order byTime, so neighbours are similar and ranges can be skippedA random column
Age of conversionWhen most late rows have arrivedWhile rows are still corrected every minute
Batches keep their minimum and maximum, and bloom filters are built by default on new columnstore chunks, so batches can be skipped without unpacking.

The life of a chunk

Inserts, updates and deletes work in the columnstore too. Frequent small changes there still cost more than in rows.
SQL
-- Change when chunks are convertedCALL remove_columnstore_policy('readings');CALL add_columnstore_policy('readings', after => INTERVAL '7 days');-- Keep raw rows for 90 daysSELECT add_retention_policy('readings', INTERVAL '90 days');-- Did the jobs run?SELECT job_id, last_run_status, last_successful_finish, total_failuresFROM timescaledb_information.job_stats;

Summaries

Continuous aggregates

SQL
CREATE MATERIALIZED VIEW readings_hourlyWITH (timescaledb.continuous) ASSELECT time_bucket('1 hour', time) AS bucket, device_id,       avg(celsius) AS avg_c, min(celsius) AS min_c,       max(celsius) AS max_c, count(celsius) AS nFROM readingsGROUP BY bucket, device_idWITH NO DATA;SELECT add_continuous_aggregate_policy('readings_hourly',    start_offset => INTERVAL '3 days',    end_offset => INTERVAL '1 hour',    schedule_interval => INTERVAL '30 minutes');-- Include raw rows that are not summarised yetALTER MATERIALIZED VIEW readings_hourlySET (timescaledb.materialized_only = false);
Every 30 minutes the job refreshes changed buckets between 3 days and 1 hour ago. Real-time reading has been off by default since 2.13.

Why dashboards get fast

10,000 devices10 s×86,400 s=86.4 M rows a day10,000×24=240,00086.4 M240,000=360\frac{10{,}000\ \text{devices}}{10\,\text{s}} \times 86{,}400\,\text{s} = 86.4\,\text{M rows a day} \qquad 10{,}000 \times 24 = 240{,}000 \qquad \frac{86.4\,\text{M}}{240{,}000} = 360
Assumed: 10,000 devices reporting every 10 seconds, 1,000 rows a second on average and 3,000 at peak. The hourly summary is 360 times smaller.

How a late reading reaches the summary

A change older than the start offset is not refreshed by the policy. Refresh that range by hand.

Growth

Availability and scaling

The usual production shape

Collectors send readings to a log. A batch writer inserts into one primary. The primary streams changes to a standby in another zone and to a read replica, which serves dashboards.
One primary takes every write. The standby protects, and the replica reads.

In this order

  1. 1

    Batch and COPY

    Insert hundreds or thousands of rows per statement. A log in front absorbs bursts.

  2. 2

    Fewer indexes

    Each index is written for each row. Keep device and time, and little else.

  3. 3

    Scale up

    Memory for active chunks and fast disks. See vertical scaling.

  4. 4

    Replicas

    Dashboards move to streaming replicas and accept lag, as in replication.

  5. 5

    Split by tenant or region

    Several independent databases. Queries across them are yours to combine, because multi-node is gone.

Operations

Jobs, freshness and upgrades

What to watch

  • Jobs

    Last status and failures of columnstore, refresh and retention. A silent failure fills the disk.

  • Chunks

    Count, size and share in columnstore.

  • Freshness

    Age of the newest row, and how far the summary lags behind it.

  • PostgreSQL itself

    WAL rate, replica lag, vacuum, connections and cache hits.

Upgrades have two parts: PostgreSQL and the extension, and each release supports certain pairs. Release notes matter: the notes for 2.32.1 warn that earlier patch versions break every background job on the PostgreSQL minor releases 18.7, 17.12 and 16.16, so the extension must be upgraded first. Restores need the matching extension version and the documented pre-restore and post-restore calls.

Decide

When to choose it, and when not

Choose it when

  • Rows arrive roughly in time order and rarely change
  • Most queries filter on time
  • You need joins with relational data, constraints and transactions
  • One strong primary can take the writes

Do not when

  • A few million rows: a plain table or native partitions will do
  • Most queries ignore time
  • Writes exceed one primary
  • You need scans across huge wide tables for many teams: ClickHouse

Neighbours

ChoiceBetter whenWeaker when
PostgreSQL partitionsFew partitions, no extension allowedYou build creation, compression and rollups yourself
ClickHouseVery large analytics, append onlyRow updates, constraints, transactions
PrometheusMetrics and alerts of serversBusiness data, joins, long retention by itself
CassandraWrite volume over many nodes, known queriesAd-hoc SQL and aggregates
The design of a full system of this kind is in metrics monitoring.

Do I need it?

Cost: the server, its standby, and disk that compression reduces. Self-hosting the Community Edition is free. What you pay is operation, and the licence decides whether you may resell it.

Summary

The whole topic in one minute.

TimescaleDB cuts a table by time inside PostgreSQL. Recent chunks stay small enough for fast inserts, old chunks become compressed columns, and whole chunks are dropped when they expire.

Filter on time, size chunks by memory, include the time column in unique keys, and read dashboards from continuous aggregates. Check which edition you run: columnstore, continuous aggregates and retention policies are in the Community Edition, whose licence forbids selling it as a service.

  • A hypertable is one table to you and many chunks to the planner.
  • Size chunks so that active indexes fit in memory. The default is 7 days.
  • Unique keys must include the time column.
  • Recent rows, older columns, then drop whole chunks.
  • Continuous aggregates refresh only changed buckets inside a window.
  • One primary writes. Multi-node ended with 2.14.

Sources