oracle user-maneged recovery(一)
一.非归档模式关闭数据库的恢复
1.shutdown immediate; 关闭数据库
2.使用操作系统命令拷贝最新的备份(数据文件和控制文件,如果备份了日志文件)
3.进行不完全恢复recover database until cancel using backup;
4.重置日志打开数据库alter database open resetlogs;
二.数据文件离线或者表空间离线的恢复
SQL> create table t1 tablespace tbs_sf as select * from dba_objects; --创建测试表到指定表空间
SQL> select file_id,file_name from dba_data_files where TABLESPACE_NAME='TBS_SF'; --可以看到数据文件时26号
FILE_ID FILE_NAME
---------- --------------------------------------------------
26 /database/oradata/skyread/sf01.dbf
SQL> alter database datafile 26 offline drop; --数据文件脱机,这里是模拟故障,恢复的时候相当于从备份拷贝一个新文件回来
Database altered.
SQL> select count(*) from t1; --可见无法查看该表空间的表
select count(*) from t1
*
ERROR at line 1:
ORA-00376: file 26 cannot be read at this time
ORA-01110: data file 26: '/database/oradata/skyread/sf01.dbf'
SQL> select hxfil file_id,fhsta status,fhscn scn,fhrba_seq seq from x$kcvfh where hxfil=26;
FILE_ID STATUS SCN SEQ
---------- ---------- ---------------- ----------
26 4 122693804311 2
SQL> select GROUP#,BYTES,ARCHIVED,STATUS,SEQUENCE# from v$log; --可见红色的日志没有被覆盖,可以进行恢复
GROUP# BYTES ARC STATUS SEQUENCE#
---------- ---------- --- ---------------- ----------
1 536870912 YES INACTIVE 1
2 536870912 NO CURRENT 2
3 536870912 YES UNUSED 0
4 536870912 YES UNUSED 0
5 536870912 YES UNUSED 0
SQL> recover datafile 26; --进行恢复
Media recovery complete.
SQL> alter database datafile 26 online;
Database altered.
SQL> select count(*) from t1;
COUNT(*)
----------
50483
三.归档模式下进行完全恢复
条件:
1.设置为归档后的进行的有效备份
2.有效备份至今所有的归档都在
3.没有归档的重做日志文件
优点:
1.只需要恢复损坏的文件
2.提交的数据不会丢失
3.可以在数据库打开的时候进行恢复(非system空间和undo空间)
SQL> alter database datafile 26 offline drop; --模拟故障,数据文件损坏
Database altered.
SQL> select GROUP#,BYTES,ARCHIVED,STATUS,SEQUENCE# from v$log;
GROUP# BYTES ARC STATUS SEQUENCE#
---------- ---------- --- ---------------- ----------
1 536870912 YES INACTIVE 1
2 536870912 NO CURRENT 2
3 536870912 YES UNUSED 0
4 536870912 YES UNUSED 0
5 536870912 YES UNUSED 0
SQL> select * from v$recover_file;--查看进行恢复是需要恢复的数据文件
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
-------------------- ------- ------- --------------------------- -------------------
26 OFFLINE OFFLINE 122693905229 2013-04-27 15:05:39
SQL> alter system switch logfile; --多做几次,把序列为2的日志覆盖掉
SQL> select GROUP#,BYTES,ARCHIVED,STATUS,SEQUENCE# from v$log; --已经覆盖掉
GROUP# BYTES ARC STATUS SEQUENCE#
-------------------- -------------------- --- ---------------- --------------------
1 536870912 YES ACTIVE 6
2 536870912 NO CURRENT 7
3 536870912 YES INACTIVE 3
4 536870912 YES ACTIVE 4
5 536870912 YES ACTIVE 5
SQL> select * from v$recovery_log;--查看进行恢复是需要的归档
THREAD# SEQUENCE# TIME ARCHIVE_NAME
-------------------- -------------------- ------------------- --------------------------------------------------
1 2 2013-04-25 16:24:26 /database/oradata/arch/1_2_813495053.dbf
SQL> recover automatic datafile 26; --使用auto模式,自动应用归档和重做日志文件恢复数据文件
Media recovery comple