ORACLE中没有参数文件和控制文件如何通过rman恢复数据库

场景:

一个DEV告诉我生产环境下某个用户的表都看不到了,需要恢复,而此时生产库上存储自动备份的参数文件控制文件的磁盘目录文件坏块,所以导致rman备份的只有数据文件和归档日志文件,这种情况下,如何在测试服务器上利用rman恢复数据呢?google了很多资料,咨询了朋友,恢复过程如下:

前期准备工作:
事先查询好先查询下原来的数据文件路径
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/home/oradata/stuorcl/system01.dbf
/home/oradata/stuorcl/sysaux01.dbf
/home/oradata/stuorcl/undotbs01.dbf
/home/oradata/stuorcl/users01.dbf
/home/oradata/stuorcl/stuorclk01.dbf
/home/oradata/stuorcl/plas01.dbf
/home/oradata/stuorcl/pl01.dbf
/home/oradata/stuorcl/help01.dbf
/home/oradata/stuorcl/adobelc01.dbf
/home/oradata/stuorcl/sms01.dbf

10 rows selected.

SQL>

事先获得redo日志文件路径
SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/home/oradata/stuorcl/redo03.log
/home/oradata/stuorcl/redo02.log
/home/oradata/stuorcl/redo01.log
/home/oradata/stuorcl/redo_dg_01.log
/home/oradata/stuorcl/redo_dg_02.log
/home/oradata/stuorcl/redo_dg_03.log

6 rows selected.

SQL>

