Convert Figma logo to code with AI

timescale logotimescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.

17,420
872
17,420
570

Top Related Projects

28,575

Scalable datastore for metrics, events, and real-time analytics

13,388

Apache Druid: a high performance real-time analytics database.

The Prometheus monitoring system and time series database.

14,292

QuestDB is an open source time-series database for fast ingest and SQL queries

ClickHouse® is a real-time analytics DBMS

5,385

Apache Pinot - A realtime distributed OLAP datastore

Quick Overview

TimescaleDB is an open-source database designed to make SQL scalable for time-series data. It is implemented as an extension to PostgreSQL, providing automatic partitioning across time and space, as well as full SQL support. TimescaleDB is optimized for fast ingest and complex queries, making it ideal for IoT, financial data, and monitoring applications.

Pros

  • Seamless integration with PostgreSQL, leveraging its robust ecosystem and features
  • Automatic time-based partitioning for improved query performance and data management
  • Supports both time-series and relational workloads in a single database
  • Offers advanced features like continuous aggregates, data retention policies, and compression

Cons

  • Requires PostgreSQL as a base system, which may not be suitable for all use cases
  • Learning curve for users not familiar with PostgreSQL or time-series databases
  • Performance may not match specialized time-series databases in certain scenarios
  • Limited support for distributed deployments compared to some other time-series solutions

Code Examples

  1. Creating a hypertable:
CREATE TABLE sensor_data (
  time        TIMESTAMPTZ       NOT NULL,
  sensor_id   INTEGER           NOT NULL,
  temperature DOUBLE PRECISION  NULL,
  humidity    DOUBLE PRECISION  NULL
);

SELECT create_hypertable('sensor_data', 'time');
  1. Inserting data into a hypertable:
INSERT INTO sensor_data (time, sensor_id, temperature, humidity)
VALUES (NOW(), 1, 25.6, 47.3),
       (NOW() - INTERVAL '1 hour', 2, 23.4, 51.2);
  1. Querying time-series data with time bucketing:
SELECT time_bucket('1 hour', time) AS hour,
       AVG(temperature) AS avg_temp,
       AVG(humidity) AS avg_humidity
FROM sensor_data
WHERE time > NOW() - INTERVAL '24 hours'
GROUP BY hour
ORDER BY hour;

Getting Started

To get started with TimescaleDB:

  1. Install PostgreSQL and TimescaleDB extension (follow instructions on the official website).
  2. Create a new database and enable the extension:
CREATE DATABASE timeseries_db;
\c timeseries_db
CREATE EXTENSION IF NOT EXISTS timescaledb;
  1. Create a table and convert it to a hypertable:
CREATE TABLE metrics (
  time TIMESTAMPTZ NOT NULL,
  device_id INTEGER,
  value DOUBLE PRECISION
);

SELECT create_hypertable('metrics', 'time');
  1. Start inserting and querying data using standard SQL commands.

Competitor Comparisons

28,575

Scalable datastore for metrics, events, and real-time analytics

Pros of InfluxDB

  • Purpose-built for time-series data, offering optimized performance for time-based queries
  • Flexible data model with tags and fields, allowing for efficient storage and querying of high-cardinality data
  • Built-in data retention policies and continuous queries for automated data management

Cons of InfluxDB

  • Limited support for complex joins and relational queries compared to TimescaleDB's SQL capabilities
  • Lacks some advanced PostgreSQL features that TimescaleDB inherits, such as full ACID compliance and rich indexing options

Code Comparison

InfluxDB query example:

SELECT mean("value") FROM "cpu_usage"
WHERE "host" = 'server01' AND time >= now() - 1h
GROUP BY time(5m)

TimescaleDB query example:

SELECT time_bucket('5 minutes', time) AS five_min,
       avg(value) AS mean_value
FROM cpu_usage
WHERE host = 'server01' AND time >= now() - interval '1 hour'
GROUP BY five_min
ORDER BY five_min;

Both databases offer efficient time-series querying, but TimescaleDB uses standard SQL syntax, while InfluxDB uses its own query language (InfluxQL or Flux). TimescaleDB's SQL approach may be more familiar to developers with relational database experience.

13,388

Apache Druid: a high performance real-time analytics database.

Pros of Druid

  • Designed for real-time analytics on large-scale streaming data
  • Highly scalable and distributed architecture
  • Supports complex aggregations and fast ad-hoc queries

Cons of Druid

  • Steeper learning curve and more complex setup
  • Limited support for updating or deleting existing data
  • Higher resource requirements for smaller datasets

Code Comparison

Druid Query Example

SELECT COUNT(*) AS count,
       SUM(price) AS total_price
FROM transactions
WHERE timestamp >= CURRENT_TIMESTAMP - INTERVAL '1' DAY
GROUP BY product_id
HAVING COUNT(*) > 100

TimescaleDB Query Example

SELECT COUNT(*) AS count,
       SUM(price) AS total_price
