控制文件损坏处理

来源:这里教程网 时间:2026-03-03 19:49:36 作者:

二、有 rman 备份的恢复    

2.1 只损坏一个控制文件的情况

本文档的恢复场景都是针对的多控制文件的情况,如果你只有一个那当我没说 ????

查看控制文件

SQL> show parameter control_files;
 
NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
control_files                 string     /oracle/app/oradata/orcl/control01.ctl, /oracle/app/oradata/orcl/control02.ctl

模拟破坏

[oracle@redhat11g8 orcl]$ echo ''>/oracle/app/oradata/orcl/control01.ctl

 

后台日志可以看到会报控制文件有坏块,但是实例还没有宕:

Errors in file /oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ckpt_30033.trc  (incident=38401):
ORA-00227: corrupt block detected in control file: (block 1, # blocks 1)
ORA-00202: control file: '/oracle/app/oradata/orcl/control01.ctl'

 

做一次检查点切换:

SQL> alter system checkpoint;
alter system checkpoint
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 26789
Session ID: 153 Serial number: 2627

 

后台日志显示实例被异常终止:

CKPT (ospid: 30033): terminating the instance due to error 227
Wed Feb 13 08:20:11 2019
System state dump requested by (instance=1, osid=30033 (CKPT)), summary=[abnormal instance termination].
System State dumped to trace file /oracle/app/diag/rdbms/orcl/orcl/trace/orcl_diag_30021_20190213082011.trc
Dumping diagnostic data in directory=[cdmp_20190213082011], requested by (instance=1, osid=30033 (CKPT)), summary=[abnormal instance termination].
Instance terminated by CKPT, pid = 30033

 

 

恢复方法:

cp control02.ctl control01.ctl

 

然后重新 startup 实例,运行正常。

 

2.2 所有控制文件都损坏的情况

模拟破坏:

[oracle@redhat11g8 orcl]$ echo ''>control01.ctl
[oracle@redhat11g8 orcl]$ echo ''>control02.ctl
SQL> alter system checkpoint;
alter system checkpoint
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 26927
Session ID: 135 Serial number: 13

后台日志情况和前面一样在发生检查点切换后,实例就宕了。

 

恢复方法:

RMAN>  restore controlfile from '/home/oracle/rman/full_08tpot0t_1_1';
 
Starting restore at 13-FEB-19
using channel ORA_DISK_1
 
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/app/oradata/orcl/control01.ctl
output file name=/oracle/app/oradata/orcl/control02.ctl
Finished restore at 13-FEB-19
 
RMAN> recover database;//对控制文件进行归档+redo恢复
RMAN> alter database open resetlogs;
 
database opened

三、没有 rman 备份的恢复

[oracle@redhat11g8 orcl]$ echo ''>control01.ctl
[oracle@redhat11g8 orcl]$ echo ''>control02.ctl
[oracle@redhat11g8 orcl]$ !sql
sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.4.0 Production on Wed Feb 13 08:59:38 2019
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> alter system checkpoint;
alter system checkpoint
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 27123
Session ID: 72 Serial number: 3

 

恢复方法,若是还能 mount 的话倒简单,

alter database backup controlfile to trace as '/tmp/ctl.txt';

即可,如果不能 mount 的话,只能麻烦点恢复:

 

通过参数文件获取数据库名:

SQL> startup nomount;
ORACLE instance started.
 
Total System Global Area 2471931904 bytes
Fixed Size            2255752 bytes
Variable Size          620758136 bytes
Database Buffers     1845493760 bytes
Redo Buffers            3424256 bytes
SQL> create pfile='/tmp/orcl.ora' from spfile;
 
File created.
 
*.db_name='orcl'

 

 

查询字符集:

SQL> select userenv('language') from dual;
 
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.US7ASCII

 

获取数据文件名和 redo 文件名:

[oracle@redhat11g8 orcl]$ ls -lh *.dbf
-rw-r-----. 1 oracle oinstall 254M Feb 13 08:54 jason01.dbf
-rw-r-----. 1 oracle oinstall 101M Feb 13 08:54 odc01.dbf
-rw-r-----. 1 oracle oinstall 1.3G Feb 13 08:54 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 781M Feb 13 08:54 system01.dbf
-rw-r-----. 1 oracle oinstall 9.9G Feb 13 08:54 temp01.dbf
-rw-r-----. 1 oracle oinstall  11M Feb  3 06:50 temp02.dbf
-rw-r-----. 1 oracle oinstall 2.6G Feb 13 08:54 test.dbf
-rw-r-----. 1 oracle oinstall 1.9G Feb 13 08:54 undotbs01.dbf
-rw-r-----. 1 oracle oinstall  11G Feb 13 08:54 users01.dbf
 
[oracle@redhat11g8 orcl]$ ls -lh *.log
-rw-r-----. 1 oracle oinstall 51M Feb 13 08:54 redo01.log
-rw-r-----. 1 oracle oinstall 51M Feb 13 08:54 redo02.log
-rw-r-----. 1 oracle oinstall 51M Feb 13 08:59 redo03.log

编写重建脚本 ( 注意临时文件不要写进重建脚本里,不然会报如下错误 )

ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-01160: file is not a data file
ORA-01110: data file : '/oracle/app/oradata/orcl/temp01.dbf'

 

 

CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/oracle/app/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/oracle/app/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/oracle/app/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/oracle/app/oradata/orcl/jason01.dbf',
  '/oracle/app/oradata/orcl/odc01.dbf',
  '/oracle/app/oradata/orcl/sysaux01.dbf',
  '/oracle/app/oradata/orcl/system01.dbf',
  '/oracle/app/oradata/orcl/test.dbf',
  '/oracle/app/oradata/orcl/undotbs01.dbf',
  '/oracle/app/oradata/orcl/users01.dbf'
CHARACTER SET US7ASCII
;
 
SQL> alter database open resetlogs;

 

Database altered.

四、注意事项

1 、除了 2.1 这种通过 cp 另一个控制文件恢复的情景,其他情景都需要在恢复完后做一个 RMAN 全备份,因为 resetlogs 打开后,之前的备份片都会失效。

2 、控制文件最好能做冗余,就算坏了一个,还可以用另一个恢复。

相关推荐