恢复之数据文件

来源:互联网 发布:单位矩阵 编辑:程序博客网 时间:2024/05/29 16:52

模拟破坏
--仍然联机
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE
--触发报错
SQL> select count(*) from tabs;
select count(*) from tabs
                     *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01115: IO error reading block from file  (block # )
ORA-01110: data file 1: '/home/gyh/oracle/oradata/orcl/system01.dbf'
ORA-27072: File I/O error
Additional information: 4
Additional information: 8721
--不能正常关闭
SQL> shutdown immediate
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/home/gyh/oracle/oradata/orcl/system01.dbf'
ORA-01210: data file header is media corrupt
SQL> conn /as sysdba;
Connected.
--只能关闭实例
SQL> shutdown abort
ORACLE instance shut down.
SQL> conn /as sysdba;
Connected.
--mount状态
RMAN> startup mount;

Oracle instance started
database mounted

Total System Global Area     417546240 bytes

Fixed Size                     2228944 bytes
Variable Size                331353392 bytes
Database Buffers              75497472 bytes
Redo Buffers                   8466432 bytes
--还原数据文件
RMAN> restore datafile 1,4;

Starting restore at 06-NOV-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /home/gyh/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/gyh/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/gyh/oracle/fast_recovery_area/ORCL/backupset/2012_11_06/o1_mf_nnndf_TAG20121106T213136_89mwkrr9_.bkp
channel ORA_DISK_1: piece handle=/home/gyh/oracle/fast_recovery_area/ORCL/backupset/2012_11_06/o1_mf_nnndf_TAG20121106T213136_89mwkrr9_.bkp tag=TAG20121106T213136
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 06-NOV-12
--打不开
RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 11/06/2012 22:03:14
ORA-01172: recovery of thread 1 stuck at block 3122 of file 1
ORA-01151: use media recovery to recover block, restore backup if needed

--必须应用在线日志,归档日志恢复
RMAN> recover datafile 1,4;

Starting recover at 06-NOV-12
using channel ORA_DISK_1

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

Finished recover at 06-NOV-12
--打开完成恢复
RMAN> alter database open;

database opened
总结:不需要日志重置即resetlogs方式打开,破坏数据文件不会立即hang住 

--模拟丢失
[oracle@linuxoracle orcl]$ rm -rf system01.dbf
[oracle@linuxoracle orcl]$ rm -rf user01.dbf
--直接crash
SQL> conn /as sysdba;
Connected to an idle instance.
SQL> startup mount
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area  417546240 bytes
Fixed Size                  2228944 bytes
Variable Size             318770480 bytes
Database Buffers           88080384 bytes
Redo Buffers                8466432 bytes
Database mounted.
RMAN> restore datafile 1,4;

Starting restore at 06-NOV-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=135 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /home/gyh/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/gyh/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/gyh/oracle/fast_recovery_area/ORCL/backupset/2012_11_06/o1_mf_nnndf_TAG20121106T213136_89mwkrr9_.bkp
channel ORA_DISK_1: piece handle=/home/gyh/oracle/fast_recovery_area/ORCL/backupset/2012_11_06/o1_mf_nnndf_TAG20121106T213136_89mwkrr9_.bkp tag=TAG20121106T213136
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 06-NOV-12

RMAN> recover datafile 1,4;

Starting recover at 06-NOV-12
using channel ORA_DISK_1

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

Finished recover at 06-NOV-12

RMAN> alter database open;

database opened

RMAN>