1. 数据库历史数据清理
#创建历史表
create table ag_alert_record_history asselect * from ag_alert_record;
select * from ag_alert_record wheremessage_time between sysdate-90 and sysdate order by message_time desc;
#删除ag_alert_record中90天之前的数据
delete from ag_alert_record where message_time >= trunc(sysdate-20) and message_time <trunc(sysdate-10);
--delete from ag_alert_record wheremessage_time <= sysdate-365;
#job启动,job第1天同步前1天的数据到历史表中
##1. 创建存储过程
create or replace procedureag_alert_record_synchronous as
begin
insert intoag_alert_record_history
(mon_id,message_time,send_time,sender,worker_id,status,response_time,handle_time,handle_user,rule_id,node_no,assembled_mon_id,focus_title)
select
t.mon_id,t.message_time,t.send_time,t.sender,t.worker_id,t.status,t.response_time,t.handle_time,t.handle_user,t.rule_id,t.node_no,t.assembled_mon_id,t.focus_titlefrom ag_alert_record t
wheret.message_time >= trunc(sysdate-1) and t.message_time < trunc(sysdate)order by t.message_time desc;
delete from ag_alert_record wheremessage_time <= sysdate-365;
end;
##2. 创建job,第一次在凌晨12点执行,以后每隔1天处理一次
declare job1 number;
begin
dbms_job.submit(job1,
what => 'wscde.ag_alert_record_synchronous;',
next_date=> to_date('2017-02-23 00:59:59', 'YYYY-MM-DD HH24:MI:SS'),
interval=> 'sysdate+1');
commit;
end;
##3. 查询job生成的id
select job,broken,what,interval,t.* fromuser_jobs t;
##4.启动job
begin
dbms_job.run(24); --jod id
end;
2. MVC前端历史数据查询修改
2.1 删除目前ag_alert_records表数据,不会造成原来逻辑改动,页面控制
2.2 新增历史数据查询页面功能,或,实现查询时间实时表与历史表数据拼接返回结果
3. ag_alert_records_history 保存1年记录,一年前的数据导出入文档备份,若未来需要审计,则通过恢复备份数据实现
具体方案:
1. 导出ag_alert_records_history为归档文件,保存
2. 清理ag_alert_records_history 一年前的数据
3. 每隔一年人工备份一次一年前的数据
其中涉及赋权的sql语句如下:
grant execute onag_alert_record_synchronous to wsjob;
grant ALL on AG_ALERT_RECORD_SYNCHRONOUS to wsjob;