41 lines
1.9 KiB
SQL
41 lines
1.9 KiB
SQL
-- ============================================================
|
|
-- Omika Diagnostic Center -- 014_diagnostics_telemetry_retention.sql
|
|
-- Rétention télémétrie : privilège de purge de telemetry_metric_hourly.
|
|
-- ============================================================
|
|
-- TO RUN ON SRV-OMIKA as PostgreSQL superuser (e.g. psql -U postgres -d <base> -f 014_...),
|
|
-- AFTER 003 (rôles) et 001 (table telemetry_metric_hourly).
|
|
--
|
|
-- Guarantees :
|
|
-- - PostgreSQL 18 compatible.
|
|
-- - Idempotent : re-running is a no-op (GRANT is idempotent).
|
|
-- - Non destructive : NO DROP, NO DELETE/TRUNCATE, no data removal.
|
|
-- - NO password, NO secret.
|
|
--
|
|
-- Context : la boucle DiagnosticTelemetryRetentionWorker purge les agrégats horaires
|
|
-- plus anciens que Diagnostics__TelemetryRetentionDays (défaut 180 j = 6 mois), par
|
|
-- LOTS BORNÉS :
|
|
--
|
|
-- DELETE FROM telemetry_metric_hourly
|
|
-- WHERE id IN (
|
|
-- SELECT id FROM telemetry_metric_hourly
|
|
-- WHERE bucket_utc < @cutoff
|
|
-- ORDER BY bucket_utc ASC, id ASC
|
|
-- LIMIT @batchSize
|
|
-- )
|
|
--
|
|
-- Cette requête requiert :
|
|
-- * DELETE sur telemetry_metric_hourly (cible du DELETE) ;
|
|
-- * SELECT sur telemetry_metric_hourly (la sous-requête lit la table).
|
|
--
|
|
-- Jusqu'ici le rôle worker (omika_diagnostics_worker) n'avait AUCUN droit sur cette
|
|
-- table (least privilege, cf. 003). On accorde le MINIMUM pour la rétention :
|
|
-- SELECT + DELETE uniquement. NO UPDATE, NO TRUNCATE, NO DDL, NO INSERT (l'upsert de
|
|
-- télémétrie n'a toujours pas de caller, la table reste non alimentée côté worker).
|
|
-- ============================================================
|
|
|
|
GRANT SELECT, DELETE ON TABLE telemetry_metric_hourly TO omika_diagnostics_worker;
|
|
|
|
-- ============================================================
|
|
-- END 014. Ordre serveur : 001 -> 002 -> 003 -> 004 -> ... -> 013 -> 014.
|
|
-- ============================================================
|