1,nomount下创建控制文件;
[[email protected] ~]# su - oracle
[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Feb 4 13:48:23 2015

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

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

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

2,启动到nomount状态
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1.1358E+10 bytes
Fixed Size    2216744 bytes
Variable Size 8589937880 bytes
Database Buffers 2751463424 bytes
Redo Buffers   13946880 bytes
SQL>

3,创建控制文件

CREATE CONTROLFILE REUSE set DATABASE "stuorcl" RESETLOGS ARCHIVELOG
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 100
   MAXINSTANCES 8
   MAXLOGHISTORY 454
DATAFILE
‘/home/oradata/stuorcl/system01.dbf‘,
‘/home/oradata/stuorcl/sysaux01.dbf‘,
‘/home/oradata/stuorcl/undotbs01.dbf‘,
‘/home/oradata/stuorcl/users01.dbf‘,
‘/home/oradata/stuorcl/stuorclk01.dbf‘,
‘/home/oradata/stuorcl/plas01.dbf‘,
‘/home/oradata/stuorcl/pl01.dbf‘,
‘/home/oradata/stuorcl/help01.dbf‘,
‘/home/oradata/stuorcl/adobelc01.dbf‘,
‘/home/oradata/stuorcl/sms01.dbf‘
LOGFILE
GROUP 1 (‘/home/oradata/stuorcl/redo03.log‘)  SIZE 10M,
GROUP 2 (‘/home/oradata/stuorcl/redo02.log‘)  SIZE 10M,
GROUP 3 (‘/home/oradata/stuorcl/redo01.log‘)  SIZE 10M,
GROUP 4 (‘/home/oradata/stuorcl/redo_dg_01.log‘)  SIZE 10M,
GROUP 5 (‘/home/oradata/stuorcl/redo_dg_02.log‘)  SIZE 10M,
GROUP 6 (‘/home/oradata/stuorcl/redo_dg_03.log‘)  SIZE 10M
CHARACTER SET ZHS16GBK;

执行过程:
SQL> CREATE CONTROLFILE REUSE set DATABASE "stuorcl" RESETLOGS ARCHIVELOG
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 100
   MAXINSTANCES 8
   MAXLOGHISTORY 454
DATAFILE
‘/home/oradata/stuorcl/system01.dbf‘,
‘/home/oradata/stuorcl/sysaux01.dbf‘,
 2    3    4    5    6    7    8    9   10  ‘/home/oradata/stuorcl/undotbs01.dbf‘,
‘/home/oradata/stuorcl/users01.dbf‘,
‘/home/oradata/stuorcl/stuorclk01.dbf‘,
‘/home/oradata/stuorcl/plas01.dbf‘,
‘/home/oradata/stuorcl/pl01.dbf‘,
‘/home/oradata/stuorcl/help01.dbf‘,
‘/home/oradata/stuorcl/adobelc01.dbf‘,
‘/home/oradata/stuorcl/sms01.dbf‘
LOGFILE
GROUP 1 (‘/home/oradata/stuorcl/redo03.log‘)  SIZE 10M,
GROUP 2 (‘/home/oradata/stuorcl/redo02.log‘)  SIZE 10M,
GROUP 3 (‘/home/oradata/stuorcl/redo01.log‘)  SIZE 10M,
GROUP 4 (‘/home/oradata/stuorcl/redo_dg_01.log‘)  SIZE 10M,
GROUP 5 (‘/home/oradata/stuorcl/redo_dg_02.log‘)  SIZE 10M,
GROUP 6 (‘/home/oradata/stuorcl/redo_dg_03.log‘)  SIZE 10M
CHARACTER SET ZHS16GBK; 11   12   13   14   15   16   17   18   19   20   21   22   23   24   25

Control file created.

SQL>

4,在新控制文件中注册数据文件备份和归档备份

catalog start with ‘/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/‘;
在mount状态下执行
RMAN> catalog start with ‘/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/‘;

released channel: ORA_DISK_1
searching for all files that match the pattern /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/

List of Files Unknown to the Database
=====================================
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/rman_backup.log
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3050.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3050.bak
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak

List of Files Which Where Not Cataloged
=======================================
File Name: /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/rman_backup.log
  RMAN-07517: Reason: The file header is corrupted

RMAN>

5,进行修复操作
RMAN>  restore database;

Starting restore at 04-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=767 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/oradata/stuorcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /home/oradata/stuorcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /home/oradata/stuorcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/oradata/stuorcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /home/oradata/stuorcl/stuorclk01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /home/oradata/stuorcl/plas01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /home/oradata/stuorcl/pl01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /home/oradata/stuorcl/help01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /home/oradata/stuorcl/adobelc01.dbf
channel ORA_DISK_1: restoring datafile 00010 to /home/oradata/stuorcl/sms01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak
channel ORA_DISK_1: piece handle=/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/full_stuorcl_20150123_3051.bak tag=TAG20150123T030053
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:45:45
Finished restore at 04-FEB-15

RMAN>

此时去看oracle后台的alert日志,正在一个个修复数据文件,信息如下:
[[email protected] trace]# tail -f /oracle/app/oracle/diag/rdbms/stuunq/stuorcl/trace/alert_stuorcl.log 
GROUP 5 (‘/home/oradata/stuorcl/redo_dg_02.log‘)  SIZE 10M,
GROUP 6 (‘/home/oradata/stuorcl/redo_dg_03.log‘)  SIZE 10M
CHARACTER SET ZHS16GBK
Wed Feb 04 17:05:40 2015
alter database mount
ORA-1100 signalled during: alter database mount
...
Wed Feb 04 17:05:55 2015
alter database mount
ORA-1100 signalled during: alter database mount...
Wed Feb 04 17:08:38 2015
Full restore complete of datafile 8 /home/oradata/stuorcl/help01.dbf.  Elapsed time: 0:00:02 
  checkpoint is 10903299975
  last deallocation scn is 9881798870
Full restore complete of datafile 9 /home/oradata/stuorcl/adobelc01.dbf.  Elapsed time: 0:00:00 
  checkpoint is 10903299975
Wed Feb 04 17:08:53 2015
Full restore complete of datafile 10 /home/oradata/stuorcl/sms01.dbf.  Elapsed time: 0:00:07 
  checkpoint is 10903299975
Wed Feb 04 17:09:52 2015
Full restore complete of datafile 7 /home/oradata/stuorcl/pl01.dbf.  Elapsed time: 0:00:46 
  checkpoint is 10903299975
  last deallocation scn is 10891613103
Wed Feb 04 17:12:41 2015
Full restore complete of datafile 3 /home/oradata/stuorcl/undotbs01.dbf.  Elapsed time: 0:03:28 
  checkpoint is 10903299975
  last deallocation scn is 10903242336
  Undo Optimization current scn is 10903252140
Wed Feb 04 17:14:00 2015
Full restore complete of datafile 4 /home/oradata/stuorcl/users01.dbf.  Elapsed time: 0:05:26 
  checkpoint is 10903299975
  last deallocation scn is 10893349080
Wed Feb 04 17:17:52 2015
Full restore complete of datafile 1 /home/oradata/stuorcl/system01.dbf.  Elapsed time: 0:08:11 
  checkpoint is 10903299975
  last deallocation scn is 10825889348
  Undo Optimization current scn is 10903252140
Wed Feb 04 17:20:27 2015
db_recovery_file_dest_size of 15360 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Wed Feb 04 17:20:40 2015
Full restore complete of datafile 2 /home/oradata/stuorcl/sysaux01.dbf.  Elapsed time: 0:12:02 
  checkpoint is 10903299975
  last deallocation scn is 10901674267
  ........

6,开始恢复操作
RMAN>  recover database;

Starting recover at 04-FEB-15
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=29053
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak
channel ORA_DISK_1: piece handle=/oracle/app/oracle/flash_recovery_area/stuorcl/backupset/2015-01-23/arch_stuorcl_20150123_3052.bak tag=TAG20150123T032709
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archived log file name=/oracle/app/oracle/flash_recovery_area/archivelog/1_29053_821708334.dbf thread=1 sequence=29053
unable to find archived log
archived log thread=1 sequence=29054
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2015 16:19:14
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 29054 and starting SCN of 10903302108

RMAN>

在11g官方文档error messages中对错误描述如下:
RMAN-06054: media recovery requesting unknown archived log for thread string with sequence string and starting SCN of string
Cause: Media recovery is requesting a log whose existence is not recorded in the recovery catalog or target database control file.
Action: If a copy of the log is available, then add it to the recovery catalog and/or control file via a CATALOG command and then retry the RECOVER command. If not, then a point-in-time recovery up to the missing log is the only alternative and database can be opened using ALTER DATABASE OPEN RESETLOGS command.

可见,出先此错误的原因是恢复需要的日志记录在控制文件或恢复目录中找不到。解决方法分两种情况:
1.如果相关的日志存在且可用的话,就将此日志记录添加到控制文件或恢复目录中。
2.如果相关的日志已经被删除了或不可用了,那么就按照错误的提示scn将数据库恢复到此scn,本案例是10903302108。也就是说此时数据库只能进行不完全恢复了,在打开数据库时得使用resetlogs打开。

recover database until scn 10903302108;
RMAN> recover database until scn 10903302108;

Starting recover at 04-FEB-15
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2015 16:30:30
RMAN-20208: UNTIL CHANGE is before RESETLOGS change

RMAN>

List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
2       2       stuorcl 3391761643       PARENT  945184     25-JUL-13
1       1       stuorcl 3391761643       CURRENT 10909913627 02-FEB-15

RMAN> 
google下,看到http://blog.itpub.net/26442936/viewspace-767439/上面有说明
RMAN> reset database to incarnation 2;
RMAN> restore database until scn 1045382;
RMAN> recover database until scn 1045382;
SQL> alter database open resetlogs;
的方式,不过我的incarnation 2已经是2013年的太早了,这种方式不适合。

尝试rman的不完全恢复记录,切换到SQL窗口去:
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 10903299975 generated at 01/23/2015 03:00:53 needed for
thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/archivelog/1_29053_821708334.dbf
ORA-00280: change 10903299975 for thread 1 is in sequence #29053

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change 10903302108 generated at 01/23/2015 03:27:09 needed for
thread 1
ORA-00289: suggestion :
/oracle/app/oracle/flash_recovery_area/archivelog/1_29054_821708334.dbf
ORA-00280: change 10903302108 for thread 1 is in sequence #29054
ORA-00278: log file
‘/oracle/app/oracle/flash_recovery_area/archivelog/1_29053_821708334.dbf‘ no
longer needed for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log
‘/oracle/app/oracle/flash_recovery_area/archivelog/1_29054_821708334.dbf‘
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log
‘/oracle/app/oracle/flash_recovery_area/archivelog/1_29054_821708334.dbf‘
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL>

SQL> alter database open resetlogs;

Database altered.

SQL>

7,去后台验证下数据,找一张一直有日期变化的表数据:
SQL> select  to_char(a.last_login_date,‘yyyy-mm-dd hh24:mi:ss‘) from stu.pst_ac a where to_char(a.last_login_date,‘yyyy-mm-dd hh24:mi:ss‘)>‘2015-01-23 00:00:00:00‘ order by to_char(a.last_login_date,‘yyyy-mm-dd hh24:mi:ss‘)  desc;

TO_CHAR(A.LAST_LOGI
-------------------
2015-01-23 03:10:38
2015-01-23 02:36:13
2015-01-23 01:47:36
2015-01-23 01:29:14
2015-01-23 01:27:41
2015-01-23 01:09:21
2015-01-23 00:52:14
2015-01-23 00:44:52
2015-01-23 00:43:46
2015-01-23 00:32:37
2015-01-23 00:31:59

TO_CHAR(A.LAST_LOGI
-------------------
2015-01-23 00:30:44
2015-01-23 00:27:27
2015-01-23 00:23:20
2015-01-23 00:18:53
2015-01-23 00:17:46
2015-01-23 00:13:25
2015-01-23 00:00:15

18 rows selected.

SQL> 
看到最新为1月23日的数据,表明恢复的数据已经是1月23日的。

去[[email protected] admin]$ sqlplus elearning/[email protected]_SID;

SQL*Plus: Release 11.2.0.1.0 Production on Wed Feb 4 19:03:56 2015

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

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

SQL> select ut.TABLE_NAME from user_tables ut where rownum<3;

no rows selected

----------------------------------------------------------------------------------------------------------------
<版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!>
原博客地址:    http://blog.itpub.net/26230597/viewspace-1426675/
原作者:黄杉 (mchdba)
----------------------------------------------------------------------------------------------------------------
SQL> 
没有一条表记录,所以还是需要找找原因,为什么用户下的表看不见了,~_~。

时间: 2024-12-24 19:29:13

ORACLE中没有参数文件和控制文件如何通过rman恢复数据库的相关文章

【Oracle】数据库启动阶段参数文件、控制文件的问题处理

Oracle启动分三个阶段: nomount: 首先查找参数文件(pfile/spfile),根据文件创建实例.Nomount的过程是启动数据库实例的过程. 没有参数文件无法nomount mount: 从参数文件中获得控制文件的位置信息,然后打开控制文件. --没有控制文件无法mount open: 打开控制文件中所有描述的文件. --没有数据文件无法open -------------------------------------------------------------------

批量迁移Oracle数据文件,日志文件及控制文件

有些时候需要将Oracle的多个数据文件以及日志文件重定位或者迁移到新的分区或新的位置,比如磁盘空间不足,或因为特殊需求.对于这种情形可以采取批量迁移的方式将多个数据文件或者日志文件实现一次性迁移.当然备份恢复也是其中的方式之一.本文主要描述如何使用批量方式来迁移数据文件,日志文件.如需要也可以将整个数据库迁移到新的位置以及重命名数据库. [sql] view plain copy print? 1.环境及需求 [email protected]:~> cat /etc/issue Welcom

同时丢失参数文件、控制文件及redo log file的不完全恢复(有数据文件的热备和归档)

转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/30839817 ##########恢复前的准备工作 1.做个热备 select 'alter tablespace '||tablespace_name|| ' begin backup;' ||chr(10)|| 'host cp '||file_name||' /backup' ||chr(10)|| 'alter tablespace '||tablespace_name|| '

遇到ORA-01207: 文件比控制文件更新 - 旧的控制文件解决办法-简单版

遇到这样的问题,如ORA-01207: 文件比控制文件更新 - 旧的控制文件 解决问题的思路是重建控制文件 注意: 1.不知道会不会丢一小部分数据.适用于不重要的库和已经停机的业务,或者急救业务. 可以尝试从不同的地方找原来的control文件,几个不同的control文件如果都一样,说明只能这么恢复,如果不一样,尽量找系统表空间比较新的control去用,因为不涉及用户数据. 2.做之前保存之前的控制文件!!!! 报错如下: SQL>startupORACLE 例程已经启动.Total Sys

数据库数据文件和控制文件恢复

数据库数据文件和控制文件恢复一次数据库数据文件和控制文件丢失或未创建恢复数据库启动方法该文档适用数据恢复:数据库安装的时候丢失控制文件和数据文件或者数据库故障的数据.控制文件丢失或者数据库的本来数据.控制文件丢失有备份文件,用备份文件恢复本文的环境变量ORACLE_BASE=/oo/oracleORACLE_HOME=/oo/oracle/11g 1.数据库启动报错数据库启动时报错: 报错1: SQL> startup ORA-01261: Parameter db_recovery_file_

Oracle RMAN 恢复数据库到不同主机(二)

我们在recover database时报一个错误: RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 149 and starting SCN of 3507749 这里是提醒恢复到一个未知的scn号.我们在备份时只有148号归档,149号还是online redo,所以没有copy过来,如果我们不指定recover的结束时间,最后就会提示我们上面的信息:RMAN-0605

oracle参数文件、控制文件、数据文件、日志文件的位置及查询方法

参数文件:所有参数文件一般在  $ORACLE_HOME/dbs 下 sqlplus查询语句:show parameter spfile; 网络连接文件: $ORACLE_HOME/dbs/network/admin 目录中 控制文件:select * from v$controlfile; 数据文件:一般在oracledata/实例名  目录下 select FILE_NAME from dba_data_files; 日志文件:一般在oracledata/实例名  目录下 select *

oracle之 利用 controlfile trace文件重建控制文件

一. 11g RAC 重建控制文件 1. --"create controlfile"命令生成到追踪文件中:alter database backup controlfile to trace; 2. --确认追踪文件的路径:SQL> select value from v$diag_info where name='Default Trace File'; 3. -- 截取脚本 在追踪文件中找到并执行NORESETLOGS版本的"create controlfile&

RMAN备份与恢复之参数文件与控制文件

0   说明 本例是基于备份数据库全库的基础上,还原参数据文件(spfile),控制文件. 1   准备 [[email protected] /]$ sqlplus /nolog SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 12 11:58:35 2015 Copyright (c) 1982, 2011, Oracle. All rights reserved. SQL> conn sys/Sina.2015@study as sys