oracle性能分析2

Oracle性能分析

软件环境:Oracle 11g , 双机RAC.

问题: 

大表(千万级行记录)查询、操作慢,经常超时终端(ORA-01013: 用户请求取消当前的操作)

分析:

1)分区表

2)历史数据归档

解决:

采用方案2)。

  • 创建历史表
create table {tablename}_his as select * from {tablename} where ...
  • 禁用除主键之外的索引
alter index {indexname} unusable;
  • 删除表数据。数据量太大(7444741)无法直接删除(执行半小时无反应中断),需批量删除。(rac环境需要到具体机器上执行)

declare  
   cursor mycursor is SELECT  ROWID FROM {tablename} WHERE ltl_time < to_date('2017-08-01','YYYY-mm-dd') order by rowid;  
   type rowid_table_type is  table  of rowid index by pls_integer;
   v_rowid   rowid_table_type;
BEGIN
   open mycursor;
   loop
     fetch   mycursor bulk collect into v_rowid  limit 5000;   --------每次处理5000行,也就是每5000行一提交
     exit when v_rowid.count=0;
     forall i in v_rowid.first..v_rowid.last
        delete from {tablename} nologging  where rowid=v_rowid(i);
     commit;
   end loop;
   close mycursor;
END;
  • 重建索引
alter index {indexname} rebuild;

 




posted @ 2017-10-26 23:02  疯子峰  阅读(443)  评论(0编辑  收藏  举报