FROM transactions
WHERE time > NOW() - INTERVAL '1 day'
GROUP BY product_id
HAVING COUNT(*) > 100

Both Druid and TimescaleDB are designed for time-series data, but they have different strengths. Druid excels in real-time analytics and scalability for large datasets, while TimescaleDB offers better SQL compatibility and easier integration with existing PostgreSQL ecosystems. The code examples show similar query syntax, with minor differences in time-related functions and column naming conventions.

The Prometheus monitoring system and time series database.

Pros of Prometheus

  • Built-in alerting and monitoring system with a powerful query language (PromQL)
  • Native support for multi-dimensional data and time series
  • Extensive ecosystem with various exporters and integrations

Cons of Prometheus

  • Limited long-term storage capabilities
  • Lacks built-in downsampling and data retention policies
  • Scaling horizontally can be challenging

Code Comparison

TimescaleDB (SQL query):

SELECT time_bucket('1 hour', time) AS hour,
       avg(temperature) AS avg_temp
FROM sensor_data
WHERE time > NOW() - INTERVAL '1 day'
GROUP BY hour
ORDER BY hour;

Prometheus (PromQL query):

avg_over_time(temperature[1h])

Additional Notes

TimescaleDB is an extension of PostgreSQL, offering advanced time-series capabilities while maintaining full SQL compatibility. It excels in handling large volumes of time-series data with efficient storage and querying.

Prometheus, on the other hand, is a complete monitoring and alerting toolkit designed for reliability and scalability in dynamic environments. It's particularly well-suited for microservices architectures and cloud-native applications.

While both handle time-series data, they serve different primary purposes: TimescaleDB as a database solution and Prometheus as a monitoring system. The choice between them depends on specific use cases and requirements.

14,292

QuestDB is an open source time-series database for fast ingest and SQL queries

Pros of QuestDB

  • Designed for high-performance time-series data processing with zero dependencies
  • Supports SQL with extensions for time-series operations
  • Offers out-of-the-box web console for data exploration and visualization

Cons of QuestDB

  • Smaller ecosystem and community compared to TimescaleDB
  • Limited advanced features like continuous aggregates and data retention policies
  • Less mature and battle-tested in production environments

Code Comparison

QuestDB SQL query:

SELECT date_trunc('hour', timestamp) AS hour,
       avg(temperature) AS avg_temp
FROM sensors
WHERE location = 'NYC'
GROUP BY hour
ORDER BY hour DESC
LIMIT 24;

TimescaleDB SQL query:

SELECT time_bucket('1 hour', timestamp) AS hour,
       avg(temperature) AS avg_temp
FROM sensors
WHERE location = 'NYC'
GROUP BY hour
ORDER BY hour DESC
LIMIT 24;

Both databases support SQL queries for time-series data, with slight differences in function names (e.g., date_trunc vs time_bucket). TimescaleDB leverages PostgreSQL's ecosystem, while QuestDB focuses on a lightweight, high-performance approach for time-series data.

ClickHouse® is a real-time analytics DBMS

Pros of ClickHouse

  • Exceptional performance for analytical queries on large datasets
  • Highly scalable and distributed architecture
  • Supports a wide range of data types and storage engines

Cons of ClickHouse

  • Steeper learning curve due to its unique query language and architecture
  • Limited support for real-time updates and deletes
  • Less suitable for OLTP workloads compared to TimescaleDB

Code Comparison

ClickHouse query example:

SELECT date, count() AS count
FROM events
GROUP BY date
ORDER BY date

TimescaleDB query example:

SELECT time_bucket('1 day', time) AS date, count(*)
FROM events
GROUP BY date
ORDER BY date

Both examples show a simple time-based aggregation query. ClickHouse uses its native syntax, while TimescaleDB extends PostgreSQL with time-bucket functions.

ClickHouse is optimized for analytical queries on large datasets, offering superior performance for complex aggregations. TimescaleDB, built on PostgreSQL, provides a more familiar SQL interface and better support for real-time updates and OLTP workloads.

Choose ClickHouse for high-performance analytics on massive datasets, and TimescaleDB for a balance between time-series capabilities and traditional relational database features.

5,385

Apache Pinot - A realtime distributed OLAP datastore

Pros of Pinot

  • Designed for real-time analytics with low latency querying on large datasets
  • Supports multiple data ingestion methods, including streaming and batch
  • Highly scalable and distributed architecture for handling massive data volumes

Cons of Pinot

  • Steeper learning curve and more complex setup compared to TimescaleDB
  • Requires more resources and infrastructure to run effectively
  • Less mature ecosystem and fewer integrations with existing tools

Code Comparison

TimescaleDB (SQL-based):

CREATE TABLE metrics (
  time TIMESTAMPTZ NOT NULL,
  device_id INTEGER,
  temperature FLOAT,
  cpu_usage FLOAT
);

SELECT time_bucket('1 hour', time) AS hour,
       AVG(temperature) AS avg_temp
