各种操作系统裸设备dd命令,以及ora-01200错误的分析

各种操作系统裸设备dd命令
很多oracle 环境都适用的是裸设备环境,常常需要适用dd命令备份裸设备。
--------------------- --------------------- --------------------- --------------------
系统保留块如下
unix    OS Reserved Size
-----   ----------------
SUN Solaris    0
HP-UX          0
Linux          0
IBM AIX        4K
Tru64 UNIX     64k
--------------------- --------------------- --------------------- ---------------------
dd 命令:
1. if=file         :输入文件名,缺省为标准输入。即指定源文件。<if=inputfile>
3.ibs=bytes         :一次读入bytes个字节,即指定一个块大小为bytes个字节。
obs=bytes            :一次输出bytes个字节,即指定一个块大小为bytes个字节。
bs=bytes          :同时设置读入/输出的块大小为bytes个字节。
4.cbs=bytes         :一次转换bytes个字节,即指定转换缓冲区大小。
5. skip=blocks       :从输入文件开头跳过blocks个块后再开始复制。
6. seek=blocks     :从输出文件开头跳过blocks个块后再开始复制。
注意:通常只用当输出文件是磁盘或磁带时才有效,即备份到磁盘或磁带时才有效。
7. count=blocks    :仅拷贝blocks个块,块大小等于ibs指定的字节数。
8.conv=conversion :用指定的参数转换文件。
ascii:转换ebcdic为ascii
ebcdic:转换ascii为ebcdic
ibm:转换ascii为alternateebcdic
block:把每一行转换为长度为cbs,不足部分用空格填充
unblock:使每一行的长度都为cbs,不足部分用空格填充
lcase:把大写字符转换为小写字符
ucase:把小写字符转换为大写字符
swab:交换输入的每对字节
noerror:出错时不停止
notrunc:不截短输出文件
sync:将每个输入块填充到ibs个字节,不足部分用空(NUL)字符补齐。

例如: dd 出来裸设备上的数据文件
dd if=/app/oracle/testdb/system01.dbf f=/backup/testbk/system01.dbf bs=8k 
--------------------- --------------------- --------------------- ---------------------

ora-01200错误:
ora-01200: 文件的真实大小比控制文件和数据文件头记录的小,一般是数据库异常导致的,在数据库的运行过程中,重新启动时,文件resize之后出现异常状况时都可能会遇到。推荐的解决方案是从备份中恢复一个完好的拷贝,执行必要的恢复,使数据库恢复到正常的状态。

问题的发现
备份失败,提示如下:
allocated channel:ch00
channel ch00:sid=32 devtype=SBT_TAPE
channel choo:Veritas NetBackup for Oracle - Release 6.5
sent command to channel:ch00
Starting backup at 24-MAR-09
channel ch00:starting incremental level 0 datafile backupset
channel ch00:specifying datafile(s) in backupset
input datafile fno=00079 name=/dev/rpub_pind1_12
input datafile fno=00090 name=/dev/rpub_ping2_13
channel ch01:starting piece 1 at 24-MAR-09
including current SPFILE in backupset
including current controlfile in backupset
input datafile fno=00044 name=/dev/rpub_pdata2_06
input datafile fno=00063 name=/dev/rpub_plob2_05
released channel:ch00
RMAN-00571==============
RMAN-00569==============
RMAN-00571==============
RMAN-03009:failure of backup command on ch00 channel at 03/24/2009 00:06:42
ORA-01122:database file 59 failed verification check
ORA-01110:data file 59:'/dev/rpub_plob2_01'
ORA-01200:actual file size of 327678 is smaller than corrent size of 655104 blocks

这里提示 文件59大小异常,文件实际大小为327678个数据块,而控制文件记录的当前大小为655104,两者不一致,导致rman异常退出,备份失败。

如果为了使rman暂时能够跳过这个错误,可以在rman中设置备份时跳过这个出现错误的表空间,在常规rman备份时,
也可以通过exclude命令来排除某些表空间:

