OA系统冗余数据过多,访问效率受到影响,现需要对历史数据进行一次清理,以提高OA访问速度
大的数据主要体现在流程上,流程数据主要放在flow_run,flow_run_data,flow_run_prcs,flow_run_feedback表中,清理一年半以前的数据是比较合理的。run_id是主键而run_id随着时间的增加而变大,run_id小于50W的流程刚好是一年半以前的历史数据,选择run_id小于50W作为临界点进行删除。以下是清理数据的计划
思路:
①创建和flow_run_data、flow_run、flow_run_prcs、flow_run_feedback、notify表结构一致的表
②把需要清理的历史数据插入刚创建的备份表中
③删除正式表中的数据
操作:
1.晚上10点以后停止mysql数据库服务,前端web服务(避免有人继续访问)
2.备份td_oa数据库
3.依次执行以下SQL语句:
4.开启web和mysql服务,验证是否成功
//对flow_run的操作
create table flow_run_old like flow_run;
insert into flow_run_old select * from flow_run where run_id < '500000';
delete from flow_run where run_id < '500000';
//对flow_run_data的操作
create table flow_run_data_old like flow_run_data;
insert flow_run_data_old select * from flow_run_data where run_id < '500000'
delete from flow_run_data where run_id < '500000';
//对flow_run_prcs操作
create table flow_run_prcs_old like flow_run_prcs;
insert into flow_run_prcs_old select * from flow_run_prcs where run_id < '500000'
delete from flow_run_prcs where run_id < '500000';
select count(*) from flow_run_prcs_old
//对flow_run_feedback操作
create table flow_run_feedback_old like flow_run_feedback;
insert into flow_run_feedback_old select * from flow_run_feedback where run_id < '500000'
delete from flow_run_feedback where run_id < '500000';
//公告notify_id<3349是2013年以前的数据,从该时刻开始删除
create table notify_old like notify;
insert into notify_old select * from notify where notify_id < '3349';
delete from notify where notify_id < '3349';
//删除一年以前的系统日志sys_log、流程日志FLOW_RUN_LOG、SMS、SMS_BODY、UC_PMS、
delete from sys_log where time //对流程日志的操作 create table flow_run_log_old like flow_run_log; insert into flow_run_log_old select * from flow_run_log where run_id < '500000'; delete from flow_run_log where run_id < '500000'; ============================================================================================================= //会议室申请 create table meeting_old like meeting; insert into meeting_old select * from meeting where m_request_time < '2013-06-01 00:00:00'; delete from meeting where m_request_time < '2013-06-01 00:00:00'; //车辆申请 create table vehicle_usage_old like vehicle_usage; insert into vehicle_usage_old select * from vehicle_usage where vu_request_date < '2013-06-01 00:00:00'; delete from vehicle_usage where vu_request_date < '2013-06-01 00:00:00'; ============================================================================================================= //在线考试信息清理主要是exam_flow和exam_data两张表,这两张表是通过flow_id关联,清理2012-06-01以前的数据,flow_id<4212 //考试发布表exam_flow create table exam_flow_old like exam_flow; insert into exam_flow_old select * from exam_flow where flow_id<'4212'; delete from exam_flow where flow_id<'4212'; //考试信息表exam_data create table exam_data_old like exam_data; insert into exam_data_old select * from exam_data where flow_id<'4212'; delete from exam_data where flow_id<'4212';