From 97229b91d1a15f0e6f5dca686656c629f19e8a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sun, 22 Nov 2026 09:50:12 +0100 Subject: [PATCH] feat(db): compress aggregates, bound daily retention and disable telemetry The hourly and daily aggregates are compressed after 30 and 180 days and the daily aggregate is no longer kept forever. TimescaleDB telemetry is turned off for the database, as self-hosted installations must not report to third parties. Refs #63 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- .../migrations/sql/00022_data_lifecycle.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 internal/migrations/sql/00022_data_lifecycle.sql diff --git a/internal/migrations/sql/00022_data_lifecycle.sql b/internal/migrations/sql/00022_data_lifecycle.sql new file mode 100644 index 0000000..399d9f0 --- /dev/null +++ b/internal/migrations/sql/00022_data_lifecycle.sql @@ -0,0 +1,33 @@ +-- +goose Up +-- TimescaleDB reports usage to its vendor by default. Self-hosted +-- installations must not phone home, so it is switched off for this +-- database; the setting applies to new connections and background jobs. +-- +goose StatementBegin +DO $$ +BEGIN + EXECUTE format('ALTER DATABASE %I SET timescaledb.telemetry_level = off', current_database()); +END +$$; +-- +goose StatementEnd + +-- Aggregates are compressed once they are past their refresh window. +ALTER MATERIALIZED VIEW check_results_1h SET (timescaledb.compress = true); +SELECT add_compression_policy('check_results_1h', compress_after => INTERVAL '30 days'); +ALTER MATERIALIZED VIEW check_results_1d SET (timescaledb.compress = true); +SELECT add_compression_policy('check_results_1d', compress_after => INTERVAL '180 days'); + +-- The daily aggregate was kept forever, including data of deleted monitors. +-- The API adjusts all retention periods to its configuration at start. +SELECT add_retention_policy('check_results_1d', INTERVAL '1095 days'); + +-- +goose Down +SELECT remove_retention_policy('check_results_1d', if_exists => true); +SELECT remove_compression_policy('check_results_1d', if_exists => true); +SELECT remove_compression_policy('check_results_1h', if_exists => true); +-- +goose StatementBegin +DO $$ +BEGIN + EXECUTE format('ALTER DATABASE %I RESET timescaledb.telemetry_level', current_database()); +END +$$; +-- +goose StatementEnd