Timescale and TimescaleDB are trademarks of Timescale, Inc.
The Grafana Labs Marks are trademarks of Grafana Labs, and are used with Grafana Labs’ permission. We are not affiliated with, endorsed or sponsored by Grafana Labs or its affiliates.
Who are we
Internal databases
Summary
Basics
Metrics platform
Zabbix
Billing
Version management
Tooling
Conclusion
What’s next
TimescaleDB
An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
select drop_chunks(relation=>'%s',older_than=> now - history_seconds);
Deletes
Big databases
⚠️ migrate_data => true ⚠️
Very slow and heavy
Migration plan
Migration
Migration
Migration
Migration
Migration
Migration
Migration
Disk space
Compression
Configure compression with ALTER TABLE
Grant tables owner the LOGIN privilege
Schedule compression jobs
Configure and start background workers
Disk space
I/O
Versions
Zabbix
TimescaleDB
7.0
2.13.0-2.15.X
6.4
2.1.0-2.15.X
6.0
2.1.0-2.15.X
5.0.10+
1.X, 2.0.1-2.15.X
5.0.0-5.0.9
1.X
Conclusion for Zabbix
Enable TimescaleDB from the beginning
Ensure background workers are started
Fine-tune for i/o bound workload
Install supported versions
Billing
Before cloud computing
Loop over customers
Loop over services
Lookup service price
Create billing line
Create bill
Subscription system
First day of the month
Cloud computing
More elasticity
Resources can be created and deleted
Countless times in a month
Pay for what’s really used
Consumption system
Requirements
Store consumption metrics
Aggregate consumption metrics
Write old data points
Architecture
Mediation
Store raw events
Compute daily aggregates
Events (hypertable)
18,000,000 rows per day
Chunk interval of 1 day
Compress after 6 months
Drop after 7 months
Daily events (continuous aggregate)
CREATE MATERIALIZED VIEW "daily_events" WITH (timescaledb.continuous) AS
SELECT
customer_id, subscription_id, time_bucket('1 day', begin) AS time,
MIN(duration) AS duration_min, MAX(duration) AS duration_max,
AVG(duration) AS duration_avg, SUM(duration) AS duration_sum,
MIN(quantity) AS quantity_min, MAX(quantity) AS quantity_max,
AVG(quantity) AS quantity_avg, SUM(quantity) AS quantity_sum,
SUM(1) AS nb_events
FROM "events"
WHERE quantity > 0
GROUP BY time, customer_id, subscription_id
WITH NO DATA;
Refresh policies
Refresh continuous aggregate
[1 hour, 7 days]
Every hour
Refresh continuous aggregate (via UDF)
[1 hour, 2 months]
Every day
Continuous aggregate
Real-time aggregate
ALTER MATERIALIZED VIEW "daily_events"
SET (timescaledb.materialized_only = false);
Real-time aggregate
Rating
Query “Mediation” aggregation
Create billing lines (“ratings”)
122,000,000 rows in hot table
Uncompressed
3,400,000,000 rows in archive table
Compressed after 3 days
Chunk interval of 1 day
Retention of 7 months
Schema migrations
Let’s add a simple “id” column
alter table massive_archive
add column id bigserial not null;
❌
ERROR: cannot add column with non-constant default expression to a hypertable that has compression
enabled
Try again
Decompress chunks
Add the column
Compress chunks
❌
Disk full
Try again
Create a second hypertable
For each chunk (oldest to newest)
Copy rows
Compress chunk
Swap hypertables
Drop unused hypertables
Compression tips
Do not segment by very high cardinality values
Do not segment by very low cardinality values
~1000 tuples per batchs
Compression example
Time
ID
Subscription
Quantity
2024-09-04 00:00:00Z
1
1
10
2024-09-04 00:00:00Z
2
2
20
2024-09-04 01:00:00Z
3
1
10
2024-09-04 01:00:00Z
4
2
30
Segment by ID
Very high cardinality
Time
ID
Subscription
Quantity
[2024-09-04 00:00:00Z]
[1]
[1]
[10]
[2024-09-04 00:00:00Z]
[2]
[2]
[20]
[2024-09-04 01:00:00Z]
[3]
[1]
[10]
[2024-09-04 01:00:00Z]
[4]
[2]
[30]
Segment by subscription
Natural compression
Time
ID
Subscription
Quantity
[2024-09-04 00:00:00Z,2024-09-04 01:00:00Z]
[1,3]
[1,1]
[10,10]
[2024-09-04 00:00:00Z,2024-09-04 01:00:00Z]
[2,4]
[2,2]
[20,30]
Conclusion for Billing
No more load the first day of the month
Easier to predict the amount of next bill
Version management
TimescaleDB is in active development
Lots of performance improvements on continuous aggregates