Oracle控制文件恢复案例

案例一:单个控制文件丢失

这种情况解决方法很简单,只要把多路复用的控制文件拷贝到相应路径就行了。

案例二:所有控制文件都丢失(用trace中的SQL创建)

在做这个实验前先生成一个trace文件

alter database backup controlfileto trace as'/backup/siqianctl.trc';

1.先关闭数据库

shutdown immediate

2.删除所有控制文件

之前可以用show parameter control_files来看下控制文件在哪些路径下

[oracle@siqian siqian11g]$ rm-f control0*

3.起库出错

startup

ORA-00205: errorin identifying controlfile,check alert logfor more info

4.利用trace来创建控制文件

CREATE CONTROLFILE REUSE DATABASE"SIQIAN11" NORESETLOGS  ARCHIVELOG

    MAXLOGFILES 16

    MAXLOGMEMBERS 3

    MAXDATAFILES 100

    MAXINSTANCES 8

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/u01/oradata/siqian11g/redo01.log'  SIZE 50M,

  GROUP 2 '/u01/oradata/siqian11g/redo02.log'  SIZE 50M,

  GROUP 3 '/u01/oradata/siqian11g/redo03.log'  SIZE 50M

DATAFILE

  '/u01/oradata/siqian11g/system01.dbf',

  '/u01/oradata/siqian11g/sysaux01.dbf',

  '/u01/oradata/siqian11g/undotbs1.dbf',

  '/u01/oradata/siqian11g/users01.dbf',

  '/u01/oradata/siqian11g/example01.dbf',

  '/u01/oradata/siqian11g/test01.dbf'

CHARACTER SET WE8MSWIN1252

;

5.打开数据库

alter database open;

案例三:用trace里的SQL创建的控制文件但此时的创建的控制文件是老的

现在我再创建一个表空间,使控制文件发生变化,一会重建时会缺少那个表空间的数据文件。

1.创建表空间

create tablespace new_ts datafile'/u01/oradata/siqian11g/new_ts01.dbf' size10m;

2.关闭数据库

shutdown immediate

3.删除所有控制文件

[oracle@siqian siqian11g]$ rm-f control0*

4.打开数据库

startup

ORA-00205: errorin identifying controlfile,check alert logfor more info

5.利用trace创建控制文件

CREATE CONTROLFILE REUSE DATABASE"SIQIAN11" NORESETLOGS  ARCHIVELOG

    MAXLOGFILES 16

    MAXLOGMEMBERS 3

    MAXDATAFILES 100

    MAXINSTANCES 8

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/u01/oradata/siqian11g/redo01.log'  SIZE 50M,

  GROUP 2 '/u01/oradata/siqian11g/redo02.log'  SIZE 50M,

  GROUP 3 '/u01/oradata/siqian11g/redo03.log'  SIZE 50M

DATAFILE

  '/u01/oradata/siqian11g/system01.dbf',

  '/u01/oradata/siqian11g/sysaux01.dbf',

  '/u01/oradata/siqian11g/undotbs1.dbf',

  '/u01/oradata/siqian11g/users01.dbf',

  '/u01/oradata/siqian11g/example01.dbf',

  '/u01/oradata/siqian11g/test01.dbf'

CHARACTER SET WE8MSWIN1252

;

6.打开数据库

alter database open;

7.查看dba_data_files数据字典

sys@SIQIAN11>selectfile_name,tablespace_namefrom dba_data_files;

FILE_NAME                                          TABLESPACE_NAME

--------------------------------------------------------------------------------

/u01/oradata/siqian11g/test01.dbf                 TEST

/u01/oradata/siqian11g/example01.dbf               EXAMPLE

/u01/oradata/siqian11g/users01.dbf                USERS

/u01/oradata/siqian11g/undotbs1.dbf                UNDOTBS1

/u01/oradata/siqian11g/sysaux01.dbf                SYSAUX

/u01/oradata/siqian11g/system01.dbf                SYSTEM

/u01/oracle/dbs/MISSING00007                       NEW_TS

 

7 rows selected.

发现有个数据文件是‘/u01/oracle/dbs/MISSING00007’,其实出现这种情况是因为控制文件中没有这个表空间的数据文件的记录。

