40 lines
1.7 KiB
SQL
40 lines
1.7 KiB
SQL
-- ============================================================
|
|
-- Omika Diagnostic Center -- 004_diagnostics_retention.sql (Phase 5C.2C)
|
|
-- PostgreSQL : moindre privilège pour la rétention diagnostic.
|
|
-- ============================================================
|
|
-- TO RUN ON SRV-OMIKA as PostgreSQL superuser (e.g. psql -U postgres).
|
|
-- DO NOT run from the development PC.
|
|
--
|
|
-- Guarantees :
|
|
-- - PostgreSQL 18 compatible.
|
|
-- - Idempotent : re-running is a no-op (GRANT is idempotent).
|
|
-- - Non destructive : NO DROP, NO DELETE/TRUNCATE, NO role/object removal.
|
|
-- - NO password, NO secret.
|
|
--
|
|
-- Context (Phase 5C.2C) : the retention loop (DiagnosticRetentionWorker) purges
|
|
-- diagnostic_event by BOUNDED batches :
|
|
--
|
|
-- DELETE FROM diagnostic_event
|
|
-- WHERE id IN (
|
|
-- SELECT id FROM diagnostic_event
|
|
-- WHERE timestamp_utc < @cutoff
|
|
-- ORDER BY timestamp_utc ASC, id ASC
|
|
-- LIMIT @batchSize
|
|
-- )
|
|
--
|
|
-- This SQL requires :
|
|
-- * DELETE on diagnostic_event (the target of the DELETE) ;
|
|
-- * SELECT on diagnostic_event (the sub-query reads the table).
|
|
--
|
|
-- The worker role (omika_diagnostics_worker) currently holds only INSERT +
|
|
-- USAGE sequence (see 003). Least privilege : grant ONLY SELECT + DELETE.
|
|
-- NO UPDATE, NO TRUNCATE, NO DDL, NO privilege on telemetry_metric_hourly.
|
|
-- ============================================================
|
|
|
|
GRANT SELECT, DELETE ON TABLE diagnostic_event TO omika_diagnostics_worker;
|
|
|
|
-- ============================================================
|
|
-- END 004. Apply order on server : 001 -> 002 -> 003 -> 004.
|
|
-- No server action is performed by the development PC.
|
|
-- ============================================================
|