TimescaleDB: Hypertables, Continuous Aggregates and Retention

Time-series on PostgreSQL - which is the entire argument for it and also exactly where its limits come from.

Taught by Noshad Alam 7 lessons 1 hr 5 min Published 30 Nov 2026

TimescaleDB is a PostgreSQL extension that makes PostgreSQL good at time-series data. That sentence contains the whole course, in both directions.

Overview

**In its favour:** it is PostgreSQL. Full SQL with joins, window functions, CTEs and subqueries. Foreign keys to your relational tables, so telemetry can reference the machine registry it belongs to and the database enforces it. Every PostgreSQL driver, every ORM, every migration tool, every monitoring integration, every backup tool and everything anyone on your team already knows. **A time-series database you can join against your business data is a materially different proposition from one you cannot**, and it is why TimescaleDB is so often the right answer for a team that already runs PostgreSQL.

**And the other direction:** it is PostgreSQL. You inherit PostgreSQL's operational characteristics completely - autovacuum, WAL, connection limits, the planner, the shared buffer pool, and the fact that a long-running transaction holds back cleanup. It will not match a purpose-built columnar engine on raw ingestion rate at extreme scale, and **multi-node scale-out was deprecated and then removed**, so the horizontal answer is not available: you scale up, and you scale out by sharding at the application level or by using the managed service. Knowing that before you design is worth a great deal.

The mechanisms are few and each has a sharp edge. A **hypertable** is a table automatically partitioned into **chunks** by time, and the chunk interval is the main tuning decision. **Continuous aggregates** are incrementally refreshed materialised views, and their refresh policy's offsets decide which late data is ever incorporated - **the same late-data problem as every time-series system, with a concrete and checkable mechanism**. **Columnstore compression** converts chunks to a columnar layout at ten to twenty times, and its `segmentby` setting decides whether your queries benefit or suffer. **Retention** drops whole chunks, which is nearly free and interacts dangerously with continuous aggregates.

One genuine relief if you have come from the previous course: **high cardinality is not a crisis here.** A million distinct devices is a million values in a column, not a million index entries competing for memory. That changes the modelling conversation entirely.

Seven modules, about 80 hours. The capstone is a ride telemetry analytics platform with continuous aggregates, retention and a recovery drill.

Introduction

This course assumes the programme's shared foundations and **expects the PostgreSQL course or equivalent experience**. We do not re-teach SQL, indexes, `EXPLAIN`, transactions or MVCC - we use them. If `EXPLAIN (ANALYZE, BUFFERS)` is not already a tool you reach for, do that course first; it is the single best preparation for this one.

For a sandbox, run **PostgreSQL 16 or 17 with TimescaleDB 2.x** in Docker, which is one image and no assembly. Record the TimescaleDB version precisely, because the compression and continuous aggregate features have moved substantially across minor versions and an answer from two years ago may describe behaviour you do not have.

You also need a **ride telemetry generator**, written in Module 1 and used throughout: vehicles, trips, GPS positions, speed, battery state and events, at a configurable rate, with **configurable device cardinality** and the ability to emit **late points** for a trip that ended hours ago. The capstone depends on both of those capabilities.

One habit from the start: **read the plan.** Every performance claim in this course is checkable with `EXPLAIN (ANALYZE, BUFFERS)`, and the specific thing to look for - whether chunk exclusion happened - is visible in it. A TimescaleDB query that is slow is almost always scanning chunks it did not need to, and the plan says so.

What you will be able to do

  • Create and configure hypertables, and choose a chunk interval with reasons
  • Explain chunks, chunk exclusion and why the interval is the main tuning knob
  • Write time-series SQL with time_bucket, gap filling and interpolation
  • Design a time-series schema with normalised dimensions and foreign keys
  • Explain why high cardinality is not the crisis here that it is elsewhere
  • Build continuous aggregates and configure refresh policies deliberately
  • State exactly which late data a refresh policy will and will not incorporate
  • Configure columnstore compression and tune segmentby and orderby
  • Measure compression ratio and the query effect of segmentby choices
  • Implement retention with drop_chunks and order policies safely
  • Diagnose a slow query by reading chunk exclusion in the plan
  • Ingest efficiently with COPY and batched inserts, and measure it
  • Plan backup and point-in-time recovery with extension awareness
  • Configure streaming replication and measure replication lag
  • Apply roles, TLS and row-level security, and explain the RLS caveat
  • Plan extension and PostgreSQL version upgrades in the right order
  • Produce a storage lifecycle and cost model

