oracle性能分析

Oracle性能分析

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

问题:sql语句(单表单条件order_id查询)执行缓慢 >5s。

分析:

PL/SQL中执行F5,可以看到是全表扫描:TABLE ACCESS FULL.

查看表记录行数:10470628

解决:

创建索引后PL/SQL执行时间<0.2s

create index {IndexName} on {Tablename}( {Column} );

扩展:

查询系统中的大表

存储空间可以用如下语句查:
select df.tablespace_name "表空间名",
       totalspace "总空间M",
       freespace "剩余空间M",
       round((1 - freespace / totalspace) * 100, 2) "使用率%"
  from (select tablespace_name, round(sum(bytes) / 1024 / 1024) totalspace
          from dba_data_files
         group by tablespace_name) df,
       (select tablespace_name, round(sum(bytes) / 1024 / 1024) freespace
          from dba_free_space
         group by tablespace_name) fs
 where df.tablespace_name = fs.tablespace_name;

查记录条数可以用如下语句:
select table_name,num_rows,t.owner from dba_tables t where num_rows > 0 and t.owner <> 'SYS'   order by num_rows desc;
posted @ 2017-10-26 00:00  疯子峰  阅读(963)  评论(0编辑  收藏  举报