A time-series database for high-performance real-time analytics packaged as a Postgres extension
Install from a Docker container:
Run the TimescaleDB container:
docker run -d --name timescaledb -p 5432:5432 -e POSTGRES_PASSWORD=password timescale/timescaledb:latest-pg17
Connect to a database:
docker exec -it timescaledb psql -d "postgres://postgres:password@localhost/postgres"
See other installation options or try Timescale Cloud for free.
You create a regular table and then convert it into a hypertable. A hypertable automatically partitions data into chunks to accelerate your queries.
-- Create timescaledb extension
CREATE EXTENSION IF NOT EXISTS timescaledb;
-- Create a regular SQL table
CREATE TABLE conditions (
time TIMESTAMPTZ NOT NULL,
location TEXT NOT NULL,
temperature DOUBLE PRECISION NULL,
humidity DOUBLE PRECISION NULL
);
-- Convert the table into a hypertable that is partitioned by time
SELECT create_hypertable('conditions', by_range('time'));
See more:
TimescaleDB’s hypercore is a hybrid row-columnar store that boosts analytical query performance on your time-series and event data, while reducing data size by more than 90%. This keeps your analytics operating at lightning speed and ensures low storage costs as you scale. Data is inserted in row format in the rowstore and converted to columnar format in the columnstore based on your configuration.
Configure the columnstore on a hypertable:
ALTER TABLE conditions SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'location'
);
Create a policy to automatically convert chunks in row format that are older than seven days to chunks in the columnar format:
SELECT add_compression_policy('conditions', INTERVAL '7 days');
See more:
Insert and query data in a hypertable via regular SQL commands. For example:
Insert data into a hypertable named conditions
:
INSERT INTO conditions
VALUES
(NOW(), 'office', 70.0, 50.0),
(NOW(), 'basement', 66.5, 60.0),
(NOW(), 'garage', 77.0, 65.2);
Return the number of entries written to the table conditions in the last 12 hours:
SELECT
COUNT(*)
FROM
conditions
WHERE
time > NOW() - INTERVAL '12 hours';
See more:
Time buckets enable you to aggregate data in hypertables by time interval and calculate summary values.
For example, calculate the average daily temperature in a table named conditions
. The table has a time
and temperature
columns:
SELECT
time_bucket('1 day', time) AS bucket,
AVG(temperature) AS avg_temp
FROM
conditions
GROUP BY
bucket
ORDER BY
bucket ASC;
See more:
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 it.
For example, create a continuous aggregate view for daily weather data in two simple steps:
Create a materialized view:
CREATE MATERIALIZED VIEW conditions_summary_daily
WITH (timescaledb.continuous) AS
SELECT
location,
time_bucket(INTERVAL '1 day', time) AS bucket,
AVG(temperature),
MAX(temperature),
MIN(temperature)
FROM
conditions
GROUP BY
location,
bucket;
Create a policy to refresh the view every hour:
SELECT
add_continuous_aggregate_policy(
'conditions_summary_daily',
start_offset => INTERVAL '1 month',
end_offset => INTERVAL '1 day',
schedule_interval => INTERVAL '1 hour'
);
See more:
Timescale 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, Timescale Cloud allows you to build data-heavy, mission-critical apps while retaining the familiarity and reliability of PostgreSQL.
A Timescale 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:
Linux/macOS | Linux i386 | Windows | Coverity | Code Coverage | OpenSSF |
---|---|---|---|---|---|
We welcome contributions to TimescaleDB! See Contributing and Code style guide for details.
Timescale is PostgreSQL made powerful. To learn more about the company and its products, visit timescale.com.