Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

timescaledb

> 数据库
Open source

A time-series database for high-performance real-time analytics packaged as a Postgres extension

23.2K stars0 likes1 views
WebsiteGitHub

About

A time-series database for high-performance real-time analytics packaged as a Postgres extension

Quick Start with TimescaleDB

Get started with TimescaleDB in under 10 minutes. This guide will help you run TimescaleDB locally, create your first hypertable with columnstore enabled, write data to the columnstore, and see instant analytical query performance.

What You'll Learn

  • How to run TimescaleDB with a one-line install or Docker command
  • How to create a hypertable with columnstore enabled
  • How to insert data directly to the columnstore
  • How to execute analytical queries

Prerequisites

  • Docker installed on your machine
  • 8GB RAM recommended
  • psql client (included with PostgreSQL) or any PostgreSQL client like pgAdmin

Step 1: Start TimescaleDB

You have two options to start TimescaleDB:

Option 1: One-line install (Recommended)

The easiest way to get started:

Important: This script is intended for local development and testing only. Do not use it for production deployments. For production-ready installation options, see the TimescaleDB installation guide.

Linux/Mac:

bash
curl -sL https://tsdb.co/start-local | sh

This command:

  • Downloads and starts TimescaleDB (if not already downloaded)
  • Exposes PostgreSQL on port 6543 (a non-standard port to avoid conflicts with other PostgreSQL instances on port 5432)
  • Automatically tunes settings for your environment using timescaledb-tune
  • Sets up a persistent data volume

Option 2: Manual Docker command also used for Windows

Alternatively, you can run TimescaleDB directly with Docker:

bash
docker run -d --name timescaledb \
    -p 6543:5432 \
    -e POSTGRES_PASSWORD=password \
    timescale/timescaledb-ha:pg18

Note: We use port 6543 (mapped to container port 5432) to avoid conflicts if you have other PostgreSQL instances running on the standard port 5432.

Wait about 1-2 minutes for TimescaleDB to download & initialize.

Step 2: Connect to TimescaleDB

Connect using psql:

bash
psql -h localhost -p 6543 -U postgres
# When prompted, enter password: password

You should see the PostgreSQL prompt. Verify TimescaleDB is installed:

sql
SELECT extname, extversion FROM pg_extension WHERE extname = 'timescaledb';

Expected output:

   extname   | extversion
-------------+------------
 timescaledb | 2.x.x

Prefer a GUI? If you'd rather use a graphical tool instead of the command line, you can download pgAdmin and connect to TimescaleDB using the same connection details (host: localhost, port: 6543, user: postgres, password: password).

Step 3: Create Your First Hypertable

Let's create a hypertable for IoT sensor data with columnstore enabled:

sql
-- Create a hypertable with automatic columnstore
CREATE TABLE sensor_data (
    time TIMESTAMPTZ NOT NULL,
    sensor_id TEXT NOT NULL,
    temperature DOUBLE PRECISION,
    humidity DOUBLE PRECISION,
    pressure DOUBLE PRECISION
) WITH (
    tsdb.hypertable
);

tsdb.hypertable - Converts this into a TimescaleDB hypertable

See more:

  • About hypertables
  • API reference
  • About columnstore
  • Enable columnstore manually
  • API reference

Step 4: Insert Sample Data

Let's add some sample sensor readings:

…

This generates ~7,776,001 readings across 10 sensors over the past 90 days.

Verify the data was inserted:

sql
SELECT COUNT(*) FROM sensor_data;

Step 5: Run Your First Analytical Queries

Now let's run some analytical queries that showcase TimescaleDB's performance:

…

Notice how fast these analytical queries run, even with aggregations across millions of rows. This is the power of TimescaleDB's columnstore.

What's Happening Behind the Scenes?

TimescaleDB automatically:

  • Partitions your data into time-based chunks for efficient querying
  • Write directly to columnstore using columnar storage (90%+ compression typical) and faster vectorized queries
  • Optimizes queries by only scanning relevant time ranges and columns
  • Enables time_bucket() - a powerful function for time-series aggregation