FROM metrics
WHERE time > NOW() - INTERVAL '24 hours'
GROUP BY hour
ORDER BY hour;

Pinot (PQL-based):

SELECT DATETIMECONVERT(ts, '1:MILLISECONDS:EPOCH', '1:HOURS:EPOCH', '1:HOURS') AS hour,
       AVG(temperature) AS avg_temp
FROM metrics
WHERE ts > FromDateTime(now(), 'yyyy-MM-dd HH:mm:ss') - 24 * 3600 * 1000
GROUP BY hour
ORDER BY hour
LIMIT 10000

Both TimescaleDB and Pinot offer powerful solutions for time-series data, with TimescaleDB providing a more familiar PostgreSQL-based approach and Pinot focusing on real-time analytics at scale.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Linux/macOSLinux i386WindowsCoverityCode CoverageOpenSSF
Build Status Linux/macOSBuild Status Linux i386Windows build statusCoverity Scan Build StatusCode CoverageOpenSSF Best Practices

TimescaleDB

TimescaleDB is an open-source database designed to make SQL scalable for time-series data. It is engineered up from PostgreSQL and packaged as a PostgreSQL extension, providing automatic partitioning across time and space (partitioning key), as well as full SQL support.

If you prefer not to install or administer your instance of TimescaleDB, try the 30 day free trial of Timescale, our fully managed cloud offering. Timescale is pay-as-you-go. We don't charge for storage you dont use, backups, snapshots, ingress or egress.

To determine which option is best for you, see Timescale Products for more information about our Apache-2 version, TimescaleDB Community (self-hosted), and Timescale Cloud (hosted), including: feature comparisons, FAQ, documentation, and support.

Below is an introduction to TimescaleDB. For more information, please check out these other resources:

For reference and clarity, all code files in this repository reference licensing in their header (either the Apache-2-open-source license or Timescale License (TSL) ). Apache-2 licensed binaries can be built by passing -DAPACHE_ONLY=1 to bootstrap.

Contributors welcome.

(To build TimescaleDB from source, see instructions in Building from source.)

Using TimescaleDB

TimescaleDB scales PostgreSQL for time-series data via automatic partitioning across time and space (partitioning key), yet retains the standard PostgreSQL interface.

In other words, TimescaleDB exposes what look like regular tables, but are actually only an abstraction (or a virtual view) of many individual tables comprising the actual data. This single-table view, which we call a hypertable, is comprised of many chunks, which are created by partitioning the hypertable's data in either one or two dimensions: by a time interval, and by an (optional) "partition key" such as device id, location, user id, etc.

Virtually all user interactions with TimescaleDB are with hypertables. Creating tables and indexes, altering tables, inserting data, selecting data, etc., can (and should) all be executed on the hypertable.

From the perspective of both use and management, TimescaleDB just looks and feels like PostgreSQL, and can be managed and queried as such.

Before you start

PostgreSQL's out-of-the-box settings are typically too conservative for modern servers and TimescaleDB. You should make sure your postgresql.conf settings are tuned, either by using timescaledb-tune or doing it manually.

Creating a hypertable

-- Do not forget to create timescaledb extension
CREATE EXTENSION timescaledb;

-- We start by creating a regular SQL table
CREATE TABLE conditions (
  time        TIMESTAMPTZ       NOT NULL,
  location    TEXT              NOT NULL,
  temperature DOUBLE PRECISION  NULL,
  humidity    DOUBLE PRECISION  NULL
);

-- Then we convert it into a hypertable that is partitioned by time
SELECT create_hypertable('conditions', 'time');

Inserting and querying data

Inserting data into the hypertable is done via normal SQL commands:

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

SELECT * FROM conditions ORDER BY time DESC LIMIT 100;

SELECT time_bucket('15 minutes', time) AS fifteen_min,
    location, COUNT(*),
    MAX(temperature) AS max_temp,
    MAX(humidity) AS max_hum
  FROM conditions
  WHERE time > NOW() - interval '3 hours'
  GROUP BY fifteen_min, location
  ORDER BY fifteen_min DESC, max_temp DESC;

In addition, TimescaleDB includes additional functions for time-series analysis that are not present in vanilla PostgreSQL. (For example, the time_bucket function above.)

Installation

Timescale, a fully managed TimescaleDB in the cloud, is available via a free trial. Create a PostgreSQL database in the cloud with TimescaleDB pre-installed so you can power your application with TimescaleDB without the management overhead.

TimescaleDB is also available pre-packaged for several platforms such as Linux, Windows, MacOS, Docker, and Kubernetes. For more information, see Install TimescaleDB.

To build from source, see Building from source.

Resources

Architecture documents

Useful tools

  • timescaledb-tune: Helps set your PostgreSQL configuration settings based on your system's resources.
  • timescaledb-parallel-copy: Parallelize your initial bulk loading by using PostgreSQL's COPY across multiple workers.

Additional documentation

Community & help

Releases & updates

Contributing