1、收集数据库性能报表
oracle用户登陆
# su - oracle
$ sqlplus '/as sysdba'
在压力测试或者sql测试前
sql> execute dbms_workload_repository.create_snapshot();
测试完成后,再次生成快照
sql> execute dbms_workload_repository.create_snapshot();
如果有了两次生成的快照后,生成报表
sql> @ ?/rdbms/admin/awrrpt.sql;
回车,然后输入一个报表名字,生成html格式的报表文件
2、如何找到消耗资源最多的sql语句
-- 逻辑读多的SQL
select * from (select buffer_gets, sql_text
from v$sqlarea
where buffer_gets > 500000
order by buffer_gets desc) where rownum<=30;
-- 执行次数多的SQL
select sql_text,executions from
(select sql_text,executions from v$sqlarea order by executions desc)
where rownum<81;
-- 读硬盘多的SQL
select sql_text,disk_reads from
(select sql_text,disk_reads from v$sqlarea order by disk_reads desc)
where rownum<21;
--根据操作系统进程找sql语句
根据进程id找sid
select sid from v$session
where paddr in ( select addr from v$process where spid=&pid) ;
根据sid找sql语句
select SQL_TEXT
from V$SQLTEXT
where HASH_VALUE
= ( select SQL_HASH_VALUE from v$session
where sid = &sid)
order by PIECE;