Oracle OS Block Header

oracle文件的第一个块(block 0)是OS block header,在数据库中查询不到信息,记录的是OS信息,以及文件大小的等信息:

SQL> select file_name,bytes from dba_data_files;
 
FILE_NAME                                               BYTES
-------------------------------------------------- ----------
/u01/app/oracle/oradata/PROD/user01.dbf              67108864
 
$ls -lrt
total 1390268
-rw-r-----  1 oracle oinstall  67117056 Apr 12 09:31 user01.dbf


从上面可以看出,OS上的大小比数据库里的大小多了一个BLOCK。

如果OS block header损坏,并不影响数据库打开、使用,但重建控制文件时会报错,用dbverify/rman也检测不到坏块,不过可以使用dbfsize来查看:
正常状态:

$dbfsize user01.dbf
 
Database file: user01.dbf
Database file type: file system
Database file size: 8192 8192 byte blocks

损坏:

$dbfsize user01.dbf
user01.dbf: Header block magic number is bad

编缉BLOCK 0,模拟损坏,可以正常启动、使用:

SQL> startup;
ORACLE instance started.
 
Total System Global Area  184549376 bytes
Fixed Size                  1266488 bytes
Variable Size             100666568 bytes
Database Buffers           79691776 bytes
Redo Buffers                2924544 bytes
Database mounted.
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/u01/app/oracle/oradata/PROD/user01.dbf'
 
 
SQL> recover datafile 4;  
Media recovery complete.
SQL> alter database open;
 
Database altered.
 
SQL> create table test01 tablespace USERS as select * from dba_objects;
 
Table created.

用dbv检查,未发现坏块:

$dbv file=user01.dbf
 
DBVERIFY: Release 10.2.0.4.0 - Production on Mon Apr 16 16:38:33 2012
 
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
 
DBVERIFY - Verification starting : FILE = user01.dbf
 
 
DBVERIFY - Verification complete
 
Total Pages Examined         : 8192
Total Pages Processed (Data) : 357
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 11
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 7824
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Highest block SCN            : 336969 (0.336969)

用dbfsize检查,报错:

$dbfsize user01.dbf
user01.dbf: Header block magic number is bad

如果重建控制文件,则会报错:

SQL> startup nomount;
ORACLE instance started.
 
Total System Global Area  184549376 bytes
Fixed Size                  1266488 bytes
Variable Size             100666568 bytes
Database Buffers           79691776 bytes
Redo Buffers                2924544 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "PROD" NORESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 5
  3      MAXLOGMEMBERS 5
  4      MAXDATAFILES 100
  5      MAXINSTANCES 2
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 (
  9      '/u01/app/oracle/oradata/PROD/REDO1_1.log',
 10      '/u01/app/oracle/oradata/PROD/REDO1_2.log',
 11      '/u01/app/oracle/oradata/PROD/REDO1_3.log'
 12    ) SIZE 100M,
 13    GROUP 2 (
 14      '/u01/app/oracle/oradata/PROD/REDO2_1.log',
 15      '/u01/app/oracle/oradata/PROD/REDO2_2.log',
 16      '/u01/app/oracle/oradata/PROD/REDO2_3.log'
 17    ) SIZE 100M
 18  -- STANDBY LOGFILE
 19  DATAFILE
 20    '/u01/app/oracle/oradata/PROD/SYSTEM01.dbf',
 21    '/u01/app/oracle/oradata/PROD/undotbs01.dbf',
 22    '/u01/app/oracle/oradata/PROD/SYSAUX01.dbf',
 23    '/u01/app/oracle/oradata/PROD/user01.dbf'
 24  CHARACTER SET AL32UTF8
 25  ;
CREATE CONTROLFILE REUSE DATABASE "PROD" NORESETLOGS  ARCHIVELOG
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-01565: error in identifying file '/u01/app/oracle/oradata/PROD/user01.dbf'
ORA-27047: unable to read the header block of file
Additional information: 2

报ORA-27047错误。这里可以在数据库打开状态下,resize datafile,这样就可以重写OS block header信息:

SQL> alter database open;
 
Database altered.
 
SQL> alter database datafile '/u01/app/oracle/oradata/PROD/user01.dbf' resize 65M;
 
Database altered.
 
SQL> select file_name,bytes from dba_data_files;
 
FILE_NAME                                               BYTES
-------------------------------------------------- ----------
/u01/app/oracle/oradata/PROD/user01.dbf              68157440

dbfsize检查正常,重建控制文件正常:

$dbfsize user01.dbf
 
Database file: user01.dbf
Database file type: file system
Database file size: 8320 8192 byte blocks
 
SQL> CREATE CONTROLFILE REUSE DATABASE "PROD" NORESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 5
  3      MAXLOGMEMBERS 5
  4      MAXDATAFILES 100
  5      MAXINSTANCES 2
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 (
  9      '/u01/app/oracle/oradata/PROD/REDO1_1.log',
 10      '/u01/app/oracle/oradata/PROD/REDO1_2.log',
 11      '/u01/app/oracle/oradata/PROD/REDO1_3.log'
 12    ) SIZE 100M,
 13    GROUP 2 (
 14      '/u01/app/oracle/oradata/PROD/REDO2_1.log',
 15      '/u01/app/oracle/oradata/PROD/REDO2_2.log',
 16      '/u01/app/oracle/oradata/PROD/REDO2_3.log'
 17    ) SIZE 100M
 18  -- STANDBY LOGFILE
 19  DATAFILE
 20    '/u01/app/oracle/oradata/PROD/SYSTEM01.dbf',
 21    '/u01/app/oracle/oradata/PROD/undotbs01.dbf',
 22    '/u01/app/oracle/oradata/PROD/SYSAUX01.dbf',
 23    '/u01/app/oracle/oradata/PROD/user01.dbf'
 24  CHARACTER SET AL32UTF8
 25  ;
 
Control file created.
 
SQL> alter database open;
 
Database altered.

注:resize 原大小,重建还是报错,需要resize一个不同的大小。

posted on 2012-12-12 14:25  一江水  阅读(2385)  评论(0编辑  收藏  举报