rman target /
Recovery Manager: Release 9.2.0.7.0 - 64bit Production
Copyriht (c) 1995,2002,Oracle Corporation. All rights reserced.
connected to target database:OS(DBID=658484424)
RMAN> configure exclude for tablespace PUB_PLOB2_01;
using target database controlfile instead of recovery catalog tablespace PUB_PLOB2_01 will be excluded from future whole database backups
new RMAN configuration parameters are successfully stored
检查告警日志文件,可以找到离线文件的相关信息,其实初始创建大小为126MB,创建时间等如下代码:
Wed Nov 16 09:00:44 2005
create tablespace pub_plob2_01 datafile '/dev/rpub_plob2_01' size 126m segment space management auto
Wed Nov 16 09:00:45 2005
Completed:created tablespace pub_plob2_01 datafile '/dev/rpub.......

而数据文件离线的具体出错时间及详细信息如下:
Mon Mar 9 16:41:04 2009
Errors in file /opt/prod/admin/ds/bdump/ds2_ckpt_827498.trc:
ORA-01171:datafile 59 going offline due to error advancing checkpoint
ORA-01122:database file 59 failed verification check
ORA-01110:data file 59:'/dev/rpub_plob2_01'
ORA-01200:actual file size of 327678 is smaller than correct size of 655104 blocks

检查点进程在增加表空间时,发现了该文件的错误,并将该文件离线,CKPT进程跟踪文件记录如下:
Oracle9i Enterprise Edition Release 9.2.0.7.0-64bit Production
With the Partitioning and Real Application Clusters options
JServer Release 9.2.0.7.0-Production
ORACLE_HOME=/opt/prod/ora92
System name:AIX
Node name:oracle2
Release:1
Version:5
Machine:0007D76F4C00
Instance name:ds2
Redo thread mounted by this instance:2
Oracle process number:10
Unix process pid:827498,image:oracle@oracle2(CKPT)
****2009-03-09......
****SESSION ID:(11.1) 2008.....
ORA-01171:datafile 59 going offline dure to error advancing checkpoint
ORA-01122:database file 59 failed verification check
ORA-01110:data file 59:'/dev/rpub_plob2_01'
ORA-01200:actual file size of 327678 is smaller than correct size of 655104 blocks

处理过程记录:
通过V$RECOVER_FILE 查看需要恢复的文件
SQL> select * from V$RECOVER_FILE ;

--查看总块大小
select A.FILE#,A.NAME,A.BLOCKS,A.BYTES/1024/1024 from v$datafile a where A.FILE#=59

物理设备确认:
lapv -l XXvg

执行恢复:
在系统中使用mklv创建分配一个新的逻辑卷
mklv -y  recvr_plob2_01  -T O -w n -s n -r n -t raw datavg 6000M

----两个节点都执行
chown oracle:oinstall /dev/ rrecvr_plob2_01 

接下来使用dd 命令将数据文件转存到文件系统中。使用dd命令时候要注意,由于在不同的OS中裸设备文件头可能预留有系统保留块。
所以我们在使用dd命令时候需要跳过该系统保留块。避免破坏系统。
我们可以通过语句  BLOCK1_OFFSET  确认保留块大小
SELECT A.FILE#,
       A.NAME,
       A.BLOCKS,
       A.BYTES / 1024 / 1024,
       A.BLOCK1_OFFSET
  FROM v$datafile a

例如AIX 系统中可以查看到BLOCK1_OFFSET偏移量为12288(12k),
oracle文件头预留了1个 8k(8192)的数据块,
另外一个 4k 的数据块就是裸设备的系统保留块。

系统保留块如下
unix    OS Reserved Size
-----   ----------------
SUN Solaris    0
HP-UX          0
Linux          0
IBM AIX        4K
Tru64 UNIX     64k

*************************************************************************
对于此案例 AIX 系统 数据块大小为  327678  转换一下,就是  327678*2 = 655356 个4k块,
在加上oracle 数据文件头块 8k,所以需要 dd 出 (655356 + 2)  655358 个4K块,
并且跳过一个裸设备的头块。
*************************************************************************
输出文件到文件 plob2_01.dbf
dd if= /dev/rpub_plob2_01  of= plob2_01.dbf  bs=4k seek=1 count= 655358

那么现在这个文件跳过AIX保留块后总共备份了  655358个4K块 及   327679 个8k数据块

dbv检查一遍
dbv file= plob2_01.dbf blocksize=8192

