记一次尝试修复oracle坏块的过程
<h1>【问题背景】</h1>
<p>windows容灾恢复后,Oracle数据库起库成功,但是Oracle每次起库不久就会自动宕掉,查看数据库告警日志显示
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=fd35b9d1cabdd8ccaf1ee7a09146635e&amp;file=file.png" alt="" /></p>
<h1>【处理过程】</h1>
<h2>一、定位问题原因</h2>
<p>1.由于alert日志中显示ORA-00600的错误,怀疑数据库中有坏块导致,执行如下命令查看未查到有坏块信息。
SELECT * FROM V$DATABASE_BLOCK_CORRUPTION;
> 视图v$database_block_corruption中查不到坏块的原因如下:
视图v$database_block_corruption中有坏块记录,但是当索引段的第一个块标记为坏块后,在dba_extents中没有该索引段的记录,这种情况下的索引损坏,这个sql语句根本无法找出坏块索引。</p>
<p>2.由于alert后面有 error 474的错误信息,查看fast_start_parallel_rollback 的值为low,将该值置为false,重启数据库还是一样的问题。
> SQL>alter sysem set fast_start_parallel_rollback = FALSE
参考网址:<a href="https://www.itpub.net/thread-1219412-1-1.html?_dsign=1decd56c">https://www.itpub.net/thread-1219412-1-1.html?_dsign=1decd56c</a></p>
<p>3.通过alert中的"file# 42 block 3839” 直接找对应坏块的表OBJ$:
> select * from dha_extents where file_id=42 and 3839 between block_id and block_id+blocks;
参考网址:<a href="https://blog.csdn.net/weixin_43230594/article/details/132585695">https://blog.csdn.net/weixin_43230594/article/details/132585695</a></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=762263912c2b01f28c92d1fa4999511a&amp;file=file.png" alt="" />
alert日志中也是在对该表执行SQL语句时报错了。</p>
<p>4.分析涉事的表及其索引发现索引不一致
analyze table SYS.OBJ$ validate structure cascade;
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4be7540a12192c88c3ecfea05d8db3e5&amp;file=file.png" alt="" /></p>
<p>参考网址
<a href="https://blog.csdn.net/weixin_43230594/article/details/132585695">https://blog.csdn.net/weixin_43230594/article/details/132585695</a></p>
<h2>二、尝试修复坏块</h2>
<p>1.尝试用如下方法直接重建索引,在执行第一条SQL语句的时候报错ORA-00054:资源正忙,但指定以NOWAIT方式获取资源,或者超时失效
> ```sql
SQL> alter table WRI$_ALERT_OUTSTANDING disable primary key;
Table altered.
SQL> alter table WRI$_ALERT_OUTSTANDING enable primary key;
Table altered.
SQL> analyze table WRI$_ALERT_OUTSTANDING validate structure cascade online;
Table analyzed.</p>
<pre><code>参考网址:https://www.parnassusdata.com/zh-hans/node/841
准备通过如下命令查询被锁的SESSION_ID及SERIAL#;
&gt; ```sql
SQL&gt; select * from v$locked_object;
SQL&gt; select sid,serial#,username,osuser from v$session where sid= xxx; #sid为第一条语句的执行结果</code></pre>
<p>参考网址:<a href="https://blog.csdn.net/qq_36105771/article/details/133706289">https://blog.csdn.net/qq_36105771/article/details/133706289</a></p>
<p>但是还未执行该命令,在执行alter table WRI$_ALERT_OUTSTANDING disable primary key;的时候报错就变成了ORA-00701
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c6f60e7b5b325f33b39a45326450eef8&amp;file=file.png" alt="" /></p>
<p>2.更换重建索引的办法
> ```sql
-- 生成索引重建sql
SQL>select 'alter index '|| owner ||'.'|| index_name ||' rebuild online;' as sql, a.*
from dba_indexes a
where table_name = 'MY_TABLE';
SQL> alter index I_H_OBJ#_COL# rebuild;
SQL> alter index I_COL1 rebuild; </p>
<pre><code>参考网址:https://blog.csdn.net/huryer/article/details/130595409
但是依然报之前的错误
3.再次更换重建索引的办法
&gt; ```sql
#以migrate模式启动数据库
SQL&gt; SHUTDOWN IMMEDIATE
SQL&gt; STARTUP MIGRATE
SQL&gt; SELECT INSTANCE_NAME, STATUS FROM V$INSTANCE;
INSTANCE_NAME STATUS
---------------- ------------
yansp OPEN MIGRATE
SQL&gt; alter table WRI$_ALERT_OUTSTANDING disable primary key;
#设置LEVEL=10的38003事件
SQL&gt; SHUTDOWN IMMEDIATE
SQL&gt; STARTUP NOMOUNT
SQL&gt; alter system set event='38003 trace name context forever, level 10' scope=spfile;
SQL&gt; STARTUP FORCE
SQL&gt; alter index I_H_OBJ#_COL# rebuild;
SQL&gt; ALTER INDEX I_ICOL1 REBUILD;</code></pre>
<p>参考网址:<a href="https://blog.csdn.net/cnntb06220/article/details/100301095">https://blog.csdn.net/cnntb06220/article/details/100301095</a></p>
<p>还是一样的问题</p>
<p>解决方案极有可能是:
<a href="https://www.php.cn/faq/134592.html">https://www.php.cn/faq/134592.html</a></p>