Maison > base de données > tutoriel mysql > le corps du texte

ORA-01207 old control file完全解决方案

WBOY
Libérer: 2016-06-07 17:12:55
original
970 Les gens l'ont consulté

ORA-01207 old control file完全解决方案

这个错误是Oracle db最常见的错误了,引起的原因很多,但是最主要的一个原因是数据库服务器突然掉电,然后重启启动数据库报错。
究其这个问题产生的原因,其实就是控制文件中记录的db信息太老,导致数据库在启动检测时出现不一致。
控制文件中记录了整个数据库的全部信息,具体包括数据文件的,日志文件等等。
那么为什么会出现控制文件记录的数据库信息太老呢,原因很简单:根据oracle db运行原理,数据库在运行期间,由于检查点发生等原因会不断的更新控制文件,同时数据库在关闭和重启过程中都会更新控制文件的内容,但是数据库服务器突然的掉电,会导致当前的db信息无法适时更新到控制文件中,再次启动数据库后,当oracle检测控制文件和其它文件信息是否一致时,就出现了这个错误。

那么解决这个问题的方法有两个:

方法1:
u        主导思想:创建控制文件,然后open数据库。
u        具体步骤:
1.startup mount
2.alter database backup controlfile to trace
3.create a control file creation script from the trace file,
and use the noresetlogs option
4.shutdown
5.startup nomount
Use the script generated by the 'backup controlfile to trace' command above
creaet the control file
6.recover database
7.alter database open
u        步骤演示:
[oracle@localhost orcl]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Nov 19 15:26:07 2006
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
添加测试数据:
SQL> create table gaojf as select * from all_objects;
Table created.
SQL> insert into gaojf select * from gaojf;
49390 rows created.
SQL> /
98780 rows created.
…………………………………
1580480 rows created.
SQL> commit;
Commit complete.
SQL> shutdown abort   
ORACLE instance shut down.
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 -Production
With the Partitioning, OLAP and Data Mining options

模拟ORA-01207错误很简单,这里不再说明,然后接着如下:
[oracle@localhost orcl]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Nov 19 15:26:47 2006
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area  167772160 bytes
Fixed Size                 1218316 bytes
Variable Size             71305460 bytes
Database Buffers           92274688bytes
Redo Buffers               2973696 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/free/oracle/oradata/orcl/system01.dbf'
ORA-01207: file is more recent than control file - old control file
出现了ORA-01207错误:
SQL> shutdown abort
ORACLE instance shut down.
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 -Production
With the Partitioning, OLAP and Data Mining options
首先删除old control file,其实也可以不删除,个人习惯,然后重建控制文件。
重建控制文件可以在数据库到mount状态下执行alter database backup controlfile to trace生成sql文件,具体操作很简单,不再描述。
IXDBA.NET社区论坛
[oracle@localhost orcl]$ rm -rf control0*
[oracle@localhost orcl]$ vi create.sql
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/free/oracle/oradata/orcl/redo01.log'  SIZE 50M,
  GROUP 2 '/free/oracle/oradata/orcl/redo02.log'  SIZE 50M,
  GROUP 3 '/free/oracle/oradata/orcl/redo03.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '/free/oracle/oradata/orcl/system01.dbf',
  '/free/oracle/oradata/orcl/undotbs01.dbf',
  '/free/oracle/oradata/orcl/sysaux01.dbf',
  '/free/oracle/oradata/orcl/users01.dbf',
  '/free/oracle/oradata/orcl/gaojfdb.dbf'
CHARACTER SET AL32UTF8
;                            
[oracle@localhost orcl]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Nov 19 15:28:00 2006
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> @create
ORACLE instance started.
Total System Global Area  167772160 bytes
Fixed Size                 1218316 bytes
Variable Size             71305460 bytes
Database Buffers           92274688bytes
Redo Buffers               2973696 bytes

Control file created.
SQL> alter database open;

alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/free/oracle/oradata/orcl/system01.dbf'
不能直接open,看来有需要恢复的,执行recover database;
SQL> recover database;
Media recovery complete.
看来是在读取redo file进行前滚,出现这个现象是由于在上面的操作中,我在添加测试数据完毕后,执行了commit命令,然后直接执行了shutdown abort的缘故,所以在重启以后数据库要前滚,从redo file中恢复数据。
一般数据库服务器在突然掉电后,也就是相当于执行了shutdown abort的操作。所以必须在创建控制文件后,执行recoverdatabase。
如果是正常关闭的数据库,可以直接open,无需recover。
此时后台进程执行前滚日志信息如下:
ALTER DATABASE RECOVER  database  
Media Recovery Start
Sun Nov 19 15:28:23 2006
Recovery of Online Redo Log: Thread 1 Group 1 Seq 22 Reading mem 0
  Mem# 0 errs 0: /free/oracle/oradata/orcl/redo01.log
Sun Nov 19 15:28:29 2006
Recovery of Online Redo Log: Thread 1 Group 2 Seq 23 Reading mem 0
  Mem# 0 errs 0: /free/oracle/oradata/orcl/redo02.log
