你好,游客 登录 注册 搜索
背景:
阅读新闻

遭遇ORA-01200错误的原因及解决方法

[日期:2011-09-26] 来源:51cto  作者:ixdba [字体: ]

1、案例现象
在数据库startup时,报错:
[Oracle@localhost ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 19 19:31:05 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area  202445884 bytes
Fixed Size                   451644 bytes
Variable Size             167772160 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/u01d/sysaux01.dbf'
ORA-01200: actual file size of 38400 is smaller than correct size of 51200 blocks

2、问题分析

SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL>
报错说,数据文件的实际大小与正确的大小较小。
SQL> col name for a50
SQL> select file#,status,bytes/1024/1024 mb,name from v$datafile;
     FILE# STATUS          MB NAME
---------- ------- ---------- --------------------------------------------------
         1 SYSTEM         300 /u01/u01d/system01.dbf
         2 ONLINE         100 /u01/u01d/undotbs01.dbf
  3 SYSTEM   400 /u01/u01d/sysaux01.dbf
         4 ONLINE          25 /u01/u01d/users01.dbf
         5 ONLINE          25 /u01/u01d/indx01.dbf
         6 ONLINE         100 /u01/u01d/perfstat.dbf
         7 ONLINE          10 /u01/u01d/timi01.dbf
6 rows selected.
SQL>
可以看出控制文件记录的是400M,而du -sh system01.dbf结果是301M。接着,查阅在线帮助文档:
[oracle@localhost ~]$oerr ora 01200
01200, 00000, "actual file size of %s is smaller than correct size of %s blocks"
// *Cause:  The size of the file as returned by the operating system is smaller
//         than the size of the file as indicated in the file header and the
//         controlfile. Somehow the file has been truncated. Maybe it is the
//         result of a half completed copy.
// *Action: Restore a good copy of the data file and do recovery as needed.
[oracle@localhost ~]$
可以看出,是数据文件的实际大小与控制文件和该数据文件的头部所记录的大小不同而引起的。一般是数据库异常导致的,在数据库的运行过程中,重新启动时,文件resize之后出现异常状况时都可能会遇到。下面看看怎么恢复,以打开数据库:

3、确定解决方案

首先转储数据文件头部看看:
SQL> alter session set events 'immediate trace name FILE_HDRS level 10';
Session altered.
SQL> @/u01/admin/mytools/myscripts/gettrcname.sql
TRACE_FILE_NAME
--------------------------------------------------------------------------------------------------------------
/u01/admin/denver/udump/denver_ora_4669.trc
SQL>
[oracle@localhost ~]$more /u01/admin/denver/udump/denver_ora_5349.trc
.....
FILE HEADER:
        Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
        Db ID=4004057640=0xeea91228, Db Name='DENVER'
        Activation ID=0=0x0
       Control Seq=1908=0x774, File size=51200=0xc800  //可见此处的大小是51200, 而ORA-01200报告说实际大小是38400
        File Number=1, Blksiz=8192, File Type=3 DATA
Tablespace #0 - SYSTEM  rel_fn:1
.....

解决方案的确定:
1.如果有备份可以采用备份来恢复.
2.最坏的情况是将文件上的数据提取出来,重新加载到数据库。
3.最好的情况是通过一些特殊的手段,将该文件恢复,重新ONLINE运行。
4.通过Metalink及各种途径寻找已知的解决方案。

此时,发现根本没有任何的备份。没办法,只有使用bbed工具来非常规恢复了。

4、用BBED工具恢复

bbed就是英文block browse block edit的缩写,用来直接查看和修改数据文件数据的一个工具。在windows上没有提供这个工具,在linux上面有,需要编译:
make -f ins_rdbms.mk BBED=$ORACLE_HOME/rdbms/lib/bbed $ORACLE_HOME/bin/bbed
然后把$ORACLE_HOME/rdbms/lib加到环境变量的PATH里面,就可以直接在命令中bbed了。不过有个默认的口令blockedit。在运行bbed之前先要自己写几个配置文件:

这里假定有2个文件,分别是file.txt、par.bbd

[oracle@localhost ~]$ ls
file.txt bbed.par
[oracle@localhost ~]$ more bbed.par
blocksize=8192
listfile=/home/oracle/file
mode=edit
[oracle@localhost ~]$ more file.txt
3 /free/oracle/oradata/orcl/sysaux01.dbf 1614807040

5、恢复过程

接下来就可以使用BBED工具了:
[oracle@localhost ~]$ bbed
Password:

BBED: Release 2.0.0.0.0 - Limited Production on Tue Sep 20 18:19:33 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED>


BBED> modify /x 00960000 offset 44  ---用find /x c8 curr 找出51200所在之处, 因为38400的十六进制为9600,在根据倒位法则就是0096
File: /u01/u01d/system01.dbf (1)
Block: 1                Offsets:   44 to  555           Dba:0x00400001
------------------------------------------------------------------------
00960000 00200000 01000300 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 a1014000 07000000 00000000
4bbaa02a 9aabd02a 0e3a0f00 00000000 00000000 00000000 00000000 00000400
7a061000 00000000 86a7dd2a 01005162 01000000 8d660000 1000ffbf 02000000
00000000 6c010000 54abd02a 6b010000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 06005359 5354454d 00000000 00000000 00000000
00000000 00000000 00000000 01000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 0a000a00 9cefc52a
5c0a0d00 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
BBED> sum apply
Check value for File 1, Block 1:
current = 0x1459, required = 0x1459
BBED> quit

试着打开数据库:
SQL> alter database open;
Database altered.
SQL> col name for a50
SQL> select file#,status,bytes/1024/1024 mb,name from v$datafile;
     FILE# STATUS          MB NAME
---------- ------- ---------- --------------------------------------------------
         1 SYSTEM         300 /u01/u01d/system01.dbf
         2 ONLINE         100 /u01/u01d/undotbs01.dbf
  3 SYSTEM   300 /u01/u01d/sysaux01.dbf  ---控制文件里记录是300M,而且数据库已经成功打开
         4 ONLINE          25 /u01/u01d/users01.dbf
         5 ONLINE          25 /u01/u01d/indx01.dbf
         6 ONLINE         100 /u01/u01d/perfstat.dbf
         7 ONLINE          10 /u01/u01d/timi01.dbf
6 rows selected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area  202445884 bytes
Fixed Size                   451644 bytes
Variable Size             167772160 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
ok, 成功打开数据库。

6、总结
ORA-01200错误的具体原因已经清楚,但是是什么导致的这次数据库故障,已无从考究。但是应该可以肯定的是,此时的数据库应该立即做个导出重建导入操作。

linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款