Continuous aggregates in TimescaleDB are a kind of hypertable that is refreshed automatically
in the background as new data is added, or old data is modified. Changes to your
dataset are tracked, and the hypertable behind the continuous aggregate is
automatically updated in the background.
Continuous aggregates have a much lower maintenance burden than regular Postgres materialized
views, because the whole view is not created from scratch on each refresh. This
means that you can get on with working your data instead of maintaining your
database.
Because continuous aggregates are based on hypertables, you can query them in exactly the same way as your other tables. This
includes continuous aggregates in the rowstore, compressed into the columnstore,
or tiered to object storage. You can even create continuous aggregates on top of your continuous aggregates,
for an even more fine-tuned aggregation.
Real-time aggregation enables you to combine pre-aggregated data from the materialized view
with the most recent raw data. This gives you up-to-date results on every query.
For more information about using continuous aggregates, see the documentation in Use continuous aggregates.
Samples
Create a continuous aggregate
Create a continuous aggregate that calculates hourly average temperature:Add a refresh policy
Automatically refresh the continuous aggregate to keep it up to date:Manually refresh a continuous aggregate
Refresh a specific time range in the continuous aggregate:Query a continuous aggregate
Query the continuous aggregate just like a regular table:Available functions
Create and modify continuous aggregates
CREATE MATERIALIZED VIEW (Continuous Aggregate): create a continuous aggregate on a hypertable or another continuous aggregateALTER MATERIALIZED VIEW (Continuous Aggregate): change an existing continuous aggregateDROP MATERIALIZED VIEW (Continuous Aggregate): drop a continuous aggregate viewcagg_migrate(): migrate a continuous aggregate from the old format to the new format introduced in TimescaleDB 2.7
Refresh continuous aggregates
refresh_continuous_aggregate(): manually refresh a continuous aggregate
Manage policies
add_continuous_aggregate_policy(): add policy to schedule automatic refresh of a
remove_continuous_aggregate_policy(): remove a refresh policy from a continuous aggregate
Experimental policy management
add_policies(): add refresh, compression, and data retention policies on a continuous aggregatealter_policies(): alter refresh, compression, or data retention policies on a continuous aggregateremove_policies(): remove refresh, compression, or data retention policies from a continuous aggregateremove_all_policies(): remove all policies from a continuous aggregateshow_policies(): show all policies that are currently set on a continuous aggregate