8.关闭数据库并启动到mount

shutdown immediate

startup mount

9.将控制文件中的数据文件名重命名

alter database rename file'/u01/oracle/dbs/MISSING00007' to'/u01/oradata/siqian11g/new_ts01.dbf';

10.打开数据库

alter database open;

11.恢复数据文件

recover datafile 7;

案例四:用备份的控制文件恢复(这里的备份控制文件是老的,缺失一些tablespace信息)

1.首先备份一个控制文件

alter database backup controlfileto '/backup/siqianctl.bak';

2.创建一个新的表空间,使备份的控制文件变老

create tablespace bak_cont_ts datafile'/u01/oradata/siqian11g/bak_cont_ts01.dbf' size 10m;

3.关闭数据库并删除当前所有的控制文件

shutdown immediate

[oracle@siqian siqian11g]$ rm-f control0*

4.启动数据库

startup

ORA-00205: errorin identifying controlfile,check alert logfor more info

5.还原备份控制文件

cp /backup/siqianctl.bak/u01/oradata/siqian11g/control01.ctl

cp /backup/siqianctl.bak/u01/oradata/siqian11g/control02.ctl

cp /backup/siqianctl.bak/u01/oradata/siqian11g/control03.ctl

6.把数据库启到mount状态

alter database mount;

7.查询控制文件中的相关信息

select file#,checkpoint_change#,namefrom v$datafile;

     FILE# CHECKPOINT_CHANGE# NAME

---------------------------- --------------------------------------------------

         1            2251199 /u01/oradata/siqian11g/system01.dbf

         2            2251199 /u01/oradata/siqian11g/sysaux01.dbf

         3            2251199 /u01/oradata/siqian11g/undotbs1.dbf

         4            2251199 /u01/oradata/siqian11g/users01.dbf

         5            2251199 /u01/oradata/siqian11g/example01.dbf

         6            2251199 /u01/oradata/siqian11g/test01.dbf

         7            2249435 /u01/oradata/siqian11g/new_ts01.dbf

 

7 rows selected.

可见里面没有刚才创建的bak_cont_ts01.bak文件。

8.使用备份的控制文件恢复数据库

recover database using backup controlfile;

ORA-00279: change2249435 generated at06/29/201322:17:58 neededfor thread 1

ORA-00289: suggestion: /backup/arch/arch_1_819402844_11.log

ORA-00280: change2249435 for thread1 is in sequence #11

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

一路回车下去恢复

到这里出错:

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

ORA-00279: change2251199 generated at06/29/201322:45:23 neededfor thread 1

ORA-00289: suggestion: /backup/arch/arch_1_819402844_14.log

ORA-00280: change2251199 for thread1 is in sequence #14

ORA-00278:log file'/backup/arch/arch_1_819402844_13.log' no longer neededfor this recovery

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

ORA-00308: cannotopen archived log'/backup/arch/arch_1_819402844_14.log'

ORA-27037: unableto obtain file status

Linux Error: 2: No suchfile or directory

Additional information:3

查了一下,只有到序列13的归档日志。

下面怎么办呢?看来得用在线日志做恢复。查看下当前日志

sys@SIQIAN11>selectgroup#,sequence#,statusfrom v$log;

    GROUP SEQUENCE# STATUS

-------------------- ----------------

         1         13 INACTIVE

         3         12 INACTIVE

         2         14 CURRENT

看下当前14序列的日志在哪个路径

select memeber from v$logfile;

MEMBER

----------------------------------------

/u01/oradata/siqian11g/redo01.log

/u01/oradata/siqian11g/redo03.log

/u01/oradata/siqian11g/redo02.log

再一次用备份控制文件恢复数据库

 

sys@SIQIAN11>recover databaseusing backup controlfile;

ORA-00279: change2251640 generated at06/29/201322:56:56 neededfor thread 1

ORA-00289: suggestion: /backup/arch/arch_1_819402844_14.log

ORA-00280: change2251640 for thread1 is in sequence #14

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

/u01/oradata/siqian11g/redo02.log

Log applied.

Media recovery complete.

9.用resetlogs打开数据库

alter database open resetlogs;

10.做数据库全备

 

你可能感兴趣的:(oracle,数据库,备件与恢复)