接下来通过dd命令将文件补齐 加上一个空块,模拟得到一个655104个8k数据块加上1个8k数据文件头的的数据文件,
正好可以骗过操作系统和控制文件。
(有点绕,因为提示中的 655104 个8k块同样也没有包含数据文件头块

dd if= /dev/zero  of= plob2_01.dbf  bs=8192 seek= 327679  count=  327426  conv=notrunc


接下来将这个文件添加到前面创建的裸设备中去,注意同样要跳过一个系统块
dd  if= plob2_01.dbf  of= /dev/ rrecvr_plob2_01  bs=4k seek= 1

alter database rename file '/dev/rpub_plob2_01' to  '/dev/rrecvr_plob2_01' ;

recover  tablespace PUB_PLOB2_01 ;

alter database  tablespace  PUB_PLOB2_01  online ;

问题解决:


---------------------linux案例一则--------------------------------------

在数据库启动的过程中可能遇到如下的错误:
点击(此处)折叠或打开
[oracle@db2server huateng]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 5 17:24:07 2012
 
Copyright (c) 1982, 2009, Oracle. All rights reserved.
 
Connected to an idle instance.
 
SQL> startup
ORACLE instance started.
 
Total System Global Area 506368000 bytes
Fixed Size 1337520 bytes
Variable Size 331351888 bytes
Database Buffers 167772160 bytes
Redo Buffers 5906432 bytes
Database mounted.
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/u01/app/oracle/oradata/huateng/htyansp01.dbf'
ORA-01200: actual file size of 7399 is smaller than correct size of 12800  blocks
 
 
SQL>
 
这个错误表示文件头记录的数据文件的大小与实际不一致:
 
--数据文件大小
SQL> ! ls -ltr /u01/app/oracle/oradata/huateng/htyansp01.dbf
-rw-r--r-- 1 oracle oinstall 60620800 08-05 17:25 /u01/app/oracle/oradata/huateng/htyansp01.dbf
 
 
SQL> select bytes from v$datafile where name='/u01/app/oracle/oradata/huateng/htyansp01.dbf';
 
     BYTES
----------
 
104857600
 
SQL> select 60620800-8192 from dual;
 
60620800-8192
-------------
 
     60612608
 
SQL> select 60612608/8192 from dual;
 
60612608/8192
-------------
 
         7399
 
实际文件的大小为 7399 个 8k BLOCKS。
 
 
SQL> select bytes from v$datafile where name='/u01/app/oracle/oradata/huateng/htyansp01.dbf';
 
     BYTES
----------
 
104857600
 
SQL> select 104857600/8192 from dual;
 
104857600/8192
--------------
 
         12800
 
而控制文件中记录的文件大小为12800个 BLOCKS。
如果有备份的话可以通过备份恢复的方法来解决这个问题。如果没有备份的话,

一种简单解决这个错误的方法是通过把数据文件构造到和控制文件记录的一模一样来骗过oracle。
如下:  
 
点击(此处)折叠或打开
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/u01/app/oracle/oradata/huateng/htyansp01.dbf'
ORA-01200: actual file size of 7399 is smaller than correct size of 12800
blocks
 
 
SQL> select 12800-7399 from dual ;
 
12800-7399
----------
 
      5401

备份
dd if= /u01/app/oracle/oradata/huateng/htyansp01.dbf  of= htyansp01back.dbf   bs=8192

如果要加count 那么记住 要加上一个8块的数据头文件。
count= 7400  

通过dd命令补齐数据文件,注意要加上一个8k的数据文件头块。

SQL> ! dd if=/dev/zero of=/u01/app/oracle/oradata/huateng/htyansp01.dbf bs=8192 count=5401 seek=7400
5401+0 records in
5401+0 records out
44244992 bytes (44 MB) copied, 0.152335 seconds, 290 MB/s
 
SQL> ! ls -ltr /u01/app/oracle/oradata/huateng/htyansp01.dbf
-rw-r--r-- 1 oracle oinstall 104865792 08-05 17:37 /u01/app/oracle/oradata/huateng/htyansp01.dbf
 
 
SQL> alter database open;
 
Database altered.








转载于:https://www.cnblogs.com/cure-t-x-y/p/4243809.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值