See more:

  • Query data
  • Write data
  • About time buckets
  • API reference
  • All TimescaleDB features

Next Steps

Now that you've got the basics, explore more:

Create Continuous Aggregates

Continuous aggregates make real-time analytics run faster on very large datasets. They continuously and incrementally refresh a query in the background, so that when you run such query, only the data that has changed needs to be computed, not the entire dataset. This is what makes them different from regular PostgreSQL materialized views, which cannot be incrementally materialized and have to be rebuilt from scratch every time you want to refresh them.

Let's create a continuous aggregate for hourly sensor statistics:

Step 1: Create the Continuous Aggregate

sql
CREATE MATERIALIZED VIEW sensor_data_hourly
WITH (timescaledb.continuous) AS
SELECT
    time_bucket('1 hour', time) AS hour,
    sensor_id,
    AVG(temperature) AS avg_temp,
    AVG(humidity) AS avg_humidity,
    AVG(pressure) AS avg_pressure,
    MIN(temperature) AS min_temp,
    MAX(temperature) AS max_temp,
    COUNT(*) AS reading_count
FROM sensor_data
GROUP BY hour, sensor_id;

This creates a materialized view that pre-aggregates your sensor data into hourly buckets. The view is automatically populated with existing data.

Step 2: Add a Refresh Policy

To keep the continuous aggregate up-to-date as new data arrives, add a refresh policy:

sql
SELECT add_continuous_aggregate_policy(
    'sensor_data_hourly',
    start_offset => INTERVAL '3 hours',
    end_offset => INTERVAL '1 hour',
    schedule_interval => INTERVAL '1 hour'
);

This policy:

  • Refreshes the continuous aggregate every hour
  • Processes data from 3 hours ago up to 1 hour ago (leaving the most recent hour for real-time queries)
  • Only processes new or changed data incrementally

Step 3: Query the Continuous Aggregate

Now you can query the pre-aggregated data for much faster results:

sql
-- Get hourly averages for the last 24 hours
SELECT
    hour,
    sensor_id,
    ROUND(avg_temp::numeric, 2) AS avg_temp,
    ROUND(avg_humidity::numeric, 2) AS avg_humidity,
    reading_count
FROM sensor_data_hourly
WHERE hour > NOW() - INTERVAL '24 hours'
ORDER BY hour DESC, sensor_id
LIMIT 50;

Benefits of Continuous Aggregates

  • Faster queries: Pre-aggregated data means queries run in milliseconds instead of seconds
  • Incremental refresh: Only new/changed data is processed, not the entire dataset
  • Automatic updates: The refresh policy keeps your aggregates current without manual intervention
  • Real-time option: You can enable real-time aggregation to combine materialized and raw data

Try It Yourself

Compare the performance difference:

sql
-- Query the raw hypertable (slower on large datasets)
\timing on
SELECT
    time_bucket('1 hour', time) AS hour,
    AVG(temperature) AS avg_temp
FROM sensor_data
WHERE time > NOW() - INTERVAL '60 days'
GROUP BY hour
ORDER BY hour DESC
LIMIT 24;

-- Query the continuous aggregate (much faster)
SELECT
    hour,
    avg_temp
FROM sensor_data_hourly
WHERE hour > NOW() - INTERVAL '60 days'
ORDER BY hour DESC
LIMIT 24;

Notice how the continuous aggregate query is significantly faster, especially as your dataset grows!

See more:

  • About continuous aggregates
  • API reference
  • TimescaleDB Documentation
  • Time-series Best Practices
  • Continuous Aggregates

Examples

Learn TimescaleDB with complete, standalone examples using real-world datasets. Each example includes sample data and analytical queries.

  • NYC Taxi Data - Transportation and location-based analytics
  • Financial Market Data - Trading and market data analysis
  • Application Events - Event logging with UUIDv7

Or try some of our workshops

  • AI Workshop: EV Charging Station Analysis - Integrate PostgreSQL with AI capabilities for managing and analyzing EV charging station data
  • Time-Series Workshop: Financial Data Analysis - Work with cryptocurrency tick data, create candlestick charts

