zoukankan      html  css  js  c++  java
  • oracle索引管理脚本

    oracle索引管理脚本

    来自metalink

    --检测某一个索引使用的情况
    select to_char(sn.begin_interval_time, 'yyyy-mm-dd hh24') c1,
           p.search_columns c2,
           count(*) c3
      from dba_hist_snapshot sn, dba_hist_sql_plan p, dba_hist_sqlstat st
     where st.sql_id = p.sql_id
       and sn.snap_id = st.snap_id
       and p.object_name = '&idxname'
     group by sn.begin_interval_time, p.search_columns;
     
     --需要重建的索引
     declare
      c_name         int;
      ignore         int;
      heights        index_stats.height%type := 0;
      lf_rowss       index_stats.lf_rows%type := 0;
      del_lf_rowss   index_stats.del_lf_rows%type := 0;
      distinct_keyss index_stats.distinct_keys%type := 0;
      cursor c_indx is
        select owner, table_name, index_name
          from dba_indexes
         where owner like upper('&schema')
           and owner not in ('SYS', 'SYSTEM');
    BEGIN
      dbms_output.enable(10000000);
      dbms_output.put_line('Owner index name %Deleted Entries Blevel Distinctiveness');
      dbms_output.put_line('-----------------------------------------------------');
      c_name := dbms_sql.open_cursor;
      for r_indx in c_indx loop
        dbms_sql.parse(c_name,
                       'analyze index ' || r_indx.owner || '.' ||
                       r_indx.index_name || ' validate structure',
                       dbms_sql.native);
        ignore := dbms_sql.execute(c_name);
     
        select height,
               decode(lf_rows, 0, 1, lf_rows) lf_rows_status,
               del_lf_rows,
               decode(distinct_keys, 0, 1, distinct_keys) dis_keys_status
          into heights, lf_rowss, del_lf_rowss, distinct_keyss
          from index_stats;
     
        if (heights > 5) or ((del_lf_rowss / lf_rowss) > 0.2) then
          dbms_output.put_line(rpad(r_indx.owner, 16, ' ') ||
                               rpad(r_indx.index_name, 40, ' ') ||
                               lpad(round((del_lf_rowss / lf_rowss) * 100, 3),
                                    17,
                                    ' ') || lpad(heights - 1, 7, '        ') ||
                               lpad(round((lf_rowss - distinct_keyss) * 100 /
                                          lf_rowss,
                                          3),
                                    16,
                                    ' '));
        end if;
     
      end loop;
      dbms_sql.close_cursor(c_name);
    END;
     
     
     
     
     
     
     
     
     
     
     
     

  • 相关阅读:
    阿里云的一道面试题:写一个爬取文档树和通过输入关键字检索爬取的内容的demo
    linux配置SVN,添加用户,配置用户组的各个权限教程
    logback的使用和配置|logback比log4j的优点|logback是一个更好的log4j
    [已解决]mysql查询一周内的数据,解决一周的起始日期是从星期日(星期天|周日|周天)开始的问题
    MySql-----InnoDB记录存储结构-----1
    Mysql----字符集和比较规则
    Mysql-----启动和配置文件-----2(未完,待续)
    MySql----前言有点用----1
    Java高并发--------并行模式和算法(需要看更多的东西,才能总结)---------5
    Java高并发------锁优化及注意事项--------4
  • 原文地址:https://www.cnblogs.com/alang85/p/2162388.html
Copyright © 2011-2022 走看看