Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2837838
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: Oracle

2012-08-17 22:34:54

一个PUBER遇到了ORA-27046: file size is not a multiple of logical block size 错误。
据说空间满了,重启后遇到了这个错误。
原帖地址:http://www.itpub.net/thread-1707321-1-1.html
怀疑是没有正常关闭数据库,就重启操作系统导致的。
这个错误表示文件的大小不是DB_BLOCK_SIZE的整数倍。
本文就简单模拟一下这个错误,及其利用dd来解决这个问题的步骤。
数据库用的 linux版本 11gr2。

[oracle@db2server huateng]$ sqlplus -v

SQL*Plus: Release 11.2.0.1.0 Production

文件htyansp01.dbf的大小为60620800字节。
[oracle@db2server huateng]$ ls -ltr htyansp01.dbf
-rw-r--r-- 1 oracle oinstall 60620800 Aug 16 07:33 htyansp01.dbf


我的数据库的DB_BLOCK_SIZE 为8K,因此这个文件占用了7400个BLOCKS,实际大小为7399个BLOCKS(减去一个OS块)。
在htyansp01.dbf文件后面增加一个4k的空块就可以模拟出这个错误。
如下:


[oracle@db2server huateng]$ dd if=/dev/zero of=htyansp01.dbf bs=4096 count=1 seek=14800 conv=notrunc
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.000354954 seconds, 11.5 MB/s
[oracle@db2server huateng]$ ls -ltr htyansp01.dbf
-rw-r--r-- 1 oracle oinstall 60624896 Aug 16 14:15 htyansp01.dbf

启动数据库就会报错:


[oracle@db2server ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 16 14:18:06 2012

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 380817408 bytes
Fixed Size 1336680 bytes
Variable Size 268438168 bytes
Database Buffers 104857600 bytes
Redo Buffers 6184960 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/app/oracle/oradata/huateng/htyansp01.dbf'

SQL>

不过前台的错误显示的不够准确,并没有显示ORA-27046错误,ALERT日志文件中的信息比较详细:

ALTER DATABASE MOUNT
2012-08-16 14:18:28.254000 +08:00
Successful mount of redo thread 1, with mount id 2136189040
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: ALTER DATABASE MOUNT
ALTER DATABASE OPEN
Errors in file /u01/app/oracle/diag/rdbms/huateng/huateng/trace/huateng_dbw0_8444.trc:
ORA-01157: ????/?????? 6 - ??? DBWR ????
ORA-01110: ???? 6: '/u01/app/oracle/oradata/huateng/htyansp01.dbf'
ORA-27046: ??????????????
Additional information: 1
Errors in file /u01/app/oracle/diag/rdbms/huateng/huateng/trace/huateng_ora_8536.trc:
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/app/oracle/oradata/huateng/htyansp01.dbf'
ORA-1157 signalled during: ALTER DATABASE OPEN...

现在我们用dd来解决这个错误。注意:一定要把文件修复的比文件头记录的文件大小大,
否则可能会遇到如下的错误:

ORA-01200: actual file size of 7399 is smaller than correct size of 12800。


那么我们如何知道文件原来的大小呢?
对于本例由于我们是自己模拟的,我们事先知道原来文件的大小的,目前只需要去掉后面增加的4092个字节即可。
在文件不可访问的情况下,V$DATAFILE是查询不到文件的大小的,显示为0:

SQL> select file#,name,blocks from v$datafile;

FILE# NAME BLOCKS
---------- -------------------------------------------------- ----------
1 /u01/app/oracle/oradata/huateng/system01.dbf 88320
2 /u01/app/oracle/oradata/huateng/sysaux01.dbf 62720
3 /u01/app/oracle/oradata/huateng/undotbs01.dbf 10880
4 /u01/app/oracle/oradata/huateng/users01.dbf 640
5 /u01/app/oracle/oradata/huateng/example01.dbf 12800
6 /u01/app/oracle/oradata/huateng/htyansp01.dbf 0
7 /u01/app/oracle/oradata/huateng/file01.dbf 2000

对于未知的情况我们可以通过如下的方法:



  • 方法1:

把文件补齐到整数倍的DB_BLOCK_SIZE,启动数据库可能会报ORA-01200错误。
如下ORA-01200: actual file size of xxxxx is smaller than correct size of yyyy。那么这个yyyy就是原来实际文件的BLOCKS数。



  • 方法2:

通过BBED来查询,文件头偏移量44记录的就是文件的实际大小,如下所示:

BBED> p offset 44
kcvfh.kcvfhhdr.kccfhfsz
-----------------------
ub4 kccfhfsz                                @44       0x00001ce7

修复过程如下:

[oracle@db2server huateng]$ dd if=htyansp01.dbf of=new.dbf bs=8192 count=7400
7400+0 records in
7400+0 records out
60620800 bytes (61 MB) copied, 0.93832 seconds, 64.6 MB/s
[oracle@db2server huateng]$ ls -ltr new.dbf
-rw-r--r-- 1 oracle oinstall 60620800 08-16 14:36 new.dbf
[oracle@db2server huateng]$ rm -rf htyansp01.dbf
[oracle@db2server huateng]$ mv new.dbf htyansp01.dbf
[oracle@db2server huateng]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 16 14:36:27 2012

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 380817408 bytes
Fixed Size 1336680 bytes
Variable Size 268438168 bytes
Database Buffers 104857600 bytes
Redo Buffers 6184960 bytes
Database mounted.
Database opened.
SQL> create table t(id int) tablespace htyansp;

Table created.

对于ORA-01200错误也可以用类似的方法。
阅读(1284) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~