本人遇到过以下情况
情况一: 版本发布后,因一条查询语句导致系统资源溢出引起系统慢
情况二: 查询语句缺少主键条件,系统单据渐渐多后出现系统慢
情况三: 查询语句因缺少索引起慢
情况四: 客户环境少索引
可使用下列语句或OraclAWR报表分析系统执行慢的SQL语句.
解决方案 :
1.通过优化语句解决系统慢问题
2.检查索引是否存在3.停用没必要的外键
查询执行慢的SQL语句
--按session_id查询执行的脚本
select distinct sql_id from v$active_session_history a where SESSION_ID=1531 select SQL_FULLTEXT from v$sql a where sql_id in ('9camzykvv9w57')
--查询执行慢的脚本
select sa.sql_id, sa.sql_text, --sa.sql_fulltext, sa.executions "执行次数", round(sa.elapsed_time / 1000000, 2) "总执行时间", round(sa.elapsed_time / 1000000 / sa.executions, 2) "平均执行时间", sa.command_type, sa.parsing_user_id "用户id", u.username "用户名", sa.hash_value from v$sqlarea sa left join all_users u on sa.parsing_user_id = u.user_id where sa.executions > 0 order by (sa.elapsed_time / sa.executions) desc
--查询当前执行的sql
SELECT b.sql_text, --content of SQL a.machine, --which machine run this code a.username, a.module, -- the method to run this SQL c.sofar / totalwork * 100, --conplete percent c.elapsed_seconds, --run time c.time_remaining --remain to run time FROM v$session a, v$sqlarea b, v$session_longops c WHERE a.sql_hash_value = b.hash_value(+) AND a.SID = c.SID(+) AND a.serial# = c.serial#(+) and b.sql_text is not null and a.username='CVNX2'
--执行最慢的语句
select * from ( select sql_id,parsing_schema_name,module,executions,sorts,command_type,disk_reads,sql_text from v$sqlarea order by disk_reads desc ) where rownum<10 ;