重建控制文件

#  使用alter database backup controlfile to trace;产生控制文件的trace file

-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
#  需要重建控制文件的话, 如果online redo 是可用的, 使用NORESETLOGS 创建新控制文件打开数据库
#  如果online redo是不可用的, 那么需要使用RESETLOGS 创建新控制文件打开数据库, 
#  联机日志被重置,数据有可能丢失
--
--     Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
#   下面的命令用来创建一个新的控制文件来开启数据库。 用于RMAN的数据将会丢失。
#   对于offline datafiles 可能需要额外的归档日志用来做介质恢复, 
#   当当前版本的所有online redo log都没有问题的情况下使用noresetlogs。

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "XIENFEI" NORESETLOGS FORCE LOGGING ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 2921
LOGFILE
  GROUP 1 '/u01/oradata/xienfei/redo01.log'  SIZE 5M,
  GROUP 2 '/u01/oradata/xienfei/redo02.log'  SIZE 5M,
  GROUP 3 '/u01/oradata/xienfei/redo03.log'  SIZE 5M
-- STANDBY LOGFILE
DATAFILE
  '/u01/oradata/xienfei/system01.dbf',
  '/u01/oradata/xienfei/undotbs01.dbf',
  '/u01/oradata/xienfei/sysaux01.dbf',
  '/u01/oradata/xienfei/users01.dbf',
  '/u01/oradata/xienfei/example01.dbf',
  '/u01/oradata/xienfei/xff01.dbf',
  '/u01/oradata/xienfei/cf01.dbf',
  '/u01/oradata/xienfei/cfxff01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/archive/1_1_756837539.arc';
#  有些时候可能需要先注册归档日志,再才能够恢复
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
#  恢复数据库
RECOVER DATABASE
-- All logs need archiving and a log switch is needed.
#  归档所有日志
ALTER SYSTEM ARCHIVE LOG ALL;
-- Database can now be opened normally.
#  打开数据库
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
#  添加临时表空间
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/oradata/xienfei/temp01.dbf'
     SIZE 32505856  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.

##    下面的RESETLOGS 重建语句, online redo log 中的内容都会丢失,所有的备份将无效 
##    仅仅在online log 损坏的情况下使用 resetlogs 创建控制文件开启数据库。  
##    resetlog创建控制文件后的开启步骤与noresetlog有一些不一样,请注意下面步骤

--     Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "XIENFEI" RESETLOGS FORCE LOGGING ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 2921
LOGFILE
  GROUP 1 '/u01/oradata/xienfei/redo01.log'  SIZE 5M,
  GROUP 2 '/u01/oradata/xienfei/redo02.log'  SIZE 5M,
  GROUP 3 '/u01/oradata/xienfei/redo03.log'  SIZE 5M
-- STANDBY LOGFILE
DATAFILE
  '/u01/oradata/xienfei/system01.dbf',
  '/u01/oradata/xienfei/undotbs01.dbf',
  '/u01/oradata/xienfei/sysaux01.dbf',
  '/u01/oradata/xienfei/users01.dbf',
  '/u01/oradata/xienfei/example01.dbf',
  '/u01/oradata/xienfei/xff01.dbf',
  '/u01/oradata/xienfei/cf01.dbf',
  '/u01/oradata/xienfei/cfxff01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
#  注册归档日志
-- ALTER DATABASE REGISTER LOGFILE '/u01/archive/1_1_756837539.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
#  使用历史控制文件恢复数据库(因为redo log是新建,所以对于redo 而言,控制文件是新建的)
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
#  使用RESETLOGS方式打开数据库
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
#  添加临时表空间
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/oradata/xienfei/temp01.dbf'
     SIZE 32505856  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.

ORA-01578坏块解决(2)

ORA-01578坏块解决(1)续集
如果在坏块之前,有rman备份,可以使用rman的备份来进行恢复,确保数据不会被丢失

1、使用rman进行恢复
[oracle@ECP-UC-DB1 ~]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.4.0 – Production on Sun Aug 14 22:21:13 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database: TEST (DBID=2056006906)

RMAN> blockrecover datafile 6 block 1477;

Starting blockrecover at 2011-08-14 22:21:16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00006
channel ORA_DISK_1: reading from backup piece /tmp/0fmk0ii5_1_1
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/tmp/0fmk0ii5_1_1 tag=TAG20110814T213357
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:02

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished blockrecover at 2011-08-14 22:21:23

2、检查坏块是否被恢复
RMAN> backup check logical validate datafile 6;

Starting backup at 2011-08-14 22:22:11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/opt/oracle/oradata/test/xifenfei01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2011-08-14 22:22:12

RMAN> exit

Recovery Manager complete.

[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 22:22:17 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select file#,block#,blocks from v$database_block_corruption;

no rows selected

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@ECP-UC-DB1 ~]$ dbv file =/opt/oracle/oradata/test/xifenfei01.dbf

DBVERIFY: Release 10.2.0.4.0 – Production on Sun Aug 14 22:22:38 2011

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

DBVERIFY – Verification starting : FILE = /opt/oracle/oradata/test/xifenfei01.dbf

DBVERIFY – Verification complete

Total Pages Examined : 2560
Total Pages Processed (Data) : 1372
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 48
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 1140
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 1256690 (0.1256690)

3、验证数据是否正确
[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 22:34:18 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select count(*) from t_rep;

COUNT(*)
———-
49857

ORA-01578坏块解决(1)中的模拟环境比较,数据恢复正确,坏块问题解决

ORA-01578坏块解决(1)

一、创建测试表
SQL> create table t_rep as
2  select * from all_objects;
Table created.
SQL> select count(*) from  t_rep;
COUNT(*)
———-
49857
二、使用bbed修改数据块
三、错误现象
1、sqlplus窗口
SQL> select count(*) from  t_rep;
select count(*) from  t_rep
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 1477)
ORA-01110: data file 6: ‘/opt/oracle/oradata/test/xifenfei01.dbf’
2、alert.log文件中
Sun Aug 14 22:01:14 2011
Hex dump of (file 6, block 1477) in trace file /opt/oracle/admin/test/udump/test_ora_10785.trc
Corrupt block relative dba: 0x018005c5 (file 6, block 1477)
Bad check value found during buffer read
Data in bad block:
type: 6 format: 2 rdba: 0x018005c5
last change scn: 0x0000.001328ef seq: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x28ef0602
check value in block header: 0x493
computed block checksum: 0x44b9
Reread of rdba: 0x018005c5 (file 6, block 1477) found same corrupted data
Sun Aug 14 22:01:15 2011
Corrupt Block Found
TSN = 6, TSNAME = XFF
RFN = 6, BLK = 1477, RDBA = 25167301
OBJN = 52727, OBJD = 52728, OBJECT = T_REP, SUBOBJECT =
SEGMENT OWNER = SYS, SEGMENT TYPE = Table Segment
四、验证是否真的坏块
1、dbv验证
[oracle@ECP-UC-DB1 ~]$ dbv file =/opt/oracle/oradata/test/xifenfei01.dbf
DBVERIFY: Release 10.2.0.4.0 – Production on Sun Aug 14 22:08:37 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
DBVERIFY – Verification starting : FILE = /opt/oracle/oradata/test/xifenfei01.dbf
Page 1477 is marked corrupt
Corrupt block relative dba: 0x018005c5 (file 6, block 1477)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x018005c5
last change scn: 0x0000.001328ef seq: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x28ef0602
check value in block header: 0x493
computed block checksum: 0x44b9
DBVERIFY – Verification complete
Total Pages Examined         : 2560
Total Pages Processed (Data) : 1371
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 48
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1140
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Highest block SCN            : 1256043 (0.1256043)
2、rman验证
RMAN> backup check logical validate datafile 6;
Starting backup at 2011-08-14 22:09:51
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/opt/oracle/oradata/test/xifenfei01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2011-08-14 22:09:53
RMAN> exit
Recovery Manager complete.
[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 22:10:00 2011
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>  select file#,block#,blocks from v$database_block_corruption;SQL> exec dbms_repair.skip_corrupt_blocks(‘SYS’,’T_REP’);
FILE#     BLOCK#     BLOCKS
———- ———- ———-
6       1477          1
五、跳过坏块读取其他数据
SQL> exec dbms_repair.skip_corrupt_blocks(‘SYS’,’T_REP’);
PL/SQL procedure successfully completed.
SQL> select skip_corrupt from dba_tables where table_name=’T_REP’;
SKIP_COR
——–
ENABLED
SQL> select count(*) from t_rep;
COUNT(*)
———-
49794
说明:数据发生丢失6号文件的1477块中的数据丢失

bbed破坏数据文件

一、安装bbed
[oracle@ECP-UC-DB1 bin]$ cd $ORACLE_HOME/rdbms/lib
[oracle@ECP-UC-DB1 lib]$ ls -al *bb*
-rw-r–r– 1 oracle oinstall 1863 Mar 11 2008 sbbdpt.o
-rw-r–r– 1 oracle oinstall 1191 Mar 11 2008 ssbbded.o
[oracle@ECP-UC-DB1 lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
[oracle@ECP-UC-DB1 lib]$ mv bbed $ORACLE_HOME/bin
[oracle@ECP-UC-DB1 lib]$ cd ~
二、bben入门
[oracle@ECP-UC-DB1 ~]$ bbed
Password: blockedit(默认该密码)
BBED: Release 2.0.0.0.0 – Limited Production on Sun Aug 14 19:56:10 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> help all
SET DBA [ dba | file#, block# ]
SET FILENAME ‘filename’
SET FILE file#
SET BLOCK [+/-]block#
SET OFFSET [ [+/-]byte offset | symbol | *symbol ]
SET BLOCKSIZE bytes
SET LIST[FILE] ‘filename’
SET WIDTH character_count
SET COUNT bytes_to_display
SET IBASE [ HEX | OCT | DEC ]
SET OBASE [ HEX | OCT | DEC ]
SET MODE [ BROWSE | EDIT ]
SET SPOOL [ Y | N ]
SHOW [ <SET parameter> | ALL ]
INFO
MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]
DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
</Nuf>:
N – a number which specifies a repeat count.
u – a letter which specifies a unit size:
b – b1, ub1 (byte)
h – b2, ub2 (half-word)
w – b4, ub4(word)
r – Oracle table/index row
f – a letter which specifies a display format:
x – hexadecimal
d – decimal
u – unsigned decimal
o – octal
c – character (native)
n – Oracle number
t – Oracle date
i – Oracle rowid
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]
MODIFY[/x|d|u|o|c] numeric/character string
[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
ASSIGN[/x|d|u|o] <target spec>=<source spec>
<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec> : [ value | <target spec options> ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ <bbed command> | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]
三、创建测试表
[oracle@ECP-UC-DB1 ~]$ sqlplus chf/xifenfei
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 19:58:46 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table t_bbed (id number,name varchar2(100)) tablespace xff;
Table created.
SQL> insert into t_bbed values(1,’xifenfei’);
1 row created.
SQL> insert into t_bbed values(2,’xff’);
1 row created.
SQL> insert into t_bbed values(3,’chengfei’);
1 row created.
SQL> commit;
Commit complete.
SQL> conn / as sysdba
Connected.
SQL> alter system checkpoint;
System altered.
SQL> conn chf/xifenfei
Connected.
SQL> set serveroutput on
SQL> declare
ridtype number;
objnum number;
relfno number;
blno number;
rowno number;
rid rowid;
begin
select rowid into rid from t_bbed where id=1;
dbms_rowid.rowid_info(rid,ridtype,objnum,relfno,blno,rowno,’SMALLFILE’);
dbms_output.put_line(‘Row Typ-‘||to_char(ridtype));
dbms_output.put_line(‘Obj No-‘||to_char(objnum));
dbms_output.put_line(‘RFNO-‘||to_char(relfno));
dbms_output.put_line(‘Block No-‘||to_char(blno));
dbms_output.put_line(‘Row No-‘||to_char(rowno));
end;–查看rowid对应的文件号,块号等信息
/
Row Typ-1
Obj No-52721
RFNO-6
Block No-780
Row No-1
PL/SQL procedure successfully completed.
四、bben准备工作
1、创建参数文件
[oracle@ECP-UC-DB1 ~]$ cat parfile.conf
blocksize=8192
listfile=list
mode=edit
2、创建数据文件列表
[oracle@ECP-UC-DB1 ~]$ cat list
1 /opt/oracle/oradata/test/xifenfei01.dbf 2097160192
五、修改数据块中内容
[oracle@ECP-UC-DB1 ~]$ bbed parfile=parfile.conf
Password:
BBED: Release 2.0.0.0.0 – Limited Production on Sun Aug 14 20:35:41 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
1、定位需要修改块
BBED> set dba 1,780
DBA 0x0040030c (4195084 1,780)
2、查看相关内容
BBED> find /c xifenfei
File: /opt/oracle/oradata/test/xifenfei01.dbf (1)
Block: 780 Offsets: 8180 to 8191 Dba:0x0040030c
————————————————————————
78696665 6e666569 01062bce
<32 bytes per line>
3、dump文件中内容
BBED> dump /v dba 1,780 offset 8180 count 32
File: /opt/oracle/oradata/test/xifenfei01.dbf (1)
Block: 780 Offsets: 8170 to 8191 Dba:0x0040030c
——————————————————-
7866662c 010202c1 02087869 66656e66 l xff,……xifenf
65690106 2bce l ei..+.
<16 bytes per line>
4、修改数据块内容
BBED> modify 500 dba 1,780
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /opt/oracle/oradata/test/xifenfei01.dbf (1)
Block: 780 Offsets: 8180 to 8191 Dba:0x0040030c
————————————————————————
01f46665 6e666569 01062bce
<32 bytes per line>
BBED> find /c xienfei
BBED-00212: search string not found
BBED> exit
六、验证修改是否成功
1、dbv验证
[oracle@ECP-UC-DB1 ~]$ dbv file =/opt/oracle/oradata/test/xifenfei01.dbf
DBVERIFY: Release 10.2.0.4.0 – Production on Sun Aug 14 20:30:56 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
DBVERIFY – Verification starting : FILE = /opt/oracle/oradata/test/xifenfei01.dbf
Page 780 is marked corrupt
Corrupt block relative dba: 0x0180030c (file 6, block 780)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x0180030c
last change scn: 0x0000.0012ce2b seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0xce2b0601
check value in block header: 0x6382
computed block checksum: 0x1c
DBVERIFY – Verification complete
Total Pages Examined : 1280
Total Pages Processed (Data) : 690
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 31
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 558
Total Pages Marked Corrupt : 1
Total Pages Influx : 0
Highest block SCN : 1232338 (0.1232338)
2、rman验证
[oracle@ECP-UC-DB1 ~]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.4.0 – Production on Sun Aug 14 20:39:55 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TEST (DBID=2056006906)
RMAN> backup check logical validate datafile 6;
Starting backup at 2011-08-14 20:40:06
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/opt/oracle/oradata/test/xifenfei01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2011-08-14 20:40:08
RMAN> exit
Recovery Manager complete.
3、直接查询验证
[oracle@ECP-UC-DB1 ~]$ sqlplus chf/xifenfei
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 20:40:14 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select file#,block#,blocks from v$database_block_corruption;
FILE# BLOCK# BLOCKS
———- ———- ———-
6 780 1
SQL> conn / as sysdba
Connected.
SQL> alter system flush BUFFER_CACHE;
System altered.
SQL> select * from chf.t_bbed;
select * from chf.t_bbed
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 780)
ORA-01110: data file 6: ‘/opt/oracle/oradata/test/xifenfei01.dbf’

oracle 10g rman自动创建数据文件

oracle官方建议,如果修改过数据库结构后,需要立即重新备份数据库,我想通过试验验证该知识点。
试验过程是使用rman备份数据库,然后添加表空间,添加数据文件,创建表在新表空间和新数据文件上,然后关闭数据库,删除新添加的数据文件,再使用rman备份来恢复数据库。操作过程如下:

1、当前数据库表空间已经数据文件情况
SQL> select name from v$tablespace;
NAME
——————————
SYSTEM
UNDOTBS1
SYSAUX
USERS
TEMP
SQL> select file#,name from v$datafile;
FILE# NAME
———- ————————————————–
1 /opt/oracle/oradata/test/system01.dbf
2 /opt/oracle/oradata/test/undotbs01.dbf
3 /opt/oracle/oradata/test/sysaux01.dbf
4 /opt/oracle/oradata/test/users01.dbf
5 /opt/oracle/oradata/test/user32g.dbf
2、rman备份数据库
[oracle@ECP-UC-DB1 ~]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.4.0 – Production on Sat Aug 13 21:44:36 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TEST (DBID=2056006906)
RMAN> backup database format ‘/tmp/%U’ plus archivelog delete input;
Starting backup at 2011-08-13 21:46:46
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=3 recid=1 stamp=757977034
input archive log thread=1 sequence=4 recid=2 stamp=758152833
input archive log thread=1 sequence=5 recid=3 stamp=758320953
input archive log thread=1 sequence=6 recid=4 stamp=758321218
input archive log thread=1 sequence=7 recid=5 stamp=758412073
input archive log thread=1 sequence=8 recid=6 stamp=758574035
input archive log thread=1 sequence=9 recid=7 stamp=758665608
input archive log thread=1 sequence=10 recid=8 stamp=758757646
input archive log thread=1 sequence=11 recid=9 stamp=758844058
input archive log thread=1 sequence=12 recid=10 stamp=758930497
input archive log thread=1 sequence=13 recid=11 stamp=759027608
input archive log thread=1 sequence=14 recid=12 stamp=759102408
channel ORA_DISK_1: starting piece 1 at 2011-08-13 21:46:50
channel ORA_DISK_1: finished piece 1 at 2011-08-13 21:47:35
piece handle=/opt/oracle/flash_recovery_area/TEST/backupset/2011_08_13/o1_mf_annnn_TAG20110813T214648_74f02bg3_.bkp tag=TAG20110813T214648 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:46
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/opt/oracle/oradata/test/archivelog/1_3_757860476.dbf recid=1 stamp=757977034
archive log filename=/opt/oracle/oradata/test/archivelog/1_4_757860476.dbf recid=2 stamp=758152833
archive log filename=/opt/oracle/oradata/test/archivelog/1_5_757860476.dbf recid=3 stamp=758320953
archive log filename=/opt/oracle/oradata/test/archivelog/1_6_757860476.dbf recid=4 stamp=758321218
archive log filename=/opt/oracle/oradata/test/archivelog/1_7_757860476.dbf recid=5 stamp=758412073
archive log filename=/opt/oracle/oradata/test/archivelog/1_8_757860476.dbf recid=6 stamp=758574035
archive log filename=/opt/oracle/oradata/test/archivelog/1_9_757860476.dbf recid=7 stamp=758665608
archive log filename=/opt/oracle/oradata/test/archivelog/1_10_757860476.dbf recid=8 stamp=758757646
archive log filename=/opt/oracle/oradata/test/archivelog/1_11_757860476.dbf recid=9 stamp=758844058
archive log filename=/opt/oracle/oradata/test/archivelog/1_12_757860476.dbf recid=10 stamp=758930497
archive log filename=/opt/oracle/oradata/test/archivelog/1_13_757860476.dbf recid=11 stamp=759027608
archive log filename=/opt/oracle/oradata/test/archivelog/1_14_757860476.dbf recid=12 stamp=759102408
Finished backup at 2011-08-13 21:47:36
Starting backup at 2011-08-13 21:47:37
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/opt/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/opt/oracle/oradata/test/sysaux01.dbf
input datafile fno=00002 name=/opt/oracle/oradata/test/undotbs01.dbf
input datafile fno=00005 name=/opt/oracle/oradata/test/user32g.dbf
input datafile fno=00004 name=/opt/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2011-08-13 21:47:37
channel ORA_DISK_1: finished piece 1 at 2011-08-13 21:48:12
piece handle=/tmp/06mjtuvp_1_1 tag=TAG20110813T214737 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2011-08-13 21:48:14
channel ORA_DISK_1: finished piece 1 at 2011-08-13 21:48:15
piece handle=/tmp/07mjtv0s_1_1 tag=TAG20110813T214737 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 2011-08-13 21:48:15
Starting backup at 2011-08-13 21:48:15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=15 recid=13 stamp=759102495
channel ORA_DISK_1: starting piece 1 at 2011-08-13 21:48:16
channel ORA_DISK_1: finished piece 1 at 2011-08-13 21:48:17
piece handle=/opt/oracle/flash_recovery_area/TEST/backupset/2011_08_13/o1_mf_annnn_TAG20110813T214815_74f050vl_.bkp tag=TAG20110813T214815 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/opt/oracle/oradata/test/archivelog/1_15_757860476.dbf recid=13 stamp=759102495
Finished backup at 2011-08-13 21:48:17
3、添加表空间/数据文件
SQL> create tablespace xff datafile ‘/opt/oracle/oradata/test/xifenfei01.dbf’ size 10m autoextend on next 10m maxsize 5G;
Tablespace created.
SQL> alter tablespace users add datafile ‘/opt/oracle/oradata/test/user02.dbf’ size 10m autoextend on next 10m maxsize 5G;
Tablespace altered.
4、创建测试表
SQL> create table chf.t_1 tablespace xff
2 as
3 select * from all_objects;
Table created.
SQL> create table chf.t_2 tablespace users
2 as
3 select * from all_objects;
Table created.
SQL> select count(*) from chf.t_1;
COUNT(*)
———-
49855
SQL> select count(*) from chf.t_2;
COUNT(*)
———-
49856
SQL> select file#,name from v$datafile;
FILE# NAME
———- ————————————————–
1 /opt/oracle/oradata/test/system01.dbf
2 /opt/oracle/oradata/test/undotbs01.dbf
3 /opt/oracle/oradata/test/sysaux01.dbf
4 /opt/oracle/oradata/test/users01.dbf
5 /opt/oracle/oradata/test/user32g.dbf
6 /opt/oracle/oradata/test/xifenfei01.dbf
7 /opt/oracle/oradata/test/user02.dbf
7 rows selected.
5、关闭数据库
SQL> shutdown abort
ORACLE instance shut down.
6、删除相关数据文件
[oracle@ECP-UC-DB1 ~]$ cd /opt/oracle/oradata/test/
[oracle@ECP-UC-DB1 test]$ ll
total 1066968
drwxr-xr-x 2 oracle oinstall 4096 Aug 13 21:48 archivelog
-rw-r—– 1 oracle oinstall 7061504 Aug 13 21:56 control01.ctl
-rw-r—– 1 oracle oinstall 7061504 Aug 13 21:56 control02.ctl
-rw-r—– 1 oracle oinstall 7061504 Aug 13 21:56 control03.ctl
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:55 redo01.log
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:46 redo02.log
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:48 redo03.log
-rw-r—– 1 oracle oinstall 335552512 Aug 13 21:48 sysaux01.dbf
-rw-r—– 1 oracle oinstall 513810432 Aug 13 21:55 system01.dbf
-rw-r—– 1 oracle oinstall 20979712 Aug 13 06:00 temp01.dbf
-rw-r—– 1 oracle oinstall 26222592 Aug 13 21:55 undotbs01.dbf
-rw-r—– 1 oracle oinstall 10493952 Aug 13 21:55 user02.dbf
-rw-r—– 1 oracle oinstall 10493952 Aug 13 21:55 user32g.dbf
-rw-r—– 1 oracle oinstall 5251072 Aug 13 21:55 users01.dbf
-rw-r—– 1 oracle oinstall 10493952 Aug 13 21:55 xifenfei01.dbf
[oracle@ECP-UC-DB1 test]$ rm xifenfei01.dbf
[oracle@ECP-UC-DB1 test]$ rm user*.dbf
[oracle@ECP-UC-DB1 test]$ ll
total 1031036
drwxr-xr-x 2 oracle oinstall 4096 Aug 13 21:48 archivelog
-rw-r—– 1 oracle oinstall 7061504 Aug 13 21:56 control01.ctl
-rw-r—– 1 oracle oinstall 7061504 Aug 13 21:56 control02.ctl
-rw-r—– 1 oracle oinstall 7061504 Aug 13 21:56 control03.ctl
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:55 redo01.log
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:46 redo02.log
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:48 redo03.log
-rw-r—– 1 oracle oinstall 335552512 Aug 13 21:48 sysaux01.dbf
-rw-r—– 1 oracle oinstall 513810432 Aug 13 21:55 system01.dbf
-rw-r—– 1 oracle oinstall 20979712 Aug 13 06:00 temp01.dbf
-rw-r—– 1 oracle oinstall 26222592 Aug 13 21:55 undotbs01.dbf
6、开启数据库
SQL> startup
ORACLE instance started.
Total System Global Area 209715200 bytes
Fixed Size 2082784 bytes
Variable Size 125831200 bytes
Database Buffers 75497472 bytes
Redo Buffers 6303744 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 – see DBWR trace file
ORA-01110: data file 4: ‘/opt/oracle/oradata/test/users01.dbf’
7、alert.log文件报错
Sat Aug 13 21:58:22 2011
ALTER DATABASE OPEN
Sat Aug 13 21:58:22 2011
Errors in file /opt/oracle/admin/test/bdump/test_dbw0_25268.trc:
ORA-01157: cannot identify/lock data file 4 – see DBWR trace file
ORA-01110: data file 4: ‘/opt/oracle/oradata/test/users01.dbf’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Sat Aug 13 21:58:22 2011
Errors in file /opt/oracle/admin/test/bdump/test_dbw0_25268.trc:
ORA-01157: cannot identify/lock data file 5 – see DBWR trace file
ORA-01110: data file 5: ‘/opt/oracle/oradata/test/user32g.dbf’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Sat Aug 13 21:58:22 2011
Errors in file /opt/oracle/admin/test/bdump/test_dbw0_25268.trc:
ORA-01157: cannot identify/lock data file 6 – see DBWR trace file
ORA-01110: data file 6: ‘/opt/oracle/oradata/test/xifenfei01.dbf’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Sat Aug 13 21:58:22 2011
Errors in file /opt/oracle/admin/test/bdump/test_dbw0_25268.trc:
ORA-01157: cannot identify/lock data file 7 – see DBWR trace file
ORA-01110: data file 7: ‘/opt/oracle/oradata/test/user02.dbf’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-1157 signalled during: ALTER DATABASE OPEN…
8、登录rman
[oracle@ECP-UC-DB1 test]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.4.0 – Production on Sat Aug 13 22:00:03 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TEST (DBID=2056006906, not open)
9、rman还原预览
RMAN> restore datafile 4,5,6,7 preview;
Starting restore at 2011-08-13 22:01:29
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
data file 6 will be created automatically during restore operation
data file 7 will be created automatically during restore operation
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— ——————-
4 Full 602.67M DISK 00:00:30 2011-08-13 21:47:38
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20110813T214737
Piece Name: /tmp/06mjtuvp_1_1
List of Datafiles in backup set 4
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——————- —-
4 Full 1177858 2011-08-13 21:47:37 /opt/oracle/oradata/test/users01.dbf
5 Full 1177858 2011-08-13 21:47:37 /opt/oracle/oradata/test/user32g.dbf
using channel ORA_DISK_1
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— ——————-
6 2.00K DISK 00:00:01 2011-08-13 21:48:16
BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20110813T214815
Piece Name: /opt/oracle/flash_recovery_area/TEST/backupset/2011_08_13/o1_mf_annnn_TAG20110813T214815_74f050vl_.bkp
List of Archived Logs in backup set 6
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——————- ———- ———
1 15 1177835 2011-08-13 21:46:46 1177874 2011-08-13 21:48:15
Media recovery start SCN is 1177858
Recovery must be done beyond SCN 1178068 to clear data files fuzziness
Finished restore at 2011-08-13 22:01:30
10、还原数据文件
RMAN> restore datafile 4,5,6,7;
Starting restore at 2011-08-13 22:02:04
using channel ORA_DISK_1
creating datafile fno=6 name=/opt/oracle/oradata/test/xifenfei01.dbf
creating datafile fno=7 name=/opt/oracle/oradata/test/user02.dbf
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /opt/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /opt/oracle/oradata/test/user32g.dbf
channel ORA_DISK_1: reading from backup piece /tmp/06mjtuvp_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/tmp/06mjtuvp_1_1 tag=TAG20110813T214737
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 2011-08-13 22:02:08
11、查看恢复后的数据文件情况
[oracle@ECP-UC-DB1 ~]$ cd /opt/oracle/oradata/test
[oracle@ECP-UC-DB1 test]$ ll
total 1066968
drwxr-xr-x 2 oracle oinstall 4096 Aug 13 21:48 archivelog
-rw-r—– 1 oracle oinstall 7061504 Aug 13 22:03 control01.ctl
-rw-r—– 1 oracle oinstall 7061504 Aug 13 22:03 control02.ctl
-rw-r—– 1 oracle oinstall 7061504 Aug 13 22:03 control03.ctl
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:55 redo01.log
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:46 redo02.log
-rw-r—– 1 oracle oinstall 52429312 Aug 13 21:48 redo03.log
-rw-r—– 1 oracle oinstall 335552512 Aug 13 21:58 sysaux01.dbf
-rw-r—– 1 oracle oinstall 513810432 Aug 13 21:58 system01.dbf
-rw-r—– 1 oracle oinstall 20979712 Aug 13 06:00 temp01.dbf
-rw-r—– 1 oracle oinstall 26222592 Aug 13 21:58 undotbs01.dbf
-rw-r—– 1 oracle oinstall 10493952 Aug 13 22:02 user02.dbf
-rw-r—– 1 oracle oinstall 10493952 Aug 13 22:02 user32g.dbf
-rw-r—– 1 oracle oinstall 5251072 Aug 13 22:02 users01.dbf
-rw-r—– 1 oracle oinstall 10493952 Aug 13 22:02 xifenfei01.dbf
12、恢复数据文件
RMAN> recover datafile 4,5,6,7;
Starting recover at 2011-08-13 22:04:21
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:04
Finished recover at 2011-08-13 22:04:25
13、open数据库
RMAN> alter database open;
database opened
RMAN> exit
Recovery Manager complete.
14、验证rman恢复结果
[oracle@ECP-UC-DB1 test]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Sat Aug 13 22:05:25 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select file#,name from v$datafile;
FILE# NAME
———- ————————————————–
1 /opt/oracle/oradata/test/system01.dbf
2 /opt/oracle/oradata/test/undotbs01.dbf
3 /opt/oracle/oradata/test/sysaux01.dbf
4 /opt/oracle/oradata/test/users01.dbf
5 /opt/oracle/oradata/test/user32g.dbf
6 /opt/oracle/oradata/test/xifenfei01.dbf
7 /opt/oracle/oradata/test/user02.dbf
7 rows selected.
SQL> select count(*) from chf.t_1;
COUNT(*)
———-
49855
SQL> select count(*) from chf.t_2;
COUNT(*)
———-
49856
注:如果在rman的还原过程中,没有自动创建数据文件,需要用命令创建alter database datafile n或者alter database datafile ‘path’,然后进行恢复