timescaledb: Time-Series data
timescaledb is a PostgreSQL extension designed for improved handling of time-series data. It provides a scalable, high-performance solution for storing and querying time-series data on top of a standard PostgreSQL database.
timescaledb
uses a time-series-aware storage model and indexing techniques to improve performance of PostgreSQL in working with time-series data. The extension divides data into chunks based on time intervals, allowing it to scale efficiently, especially for large data sets. The data is then compressed, optimized for write-heavy workloads, and partitioned for parallel processing. timescaledb
also includes a set of functions, operators, and indexes that work with time-series data to reduce query times, and make data easier to work with.
Enable the extension
- Go to the Database page in the Dashboard.
- Click on Extensions in the sidebar.
- Search for "timescaledb" and enable the extension.
Usage
To demonstrate how timescaledb
works, let's consider a simple example where we have a table that stores temperature data from different sensors. We will create a table named "temperatures" and store data for two sensors.
First we create a hypertable, which is a virtual table that is partitioned into chunks based on time intervals. The hypertable acts as a proxy for the actual table and makes it easy to query and manage time-series data.
Next, we can populate some values
And finally we can query the table using timescaledb
's time_bucket
function to divide the time-series into intervals of the specified size (in this case, 1 hour) averaging the temperature
reading within each group.
Resources
- Official
timescaledb
documentation