Sun Nov 19 15:28:38 2006
Recovery of Online Redo Log: Thread 1 Group 3 Seq 24 Reading mem 0
  Mem# 0 errs 0: /free/oracle/oradata/orcl/redo03.log
Sun Nov 19 15:28:40 2006
Media Recovery Complete (orcl)
Completed: ALTER DATABASE RECOVER  database  
此时可以打开数据库
SQL> alter database open;
SQL> select count(*) from gaojf;
  COUNT(*)
----------
   3160960

SQL>

方法2:
模拟ORA-01207错误很简单,不再描述:

u        思路:用旧的控制文件恢复,最后用resetlogs打开数据库。
u        具体步骤:
1:startup mount;
2:recover database using backup controlfile untilcancel;
然后根据情况,指定archive log和redo file。
3:alter database open resetlogs;
u        操作演示:
oracle@linux:/free/oracle/oradata/orcl> sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期日 11月 19 13:57:512006
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area  167772160 bytes
Fixed Size                 
1218316 bytes
Variable Size             88082676 bytes
Database Buffers           75497472bytes
Redo Buffers               2973696 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/free/oracle/oradata/orcl/system01.dbf'
ORA-01207: file is more recent than control file - old control file
执行恢复:

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 891145 generated at 11/18/2006 06:02:11 needed for thread 1
ORA-00289: suggestion :
/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_47_%u_.arc

ORA-00280: change 891145 for thread 1 is in sequence #47

Specify log: {=suggested | filename | AUTO | CANCEL}
auto (由于o1_mf_1_47_%u_.arc这个归档日志,我这里有这个文件,所以指定auto,此时应用了一些归档日志)
ORA-00279: change 911145 generated at 11/19/2006 13:49:24 needed for thread 1
ORA-00289: suggestion :
/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_48_%u_.arc
ORA-00280: change 911145 for thread 1 is in sequence #48
ORA-00278: log file
'/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_47_2ozw355r
_.arc' no longer needed for this recovery

ORA-00279: change 911687 generated at 11/19/2006 13:54:36 needed for thread 1
ORA-00289: suggestion :
/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_49_%u_.arc
ORA-00280: change 911687 for thread 1 is in sequence #49
ORA-00278: log file
'/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_48_2ozwf289
_.arc' no longer needed for this recovery


ORA-00308: cannot open archived log
'/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_49_%u_.arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/free/oracle/oradata/orcl/system01.dbf'


这种恢复方式,不会自动去找联机redo文件,所以必须要手工指定!


SQL> recover database using backup controlfile until cancel;
ORA-00279: change 911687 generated at 11/19/2006 13:54:36 needed for thread 1
ORA-00289: suggestion :
/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_49_%u_.arc
ORA-00280: change 911687 for thread 1 is in sequence #49


Specify log: {=suggested | filename | AUTO | CANCEL}
/free/oracle/oradata/orcl/redo01.log
ORA-00310: archived log contains sequence 47; sequence 49 required
ORA-00334: archived log: '/free/oracle/oradata/orcl/redo01.log'


ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/free/oracle/oradata/orcl/system01.dbf'

需要的不是这个redo文件,继续指定!

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 911687 generated at 11/19/2006 13:54:36 needed for thread 1
ORA-00289: suggestion :
/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_49_%u_.arc
ORA-00280: change 911687 for thread 1 is in sequence #49

Specify log: {=suggested | filename | AUTO | CANCEL}
/free/oracle/oradata/orcl/redo02.log
ORA-00310: archived log contains sequence 48; sequence 49 required

ORA-00334: archived log: '/free/oracle/oradata/orcl/redo02.log'


ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/free/oracle/oradata/orcl/system01.dbf'

仍然不是,继续指定!

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 911687 generated at 11/19/2006 13:54:36 needed for thread 1
ORA-00289: suggestion :
/free/oracle/flash_recovery_area/ORCL/archivelog/2006_11_19/o1_mf_1_49_%u_.arc
ORA-00280: change 911687 for thread 1 is in sequence #49


Specify log: {=suggested | filename | AUTO | CANCEL}
/free/oracle/oradata/orcl/redo03.log
Log applied.
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
SQL> select count(*) from gaojf;
  COUNT(*)
----------
    791392
SQL>
完成恢复,数据没有丢失,但是redo file被重置,,建议马上备份数据库一次。

通过以上两个方法,都可以完成恢复。
但是方法1中重建控制文件这个方法可能会简单一些,并且最后可以直接open,这样以前的备份也可以使用。建议使用这个方法。
方法2中,由于在recover中,还要一个一个的指定redo文件去试,最后resetlogs数据库,重置了redo文件,这样恢复完成后,以前如果有的备份可能就无法使用了.可能我认为是稍微复杂了,但是恢复数据库的目的都达到了

更多Oracle相关信息见Oracle 专题页面 ?tid=12

linux

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal