首頁 資料庫 mysql教程 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

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

與MySQL中使用索引相比,全表掃描何時可以更快? 與MySQL中使用索引相比,全表掃描何時可以更快? Apr 09, 2025 am 12:05 AM

全表掃描在MySQL中可能比使用索引更快,具體情況包括:1)數據量較小時;2)查詢返回大量數據時;3)索引列不具備高選擇性時;4)複雜查詢時。通過分析查詢計劃、優化索引、避免過度索引和定期維護表,可以在實際應用中做出最優選擇。

可以在 Windows 7 上安裝 mysql 嗎 可以在 Windows 7 上安裝 mysql 嗎 Apr 08, 2025 pm 03:21 PM

是的,可以在 Windows 7 上安裝 MySQL,雖然微軟已停止支持 Windows 7,但 MySQL 仍兼容它。不過,安裝過程中需要注意以下幾點:下載適用於 Windows 的 MySQL 安裝程序。選擇合適的 MySQL 版本(社區版或企業版)。安裝過程中選擇適當的安裝目錄和字符集。設置 root 用戶密碼,並妥善保管。連接數據庫進行測試。注意 Windows 7 上的兼容性問題和安全性問題,建議升級到受支持的操作系統。

說明InnoDB全文搜索功能。 說明InnoDB全文搜索功能。 Apr 02, 2025 pm 06:09 PM

InnoDB的全文搜索功能非常强大,能够显著提高数据库查询效率和处理大量文本数据的能力。1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

InnoDB中的聚類索引和非簇索引(次級索引)之間的差異。 InnoDB中的聚類索引和非簇索引(次級索引)之間的差異。 Apr 02, 2025 pm 06:25 PM

聚集索引和非聚集索引的區別在於:1.聚集索引將數據行存儲在索引結構中,適合按主鍵查詢和範圍查詢。 2.非聚集索引存儲索引鍵值和數據行的指針,適用於非主鍵列查詢。

mysql:簡單的概念,用於輕鬆學習 mysql:簡單的概念,用於輕鬆學習 Apr 10, 2025 am 09:29 AM

MySQL是一個開源的關係型數據庫管理系統。 1)創建數據庫和表:使用CREATEDATABASE和CREATETABLE命令。 2)基本操作:INSERT、UPDATE、DELETE和SELECT。 3)高級操作:JOIN、子查詢和事務處理。 4)調試技巧:檢查語法、數據類型和權限。 5)優化建議:使用索引、避免SELECT*和使用事務。

mysql用戶和數據庫的關係 mysql用戶和數據庫的關係 Apr 08, 2025 pm 07:15 PM

MySQL 數據庫中,用戶和數據庫的關係通過權限和表定義。用戶擁有用戶名和密碼,用於訪問數據庫。權限通過 GRANT 命令授予,而表由 CREATE TABLE 命令創建。要建立用戶和數據庫之間的關係,需創建數據庫、創建用戶,然後授予權限。

mysql 和 mariadb 可以共存嗎 mysql 和 mariadb 可以共存嗎 Apr 08, 2025 pm 02:27 PM

MySQL 和 MariaDB 可以共存,但需要謹慎配置。關鍵在於為每個數據庫分配不同的端口號和數據目錄,並調整內存分配和緩存大小等參數。連接池、應用程序配置和版本差異也需要考慮,需要仔細測試和規劃以避免陷阱。在資源有限的情況下,同時運行兩個數據庫可能會導致性能問題。

說明不同類型的MySQL索引(B樹,哈希,全文,空間)。 說明不同類型的MySQL索引(B樹,哈希,全文,空間)。 Apr 02, 2025 pm 07:05 PM

MySQL支持四種索引類型:B-Tree、Hash、Full-text和Spatial。 1.B-Tree索引適用於等值查找、範圍查詢和排序。 2.Hash索引適用於等值查找,但不支持範圍查詢和排序。 3.Full-text索引用於全文搜索,適合處理大量文本數據。 4.Spatial索引用於地理空間數據查詢,適用於GIS應用。

See all articles