Home Database Mysql Tutorial ORA-01207 old control file完全解决方案

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

Jun 07, 2016 pm 05:12 PM

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1654
14
PHP Tutorial
1252
29
C# Tutorial
1225
24
When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Laravel Eloquent ORM in Bangla partial model search) Laravel Eloquent ORM in Bangla partial model search) Apr 08, 2025 pm 02:06 PM

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

See all articles