客户XXX数据库服务器掉电,数据库 startup启动数据库遇到ORA-01200错误,信息如下:
SQL> startup;
ORACLE instance started.
Total System Global Area 997953536 bytes
Fixed Size 2259400 bytes
Variable Size 515900984 bytes
Database Buffers 473956352 bytes
Redo Buffers 5836800 bytes
Database mounted.
ERROR at line 1:
ORA-01122: database file 7 failed verification check
ORA-01110: data file 7: '+DG_DATA/orcl/my_tps01.dbf'
ORA-01200: actual file size of 12800 is smaller than correct size of 12928 blocks
问题原因
根据问题报错信息,可以判断是实际数据文件大小与控制文件和数据文件头中的信息不一致。
[oracle@node1 backup]$ 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
// control file. 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.
查看数据文件头中数据文件blocks数量和文件大小
SQL> select file#,name,blocks,bytes from v$datafile where file#=7;
FILE# NAME BLOCKS BYTES
---------- ------------------------------ ---------- ----------
7 +DG_DATA/orcl/my_tps01.dbf 12928 105906176
SQL> select file#,name,blocks,bytes from v$datafile_header where file#=7;
FILE# NAME BLOCKS BYTES
---------- ------------------------------ ---------- ----------
7 +DG_DATA/orcl/my_tps01.dbf 12928 105906176
ASMCMD> ls -l +DG_DATA/orcl/my_tps01.dbf
Type Redund Striped Time Sys Name
N my_tps01.dbf => +DG_DATA/ORCL/DATAFILE/my_tps01.dbf.272.1123349667
ASMCMD> ls -ls +DG_DATA/ORCL/DATAFILE/my_tps01.dbf.272.1123349667
Type Redund Striped Time Sys Block_Size Blocks Bytes Space Name
DATAFILE UNPROT COARSE DEC 13 17:00:00 Y 8192 12801 104865792 106954752 my_tps01.dbf.272.1123349667
解决方案
弄清具体问题发生原因后,该问题有如下2种解决办法:
- 方式1 :通过dd命令填充数据文件实际大小为correct size of 12928中的值
- 方式2 :通过bbed 改数据文件头部偏移量44处的值为数据文件实际占用块数
方式1:dd命令填充数据文件
1. 将数据文件从ASM磁盘组中拷贝到本地文件系统上
[grid@node1 backup]$ asmcmd cp +DG_DATA/orcl/my_tps01.dbf /u01/backup/my_tps01.dbf
copying +DG_DATA/orcl/my_tps01.dbf -> /u01/backup/my_tps01.dbf
保留一个原始备份在文件系统
[grid@node1 backup]$ cp /u01/backup/my_tps01.dbf /u01/backup/my_tps01.dbf.org
[grid@node1 backup]$ chmod 775 /u01/backup/my_tps01.dbf
[grid@node1 backup]$ ls -l /u01/backup/my_tps01.dbf
-rwxrwxr-x 1 grid oinstall 104865792 Dec 13 17:38 /u01/backup/my_tps01.dbf
SQL> select 104865792 / 8192 from dual;
104865792/8192
--------------
12801
每个数据文件的第一个块(block 0)是OS block header,因此数据文件实际大小比数据文件头记录的数量多一个block,也就是8K大小。
2.使用dd命令向数据文件中填入空块,使数据文件大小与文件头中记录的大小一致。
dd if=/dev/zero of=/u01/backup/my_tps01.dbf bs=8192 seek=12801 count=128 conv=notrunc
[oracle@node1 backup]$ ls -l /u01/backup/my_tps01.dbf
-rwxrwxr-x 1 grid oinstall 105914368 Dec 13 17:40 /u01/backup/my_tps01.dbf
SQL> select 105914368 / 8192 from dual;
12929
3.将文件重名名到本地文件系统上的文件,并open打开数据库
SQL> alter database rename file '+DG_DATA/orcl/my_tps01.dbf' to '/u01/backup/my_tps01.dbf';
Database altered.
SQL> recover datafile 7;
Media recovery complete.
SQL> alter database open;
Database altered.
此时数据库可以open了,alert日志也无报错:
SMON: enabling tx recovery
Database Characterset is ZHS16GBK
No Resource Manager plan active
Starting background process GTX0
Tue Dec 13 17:12:52 2022
GTX0 started with pid=39, OS id=29629
Starting background process RCBG
Tue Dec 13 17:12:52 2022
RCBG started with pid=40, OS id=29631
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Tue Dec 13 17:12:52 2022
QMNC started with pid=41, OS id=29633
Tue Dec 13 17:12:53 2022
minact-scn: Inst 1 is now the master inc#:2 mmon proc-id:18190 status:0x7
minact-scn status: grec-scn:0x0000.00000000 gmin-scn:0x0000.00000000 gcalc-scn:0x0000.00000000
Completed: alter database open
Tue Dec 13 17:12:54 2022
Starting background process CJQ0
Tue Dec 13 17:12:54 2022
CJQ0 started with pid=42, OS id=29648
4.使用dbv校验数据文件,也无坏块,如下:
[oracle@node1 backup]$ dbv file=/u01/backup/my_tps01.dbf
DBVERIFY: Release 11.2.0.4.0 - Production on Tue Dec 13 17:13:52 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE = /u01/backup/my_tps01.dbf
DBVERIFY - Verification complete
Total Pages Examined : 12800
Total Pages Processed (Data) : 1243
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 155
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 11402
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 2297177 (0.2297177)
5.关闭数据库实例,把数据文件拷贝到ASM磁盘组中
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[grid@node1 backup]$ asmcmd cp /u01/backup/my_tps01.dbf +DG_DATA/orcl/my_tps01.dbf
copying /u01/backup/my_tps01.dbf -> +DG_DATA/orcl/my_tps01.dbf
6.尝试使用rman backup as copy方式遇到ORA-19566坏块错误。
RMAN> backup as copy datafile 7 format '+DG_DATA/orcl/my_tps01.dbf';
Starting backup at 13-DEC-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 instance=orcl1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/backup/my_tps01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/13/2022 17:26:13
ORA-19566: exceeded limit of 0 corrupt blocks for file /u01/backup/my_tps01.dbf
7.尝试使用备份集方式(跳过空块),同样遇到ORA-19566错误
RMAN> backup as backupset datafile 7 format '/u01/backup/dbf7.bak';
Starting backup at 13-DEC-22
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/backup/my_tps01.dbf
channel ORA_DISK_1: starting piece 1 at 13-DEC-22
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/13/2022 17:53:45
ORA-19566: exceeded limit of 0 corrupt blocks for file /u01/backup/my_tps01.dbf
8.使用RMAN检查坏块,发现dd命令填充的数据块都被认作是坏块,如下:
RMAN> validate datafile 7;
Starting validate at 14-DEC-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=678 instance=orcl1 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00007 name=/u01/backup/my_tps01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7 FAILED 0 11402 12928 2297177
File Name: /u01/backup/my_tps01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 1243
Index 0 0
Other 128 283
validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/orcl/orcl1/trace/orcl1_ora_5350.trc for details
Finished validate at 14-DEC-22
由此可见,使用dd命令填充方式只能将数据库拉起,无法完美解决问题,还需要继续解决坏块问题。
方式2:bbed 修改文件头
1.删除修改过的文件,从原始备份拷贝一份
rm /u01/backup/my_tps01.dbf
cp /u01/backup/my_tps01.dbf.org /u01/backup/my_tps01.dbf
2.link bbed 过程省略。。。。。。
3.编辑bbed 参数文件
[oracle@node1 backup]$ cat filelist.txt
7 /u01/backup/my_tps01.dbf 104857600
[oracle@node1 backup]$ cat bbed.par
blocksize=8192
listfile=./filelist.txt
mode=edit
password=blockedit
4.使用bbed修改文件头blocks数量
oracle@node1 backup]$ bbed parfile=bbed.par
BBED: Release 2.0.0.0.0 - Limited Production on Wed Dec 14 09:24:42 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED>
BBED> show all
FILE# 7
BLOCK# 1
OFFSET 0
DBA 0x01c00001 (29360129 7,1)
FILENAME /u01/backup/my_tps01.dbf
BIFILE bifile.bbd
LISTFILE ./filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
BBED> set dba 7,1 offset 44
DBA 0x01c00001 (29360129 7,1)
OFFSET 44
BBED> p
kcvfh.kcvfhhdr.kccfhfsz
-----------------------
ub4 kccfhfsz @44 0x00003280
ORA-01122: database file 7 failed verification check
ORA-01110: data file 7: '+DG_DATA/orcl/my_tps01.dbf'
ORA-01200: actual file size of 12800 is smaller than correct size of 12928
blocks
现在需要将blocks数量12928改为12800,即0x3200
[grid@node1 ~]$ printf "%d\n" 0x3280
12928
[grid@node1 ~]$ printf "%x\n" 12800
3200
BBED> assign offset 44=0x3200
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
ub4 kccfhfsz @44 0x00003200
BBED> p
kcvfh.kcvfhhdr.kccfhfsz
-----------------------
ub4 kccfhfsz @44 0x00003200
或者使用 assign kcvfh.kcvfhhdr.kccfhfsz=0x3200
BBED> assign kcvfh.kcvfhhdr.kccfhfsz=0x3200
ub4 kccfhfsz @44 0x00003200
BBED> sum apply
Check value for File 7, Block 1:
current = 0xd4f1, required = 0xd4f1
BBED> exit
5.退出bbed,然后重启数据库,如下
SQL> startup;
ORACLE instance started.
Total System Global Area 997953536 bytes
Fixed Size 2259400 bytes
Variable Size 515900984 bytes
Database Buffers 473956352 bytes
Redo Buffers 5836800 bytes
Database mounted.
Database opened.
6.使用DBV 和RMAN 校验数据块,均无坏块。
[oracle@node1 backup]$ dbv file=/u01/backup/my_tps01.dbf
DBVERIFY: Release 11.2.0.4.0 - Production on Wed Dec 14 09:33:51 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE = /u01/backup/my_tps01.dbf
DBVERIFY - Verification complete
Total Pages Examined : 12800
Total Pages Processed (Data) : 1243
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 155
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 11402
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 2297177 (0.2297177)
[oracle@node1 backup]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 14 09:33:57 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1608114441)
RMAN> validate datafile 7;
Starting validate at 14-DEC-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=679 instance=orcl1 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00007 name=/u01/backup/my_tps01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7 OK 0 11402 12800 2297177
File Name: /u01/backup/my_tps01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 1243
Index 0 0
Other 0 155
Finished validate at 14-DEC-22
7.使用RMAN将数据文件7移动到ASM磁盘组
[grid@node1 ~]$ asmcmd rm -f +DG_DATA/orcl/my_tps01.dbf
[oracle@node1 backup]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 14 09:33:57 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1608114441)
RMAN> backup as copy datafile 7 format '+DG_DATA/orcl/my_tps01.dbf';
Starting backup at 14-DEC-22
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/backup/my_tps01.dbf
output file name=+DG_DATA/orcl/my_tps01.dbf tag=TAG20221214T093552 RECID=2 STAMP=1123407354
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 14-DEC-22
RMAN> sql 'alter database datafile 7 offline';
sql statement: alter database datafile 7 offline
RMAN> switch datafile 7 to copy;
datafile 7 switched to datafile copy "+DG_DATA/orcl/my_tps01.dbf"
RMAN> recover datafile 7;
Starting recover at 14-DEC-22
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 14-DEC-22
RMAN> sql 'alter database datafile 7 online';
sql statement: alter database datafile 7 online
SQL> select file#,name,status,blocks,bytes from v$datafile;
FILE# NAME STATUS BLOCKS BYTES
---------- ---------------------------------- ------- ---------- ----------
1 +DG_DATA/orcl/system01.dbf SYSTEM 98560 807403520
2 +DG_DATA/orcl/sysaux01.dbf ONLINE 71680 587202560
3 +DG_DATA/orcl/undotbs01.dbf ONLINE 13440 110100480
4 +DG_DATA/orcl/users01.dbf ONLINE 640 5242880
5 +DG_DATA/orcl/example01.dbf ONLINE 40080 328335360
6 +DG_DATA/orcl/undotbs02.dbf ONLINE 3200 26214400
7 +DG_DATA/orcl/my_tps01.dbf ONLINE 12800 104857600
8 +DG_DATA/orcl/odc_tps01.dbf ONLINE 1920 15728640
参考文档
When Performing Recover From Hot Backup ORA-01237 or ORA-01200 (Doc ID 1413507.1)
标签:u01,backup,tps01,dbf,01200,my,ORA From: https://blog.51cto.com/u_13482808/6943946