Skip to content

Commit

Permalink
add old data scripts for mysql; uppercase SQL words in other files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Ivanov committed Apr 28, 2014
1 parent 704524a commit 1413819
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 23 deletions.
16 changes: 16 additions & 0 deletions check-old-data.my.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- intervals in days
SET @history_interval = 7;
SET @trends_interval = 90;

SELECT count(alertid) AS alerts FROM alerts WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(acknowledgeid) AS acknowledges FROM acknowledges WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(eventid) AS events FROM events WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);

SELECT count(itemid) AS history FROM history WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(itemid) AS history_uint FROM history_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(itemid) AS history_str FROM history_str WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(itemid) AS history_text FROM history_text WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(itemid) AS history_log FROM history_log WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);

SELECT count(itemid) AS trends FROM trends WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
SELECT count(itemid) AS trends_uint FROM trends_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
22 changes: 11 additions & 11 deletions check-old-data.pg.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
-- keep 1 week of history and 3 months of trends
-- intevals in days
\set history_interval 7
\set trends_interval 90

SELECT count(alertid) AS alerts FROM alerts where age(to_timestamp(alerts.clock)) > (:history_interval * interval '1 day');
SELECT count(alertid) AS alerts FROM alerts WHERE age(to_timestamp(alerts.clock)) > (:history_interval * interval '1 day');

SELECT count(acknowledgeid) AS acknowledges FROM acknowledges where age(to_timestamp(acknowledges.clock)) > (:history_interval * interval '1 day');
SELECT count(acknowledgeid) AS acknowledges FROM acknowledges WHERE age(to_timestamp(acknowledges.clock)) > (:history_interval * interval '1 day');

SELECT count(eventid) AS events FROM events where age(to_timestamp(events.clock)) > (:history_interval * interval '1 day');
SELECT count(eventid) AS events FROM events WHERE age(to_timestamp(events.clock)) > (:history_interval * interval '1 day');

SELECT count(itemid) AS history FROM history where age(to_timestamp(history.clock)) > (:history_interval * interval '1 day');
SELECT count(itemid) AS history_uint FROM history_uint where age(to_timestamp(history_uint.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history_str FROM history_str where age(to_timestamp(history_str.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history_text FROM history_text where age(to_timestamp(history_text.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history_log FROM history_log where age(to_timestamp(history_log.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history FROM history WHERE age(to_timestamp(history.clock)) > (:history_interval * interval '1 day');
SELECT count(itemid) AS history_uint FROM history_uint WHERE age(to_timestamp(history_uint.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history_str FROM history_str WHERE age(to_timestamp(history_str.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history_text FROM history_text WHERE age(to_timestamp(history_text.clock)) > (:history_interval * interval '1 day') ;
SELECT count(itemid) AS history_log FROM history_log WHERE age(to_timestamp(history_log.clock)) > (:history_interval * interval '1 day') ;

SELECT count(itemid) AS trends FROM trends where age(to_timestamp(trends.clock)) > (:trends_interval * interval '1 day');
SELECT count(itemid) AS trends_uint FROM trends_uint where age(to_timestamp(trends_uint.clock)) > (:trends_interval * interval '1 day') ;
SELECT count(itemid) AS trends FROM trends WHERE age(to_timestamp(trends.clock)) > (:trends_interval * interval '1 day');
SELECT count(itemid) AS trends_uint FROM trends_uint WHERE age(to_timestamp(trends_uint.clock)) > (:trends_interval * interval '1 day') ;
16 changes: 16 additions & 0 deletions delete-old-data.my.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- intervals in days
SET @history_interval = 7;
SET @trends_interval = 90;

DELETE FROM alerts WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
SELECT count(acknowledgeid) AS acknowledges FROM acknowledges WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
DELETE FROM events WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);

DELETE FROM history WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
DELETE FROM history_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
DELETE FROM history_str WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
DELETE FROM history_text WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
DELETE FROM history_log WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);

DELETE FROM trends WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
DELETE FROM trends_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
14 changes: 7 additions & 7 deletions delete-unused-data.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
delete from history where itemid not in (select itemid from items where status='0');
delete from history_uint where itemid not in (select itemid from items where status='0');
delete from history_str where itemid not in (select itemid from items where status='0');
delete from history_text where itemid not in (select itemid from items where status='0');
delete from history_log where itemid not in (select itemid from items where status='0');
DELETE FROM history WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');
DELETE FROM history_uint WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');
DELETE FROM history_str WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');
DELETE FROM history_text WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');
DELETE FROM history_log WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');

delete from trends where itemid not in (select itemid from items where status='0');
delete from trends_uint where itemid not in (select itemid from items where status='0');
DELETE FROM trends WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');
DELETE FROM trends_uint WHERE itemid NOT IN (SELECT itemid FROM items WHERE status='0');
5 changes: 2 additions & 3 deletions stop-and-delete-email-alerts.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
truncate alerts;
truncate escalations;

TRUNCATE alerts;
TRUNCATE escalations;
4 changes: 2 additions & 2 deletions stop-email-alerts.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
update alerts set status=2,error='' where status=0 and alerttype=0;
truncate escalations;
UPDATE alerts SET status=2,error='' WHERE status=0 AND alerttype=0;
TRUNCATE escalations;

0 comments on commit 1413819

Please sign in to comment.