代码改变世界

Oracle Recovery 01 - 常规恢复之完全恢复

2015-08-07 11:49  AlfredZhao  阅读(4214)  评论(2编辑  收藏  举报

背景:这里提到的常规恢复指的是数据库有完备可用的RMAN物理备份。
实验环境:RHEL6.4 + Oracle 11.2.0.4 DG primary.

一、常规恢复之完全恢复:不丢失数据

一、常规恢复之完全恢复:不丢失数据

Oracle 数据库常规恢复的几个概念:

常规恢复之完全恢复:不丢失数据。
比如数据文件丢失,临时文件丢失,参数文件丢失。可以通过RMAN备份完全恢复数据库。
示例:Oracle Recovery 01 - 常规恢复之完全恢复

常规恢复之不完全恢复:部分数据丢失。
一般是有控制文件或是在线重做日志文件丢失。通过RMAN备份恢复,resetlogs会导致丢失数据。
示例:Oracle Recovery 02 - 常规恢复之不完全恢复

1.1 单个数据文件丢失或损坏

### 启动数据库报错: ###
SQL> startup
ORACLE instance started.

Total System Global Area 1620115456 bytes
Fixed Size                  2253704 bytes
Variable Size             905972856 bytes
Database Buffers          704643072 bytes
Redo Buffers                7245824 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 15 - see DBWR trace file
ORA-01110: data file 15: '+DATA1/jyzhao/datafile/dbs_d_jingyu.259.886871319'

恢复方法:

RMAN>
   restore datafile 15;
   recover datafile 15;
   sql 'alter database datafile 15 online';
   sql 'alter database open';

1.2 所有数据文件丢失或损坏

### 启动数据库报错: ###
SQL> startup          
ORACLE instance started.

Total System Global Area 1620115456 bytes
Fixed Size                  2253704 bytes
Variable Size             905972856 bytes
Database Buffers          704643072 bytes
Redo Buffers                7245824 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '+DATA1/jyzhao/datafile/system.278.886441901'

恢复方法:

RMAN>
   restore database;
   recover database;
   sql 'alter database open';

1.3 参数文件丢失或损坏

### 启动数据库报错: ###
SQL> startup 
ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file '+DATA1/jyzhao/spfilejyzhao.ora'
ORA-17503: ksfdopn:2 Failed to open file +DATA1/jyzhao/spfilejyzhao.ora
ORA-15056: additional error message
ORA-17503: ksfdopn:2 Failed to open file +DATA1/jyzhao/spfilejyzhao.ora
ORA-15173: entry 'spfilejyzhao.ora' does not exist in directory 'jyzhao'
ORA-06512: at line 4

恢复方法:

1)vi编辑初始化参数文件,指定db_name, control_files,compatible
vi /u01/app/oracle/product/11.2.0/db_1/dbs/init86.ora

db_name='jyzhao'
control_files = '+DATA1/JYZHAO/CONTROLFILE/Current.260.874084673'
compatible ='11.2.0.4'

2)启动到mount状态

SQL> startup mount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/init86.ora'

3)RMAN恢复spfile文件

RMAN> restore spfile from autobackup;

4)关库重新用恢复的spfile文件启动数据库

SQL> shutdown abort
SQL> startup

1.4 参数文件,数据文件丢失或损坏

启动数据库报错:

综合考虑1.3,1.2,1.1的内容。

恢复方法:

先按照1.3恢复参数文件,再根据实际情况选择1.1或1.2。

1.5 临时文件丢失或损坏

重启库之后自动重建临时文件并成功open数据库。 可以在alert.log看到如下一段日志:
[8440] Successfully onlined Undo Tablespace 2.
Undo initialization finished serial:0 start:348324004 end:348324254 diff:250 (2 seconds)
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Re-creating tempfile +DATA1/jyzhao/tempfile/temp.264.874084679 as +DATA1/jyzhao/tempfile/temp.264.887107953
Database Characterset is ZHS16GBK
No Resource Manager plan active
Archived Log entry 1162 added for thread 1 sequence 883 ID 0x93779c13 dest 1:
ARC1: Standby redo logfile selected for thread 1 sequence 883 for destination LOG_ARCHIVE_DEST_2
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Fri Aug 07 10:52:33 2015
QMNC started with pid=38, OS id=8605 
ARC3: Archival started
ARC0: STARTING ARCH PROCESSES COMPLETE
Completed: ALTER DATABASE OPEN