Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created April 16, 2013 15:20
Show Gist options
  • Select an option

  • Save sycobuny/5396811 to your computer and use it in GitHub Desktop.

Select an option

Save sycobuny/5396811 to your computer and use it in GitHub Desktop.
Cleaning out old OSSEC alerts
WITH
del_data AS (
DELETE
FROM data
WHERE EXISTS (
SELECT id
FROM alert
WHERE timestamp <= EXTRACT(EPOCH FROM (NOW() - '1 year'::interval))::integer AND
data.id = alert.id
)
RETURNING id
)
DELETE
FROM alert
WHERE EXISTS (
SELECT 1
FROM del_data
WHERE alert.id = del_data.id
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment