24 lines
865 B
PL/PgSQL
24 lines
865 B
PL/PgSQL
CREATE OR REPLACE FUNCTION fr24.drop_raw_partitions_older_than(retention_days INTEGER)
|
|
RETURNS void
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
partition_record RECORD;
|
|
cutoff_date DATE := CURRENT_DATE - retention_days;
|
|
BEGIN
|
|
FOR partition_record IN
|
|
SELECT inhrelid::regclass::text AS partition_name
|
|
FROM pg_inherits
|
|
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
|
|
WHERE parent.relname = 'raw_packets'
|
|
AND parent.relnamespace = 'fr24'::regnamespace
|
|
LOOP
|
|
IF partition_record.partition_name <> 'fr24.raw_packets_default' THEN
|
|
EXECUTE format('ALTER TABLE %s DETACH PARTITION %s', 'fr24.raw_packets', partition_record.partition_name);
|
|
END IF;
|
|
END LOOP;
|
|
END;
|
|
$$;
|
|
|
|
COMMENT ON FUNCTION fr24.drop_raw_partitions_older_than(INTEGER) IS 'Retention helper placeholder; actual cleanup is driven by monitoring/preprocess scheduler.';
|