What each level covers

5 levels · 7 lessons

  1. Beginner - Foundations

    Hypertables, chunks and the extension model; then the time-series SQL and the schema design that follows from it.

    2 lessons 21 min of reading

    Start with The Extension Model, Hypertables, Chunks and Ingestion →
  2. Intermediate - Application Behaviour

    Continuous aggregates and their refresh offsets, compression, and the retention interaction that loses data.

    1 lesson 12 min of reading

    Start with Continuous Aggregates, Compression and Retention Policies →
  3. Advanced - Performance and Reliability

    Reading plans to find the real cost; then PostgreSQL's recovery machinery, which is the best in this programme.

    2 lessons 15 min of reading

    Start with Chunk Exclusion, EXPLAIN, Batch Ingestion and Aggregate Performance →
  4. Expert - Security and Production Architecture

    Roles, the row-level security caveat that surprises people, monitoring, and the storage lifecycle that is the bill.

    1 lesson 10 min of reading

    Start with Roles, TLS, Row-Level Security, Monitoring and Upgrades →
  5. Capstone

    One ride telemetry platform, defended on aggregate correctness, a verified recovery drill and a priced lifecycle.

    1 lesson 7 min of reading

    Start with Capstone - Ride Telemetry Analytics Platform →

Guides and articles

Longer reading about this subject, written alongside the course.

Course guide How to work through this course Why to do PostgreSQL first, the four decisions that matter, the two experiments worth doing properly, and what to skip. 4 min read

Before you start

  • Docker, with PostgreSQL 16 or 17 and TimescaleDB 2.x
  • psql, and a PostgreSQL client library
  • A ride telemetry generator you write, with configurable cardinality and late points
  • The PostgreSQL course or equivalent working experience

Common questions

What does the TimescaleDB: Hypertables, Continuous Aggregates and Retention course cover?
It is 5 levels and 7 lessons: Beginner - Foundations; Intermediate - Application Behaviour; Advanced - Performance and Reliability; Expert - Security and Production Architecture; Capstone. Each level ends with a quiz, and the last one is an exam over the whole course.
How long does it take?
About 65 minutes of reading and exercises - roughly 1.1 hours. It is self-paced with no cohort and no start date, so you can leave and come back and the site remembers where you were.
What do I need to know first?
Docker, with PostgreSQL 16 or 17 and TimescaleDB 2.x. psql, and a PostgreSQL client library. A ride telemetry generator you write, with configurable cardinality and late points. The PostgreSQL course or equivalent working experience.
Is it free?
Yes. Every lesson, example and quiz in this course is free to read, and you do not need an account to read them. Signing in only adds progress tracking and quiz results.
What will I be able to do afterwards?
Create and configure hypertables, and choose a chunk interval with reasons. Explain chunks, chunk exclusion and why the interval is the main tuning knob. Write time-series SQL with time_bucket, gap filling and interpolation. Design a time-series schema with normalised dimensions and foreign keys. Explain why high cardinality is not the crisis here that it is elsewhere. Build continuous aggregates and configure refresh policies deliberately. State exactly which late data a refresh policy will and will not incorporate. Configure columnstore compression and tune segmentby and orderby. Measure compression ratio and the query effect of segmentby choices. Implement retention with drop_chunks and order policies safely. Diagnose a slow query by reading chunk exclusion in the plan. Ingest efficiently with COPY and batched inserts, and measure it. Plan backup and point-in-time recovery with extension awareness. Configure streaming replication and measure replication lag. Apply roles, TLS and row-level security, and explain the RLS caveat. Plan extension and PostgreSQL version upgrades in the right order. Produce a storage lifecycle and cost model.