Want TimescaleDB hosted and managed for you? Try Tiger Cloud

Tiger Cloud is the modern PostgreSQL data platform for all your applications. It enhances PostgreSQL to handle time series, events, real-time analytics, and vector search—all in a single database alongside transactional workloads. You get one system that handles live data ingestion, late and out-of-order updates, and low latency queries, with the performance, reliability, and scalability your app needs. Ideal for IoT, crypto, finance, SaaS, and a myriad other domains, Tiger Cloud allows you to build data-heavy, mission-critical apps while retaining the familiarity and reliability of PostgreSQL. See our whitepaper for a deep dive into Tiger Cloud's architecture and how it meets the needs of even the most demanding applications.

A Tiger Cloud service is a single optimized 100% PostgreSQL database instance that you use as is, or extend with capabilities specific to your business needs. The available capabilities are:

  • Time-series and analytics: PostgreSQL with TimescaleDB. The PostgreSQL you know and love, supercharged with functionality for storing and querying time-series data at scale for real-time analytics and other use cases. Get faster time-based queries with hypertables, continuous aggregates, and columnar storage. Save on storage with native compression, data retention policies, and bottomless data tiering to Amazon S3.
  • AI and vector: PostgreSQL with vector extensions. Use PostgreSQL as a vector database with purpose built extensions for building AI applications from start to scale. Get fast and accurate similarity search with the pgvector and pgvectorscale extensions. Create vector embeddings and perform LLM reasoning on your data with the pgai extension.
  • PostgreSQL: the trusted industry-standard RDBMS. Ideal for applications requiring strong data consistency, complex relationships, and advanced querying capabilities. Get ACID compliance, extensive SQL support, JSON handling, and extensibility through custom functions, data types, and extensions. All services include all the cloud tooling you'd expect for production use: automatic backups, [high availability](https://docs.tigerdata.com/use-t

Issues· 411 open

View all issuesOpen on GitHub
  • #9432

    Dependency Dashboard

    ciUpdated Sep 30, 2026
  • #9342

    [Bug]: Hierarchial CAgg Chain Broken from 1 day to 1 month

    bugContinuous Aggregatev2.23.1Updated Sep 30, 2026
  • #10721

    [Bug]: Multi-row INSERT into a compressed chunk raises a false duplicate-key error, or silently drops rows with ON CONFLICT DO NOTHING, after a row with NULL in a segmentby key column

    bugneeds-triagev2.31.0Updated Sep 30, 2026
  • #10414

    [Bug]: Segfault on DELETE, SELECT, and INSERT ON CONFLICT against a columnstore chunk converted with `timescaledb.sparse_index = ''`

    bugv2.29.1Updated Sep 29, 2026
  • #10711

    [Bug]: Query cancel during TSL load sticks the backend on the Apache continuous-aggregate stub (0A000) even when timescaledb.license is timescale

    bugv2.30.1Updated Sep 29, 2026
  • #10709

    [Bug]: Compression changes interval values: equal intervals with different month/day/time parts are merged by dictionary compression

    bugneeds-triagev2.31.0Updated Sep 29, 2026
  • #10688

    [Bug]: compress_chunk fails with "row is too big" when orderby text columns hold wide values

    bugneeds-triagev2.31.0Updated Sep 28, 2026
  • #10691

    [Bug]: Wrong query results after merge_chunks on compressed chunks whose orderby ranges overlap

    bugneeds-triagev2.31.0Updated Sep 28, 2026
  • #10689

    [Bug]: INSERT ... ON CONFLICT DO UPDATE with a repeated key succeeds on a compressed chunk instead of raising SQLSTATE 21000

    bugneeds-triagev2.31.0Updated Sep 28, 2026
  • #10681

    TSDB 2.13 + PostgreSQL 16 : multi-node block

    Updated Sep 28, 2026

> Tags

Canalyticsdatabasefinancial-analysishacktoberfest

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库