您的位置:首页 > 数据库 > Oracle

ORACLE故障排除--注意事项

2011-12-09 23:11 218 查看
1.
在系统良好运作时, 进行一次Statspack! 并将结果文件保存作为以后的判断标准.
2.
ORACLE中建立一张存放有执行计划的表
脚本如下:

--建立一张计划表
create table plan_hashes
( sql_text varchar2(1000),
hash_value number,
plan_hash_value number,
constraint plan_hashes_pk
primary key(hash_value,sql_text,plan_hash_value)
)
organization index;

--将shared_pool中的语句插入计划表
insert into plan_hashes( sql_text, hash_value, plan_hash_value )
select distinct sql_text,
hash_value,
plan_hash_value
from v$sql
where command_type in (
/* DELETE */ 7, /* INSERT */ 2,
/* MERGE */ 189, /* SELECT */ 3,
/* UPDATE */ 6 )
and parsing_user_id <> 0
and parsing_schema_id <> 0;

--查看当前shared pool中的执行计划与计划表的差异
select distinct sql_text,
hash_value,
plan_hash_value,
decode( (select 1
from plan_hashes
where plan_hashes.hash_value = v$sql.hash_value
and plan_hashes.sql_text = v$sql.sql_text
and rownum = 1), 1, 'Changed', 'New' ) status
from v$sql
where (sql_text, hash_value, plan_hash_value)
not in (select sql_text, hash_value, plan_hash_value
from plan_hashes)
and command_type in (
/* DELETE */ 7, /* INSERT */ 2,
/* MERGE */ 189, /* SELECT */ 3,
/* UPDATE */ 6 )
and parsing_user_id <> 0
and parsing_schema_id <> 0
/

--shared_pool中新的执行计划存入计划表
insert into plan_hashes( sql_text, hash_value, plan_hash_value )
select distinct sql_text,
hash_value,
plan_hash_value
from v$sql
where (sql_text, hash_value, plan_hash_value)
not in (select sql_text, hash_value, plan_hash_value
from plan_hashes)
and command_type in (
/* DELETE */ 7, /* INSERT */ 2,
/* MERGE */ 189, /* SELECT */ 3,
/* UPDATE */ 6 )
and parsing_user_id <> 0
and parsing_schema_id <> 0
/

3.
找出差异
收集了之前的历史资料,我们就能通过比对找出两者之间的差别

4.
每次只更改一个问题
不要多个人同时更改多个问题,也不要一个人更改多个问题,这样就无法确定到底是哪个变动解决了问题所在

5.
确认是否需要修改这个问题
改动一个问题之前要先确定目标,并且经过验证(小规模的基准测试是必要的)之后才能动手

6.
做好备份
任何改动之前都需要进行备份,使系统能够回退到改动前的状态时必须的

7.
建立小型的测试用例
由于系统可能会很庞大,运行起来相当复杂耗时,所以需要尽可能多的剥离不需要的代码,使用简单,明了的测试用例重现错误!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: