CONTROLFILE_CHANGE#,CHECKPOINT_CHANGE#, current_scn from v$database; select tablespace_name, file#, name, bytes/1024/1024, checkpoint_change#, checkpoint_time from v$datafile_header; select a.group#, a.sequence#, a.members, a.status, a.archived, b.member, b.status, a.first_change#, a.first_time from v$log a, v$logfile b where a.group# = b.group# order by a.group#;
Recovery with an old controlfile/recover database using backup controlfile
Question:
I have a full database backup wth control file and archvelogs which is taken by rman yesterday. Today my db s crashed at the evenng and control fle s corrupted. When I restore yesterdays controlfile from backupset, and restore all yesterday's datafiles, can I apply todays archivelogs and apply to these datafiles? Do I lose any data in this scenerio? Answer:
When you take online/hot backup then yours backup is inconsistent , upon recovery oracle makes inconsistent backups consistent by applying all archived and online redo logs, oracle makes recovery by reading the earliest/oldest SCN in any of the datafile headers and apply the changes from the logs back into the datafile. Yes indeed controlfile has repositry about alls backup stuff like database backup as well archivelog backup. If you take backup of archivelog then it goes to control file entry, upon restoration activity oracle reads the controlfile to ask where archivelog exist to be restored. If yours todays archivelogs are on disk not in controlfile repositry then oracle will apply these todays archivelog regardless controlfile knows or not, If the RMAN repository or controlfile indicates that no copies of a needed log sequence number exist on disk, then RMAN looks in backups and restores archived redo logs as needed to perform the media recovery, there is no concern controlfile for applying archivelogs at all, if you have todays archivelogs exist then you will lose data only which is in current redo log thats why multiplexing redo log came into ours dbackup plan. Question:
But control file is older it doesnt store the info of new archivelogs. How can I add? Answer:
Contorolfile older issue raise when you have controlfile for yesterday and datafile for today, if you restore yesterdays controlfle and restore the datafile from this yesterday controlfile and then started recovery to this yesterday controlfile then there would be no any issue to recover the database till before crash using todays archivelogs. Here you have to remember one thing you will lose only data for current redo log, if you have redo log keep intact by multiplexing then you can recover this multiplexed current redo log data also. If yesterdays controlfile dont know todays database physical activity i.e. adding datafile then archivelog data for this todays datafile applying will raise the error during recovery. Here i am going to prove that yesterdays controlfile will not be an issue for tracking the todays archivelog during recovery process and it will apply safely.
SYS@orcl> SYS@orcl> select a.group#, a.sequence#, a.members, a.status, a.archived, b.member, b.status, a.first_change#, a.first_time from v$log a, v$logfile b where a.group# = b.group# order by a.group#;
GROUP# SEQUENCE# MEMBERS STATUS ARC MEMBER STATUS FIRST_CHANGE# FIRST_TIM ------ --------- ------- ---------- --- ------------------------- ----- ---------- ------------- --------- 1 4 2 CURRENT NO /u01/oradata/orcl/redo01b.log 1494985 18-MAY-14 1 4 2 CURRENT NO /u01/oradata/orcl/redo01.log 1494985 18-MAY-14 2 2 2 INACTIVE YES /u01/oradata/orcl/redo02.log 1494600 18-MAY-14 2 2 2 INACTIVE YES /u01/oradata/orcl/redo02b.log 1494600 18-MAY-14 3 3 2 INACTIVE YES /u01/oradata/orcl/redo03b.log 1494982 18-MAY-14 3 3 2 INACTIVE YES /u01/oradata/orcl/redo03.log 1494982 18-MAY-14
6 rows selected.
SYS@orcl> SYS@orcl> create table scott.a as select * from all_objects;
Table created.
SYS@orcl> alter system switch logfile;
System altered.
SYS@orcl> create table scott.b as select * from all_objects;
Table created.
SYS@orcl> alter system switch logfile;
System altered.
SYS@orcl> create table scott.c as select * from all_objects;
SYS@orcl> select a.group#, a.sequence#, a.members, a.status, a.archived, b.member, b.status, a.first_change#, a.first_time from v$log a, v$logfile b where a.group# = b.group# order by a.group#;
GROUP# SEQUENCE# MEMBERS STATUS ARC MEMBER STATUS FIRST_CHANGE# FIRST_TIM ------ --------- ------- ---------- --- ------------------------- ----- ---------- ------------- --------- 1 7 2 CURRENT NO /u01/oradata/orcl/redo01b.log 1495347 18-MAY-14 1 7 2 CURRENT NO /u01/oradata/orcl/redo01.log 1495347 18-MAY-14 2 5 2 INACTIVE YES /u01/oradata/orcl/redo02.log 1495187 18-MAY-14 2 5 2 INACTIVE YES /u01/oradata/orcl/redo02b.log 1495187 18-MAY-14 3 6 2 INACTIVE YES /u01/oradata/orcl/redo03b.log 1495265 18-MAY-14 3 6 2 INACTIVE YES /u01/oradata/orcl/redo03.log 1495265 18-MAY-14
6 rows selected.
SYS@orcl>
Now Shutdown the database and take full database cold backup. After that open the database and add data into the database.
SYS@orcl> shutdown Database closed. Database dismounted. ORACLE instance shut down. SYS@orcl> SYS@orcl> SYS@orcl> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@linux9 ~]$ [oracle@linux9 ~]$ [oracle@linux9 ~]$ ls -ltr /u02/backup/orcl/ total 0 [oracle@linux9 ~]$ [oracle@linux9 ~]$ cp /u01/oradata/orcl/*.* /u02/backup/orcl/ [oracle@linux9 ~]$ [oracle@linux9 ~]$ sqlplus "/ as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Sun May 18 00:44:38 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SYS@orcl> startup ORACLE instance started.
Total System Global Area 418484224 bytes Fixed Size 1336932 bytes Variable Size 310380956 bytes Database Buffers 100663296 bytes Redo Buffers 6103040 bytes Database mounted. Database opened. SYS@orcl> SYS@orcl> SYS@orcl> SYS@orcl> select a.group#, a.sequence#, a.members, a.status, a.archived, b.member, b.status, a.first_change#, a.first_time from v$log a, v$logfile b where a.group# = b.group# order by a.group#;
GROUP# SEQUENCE# MEMBERS STATUS ARC MEMBER STATUS FIRST_CHANGE# FIRST_TIM ------ --------- ------- ---------- --- ------------------------- ----- ---------- ------------- --------- 1 7 2 CURRENT NO /u01/oradata/orcl/redo01b.log 1495347 18-MAY-14 1 7 2 CURRENT NO /u01/oradata/orcl/redo01.log 1495347 18-MAY-14 2 5 2 INACTIVE YES /u01/oradata/orcl/redo02.log 1495187 18-MAY-14 2 5 2 INACTIVE YES /u01/oradata/orcl/redo02b.log 1495187 18-MAY-14 3 6 2 INACTIVE YES /u01/oradata/orcl/redo03b.log 1495265 18-MAY-14 3 6 2 INACTIVE YES /u01/oradata/orcl/redo03.log 1495265 18-MAY-14
6 rows selected.
SYS@orcl> create table scott.d as select * from all_objects;
Table created.
SYS@orcl> alter system switch logfile;
System altered.
SYS@orcl> create table scott.e as select * from all_objects;
Table created.
SYS@orcl> alter system switch logfile;
System altered.
SYS@orcl> create table scott.f as select * from all_objects;
SYS@orcl> select a.group#, a.sequence#, a.members, a.status, a.archived, b.member, b.status, a.first_change#, a.first_time from v$log a, v$logfile b where a.group# = b.group# order by a.group#;
GROUP# SEQUENCE# MEMBERS STATUS ARC MEMBER STATUS FIRST_CHANGE# FIRST_TIM ------ --------- ------- ---------- --- ------------------------- ----- ---------- ------------- --------- 1 10 2 CURRENT NO /u01/oradata/orcl/redo01b.log 1496259 18-MAY-14 1 10 2 CURRENT NO /u01/oradata/orcl/redo01.log 1496259 18-MAY-14 2 8 2 ACTIVE YES /u01/oradata/orcl/redo02.log 1496099 18-MAY-14 2 8 2 ACTIVE YES /u01/oradata/orcl/redo02b.log 1496099 18-MAY-14 3 9 2 ACTIVE YES /u01/oradata/orcl/redo03b.log 1496180 18-MAY-14 3 9 2 ACTIVE YES /u01/oradata/orcl/redo03.log 1496180 18-MAY-14
6 rows selected.
SYS@orcl>
Now delete alls datafiles
[oracle@linux9 orcl]$ [oracle@linux9 orcl]$ cd /u01/oradata/orcl/ [oracle@linux9 orcl]$ [oracle@linux9 orcl]$ ls -ltr total 2576736 -rw-r----- 1 oracle oinstall 104865792 May 17 23:59 example01.dbf -rw-r----- 1 oracle oinstall 10493952 May 17 23:59 temp01.dbf -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02b.log -rw-r----- 1 oracle oinstall 20979712 May 18 00:46 users02.dbf -rw-r----- 1 oracle oinstall 753672192 May 18 00:46 users01.dbf -rw-r----- 1 oracle oinstall 99622912 May 18 00:46 undotbs01.dbf -rw-r----- 1 oracle oinstall 723525632 May 18 00:46 system01.dbf -rw-r----- 1 oracle oinstall 597696512 May 18 00:46 sysaux01.dbf -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:48 redo01.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:48 redo01b.log -rw-r----- 1 oracle oinstall 10469376 May 18 00:49 control01.ctl [oracle@linux9 orcl]$ [oracle@linux9 orcl]$ rm *.dbf [oracle@linux9 orcl]$ [oracle@linux9 orcl]$ ls -ltr total 317800 -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:48 redo01.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:48 redo01b.log -rw-r----- 1 oracle oinstall 10469376 May 18 00:49 control01.ctl [oracle@linux9 orcl]$ [oracle@linux9 orcl]$
Check the alter log file for error.
Errors in file /ora_home/apps/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_19585. trc: ORA-01116: error in opening database file 1 ORA-01110: data file 1: '/u01/oradata/orcl/system01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 Errors in file /ora_home/apps/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_19585. trc: ORA-01116: error in opening database file 2 ORA-01110: data file 2: '/u01/oradata/orcl/sysaux01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 Errors in file /ora_home/apps/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_19585. trc: ORA-01116: error in opening database file 4 ORA-01110: data file 4: '/u01/oradata/orcl/users01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 Errors in file /ora_home/apps/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_19585. trc: ORA-01116: error in opening database file 5 ORA-01110: data file 5: '/u01/oradata/orcl/users02.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 Errors in file /ora_home/apps/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_19585. trc: ORA-01116: error in opening database file 3 ORA-01110: data file 3: '/u01/oradata/orcl/undotbs01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory
[oracle@linux9 orcl]$ cd /u01/oradata/orcl/ [oracle@linux9 orcl]$ [oracle@linux9 orcl]$ ls -ltr total 317800 -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:56 redo01.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:56 redo01b.log -rw-r----- 1 oracle oinstall 10469376 May 18 00:56 control01.ctl [oracle@linux9 orcl]$ [oracle@linux9 orcl]$ cp /u02/backup/orcl/*.dbf . [oracle@linux9 orcl]$ [oracle@linux9 orcl]$ ls -ltr total 2576736 -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo02b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:46 redo03b.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:56 redo01.log -rw-r----- 1 oracle oinstall 52429312 May 18 00:56 redo01b.log -rw-r----- 1 oracle oinstall 10469376 May 18 00:56 control01.ctl -rw-r----- 1 oracle oinstall 104865792 May 18 00:58 example01.dbf -rw-r----- 1 oracle oinstall 597696512 May 18 00:58 sysaux01.dbf -rw-r----- 1 oracle oinstall 723525632 May 18 00:58 system01.dbf -rw-r----- 1 oracle oinstall 10493952 May 18 00:58 temp01.dbf -rw-r----- 1 oracle oinstall 99622912 May 18 00:58 undotbs01.dbf -rw-r----- 1 oracle oinstall 753672192 May 18 00:59 users01.dbf -rw-r----- 1 oracle oinstall 20979712 May 18 00:59 users02.dbf [oracle@linux9 orcl]$
SYS@orcl> startup ORACLE instance started.
Total System Global Area 418484224 bytes Fixed Size 1336932 bytes Variable Size 310380956 bytes Database Buffers 100663296 bytes Redo Buffers 6103040 bytes Database mounted. ORA-01113: file 1 needs media recovery ORA-01110: data file 1: '/u01/oradata/orcl/system01.dbf'
SYS@orcl> recover database; ORA-00279: change 1495820 generated at 05/18/2014 00:41:48 needed for thread 1 ORA-00289: suggestion : /u02/FRA/ORCL/archivelog/2014_05_18/o1_mf_1_7_9qhfc4d1_.arc ORA-00280: change 1495820 for thread 1 is in sequence #7
Specify log: {<RET>=suggested | filename | AUTO | CANCEL} auto Log applied. Media recovery complete. SYS@orcl> SYS@orcl> alter database open;
Database altered.
SYS@orcl> select a,b,c,d,e,f from (select count(*) a from scott.a), (select count(*) b from scott.b), (select count(*) c from scott.c),(select count(*) d from scott.d), (select count(*) e from scott.e), (select count(*) f from scott.f);
A B C D E F ---------- ---------- ---------- ---------- ---------- ---------- 71419 71420 71421 71422 71423 71424
SYS@orcl> select a.group#, a.sequence#, a.members, a.status, a.archived, b.member, b.status, a.first_change#, a.first_time from v$log a, v$logfile b where a.group# = b.group# order by a.group#;
GROUP# SEQUENCE# MEMBERS STATUS ARC MEMBER STATUS FIRST_CHANGE# FIRST_TIM ------ --------- ------- ---------- --- ------------------------- ----- ---------- ------------- --------- 1 10 2 CURRENT NO /u01/oradata/orcl/redo01b.log 1496259 18-MAY-14 1 10 2 CURRENT NO /u01/oradata/orcl/redo01.log 1496259 18-MAY-14 2 8 2 INACTIVE YES /u01/oradata/orcl/redo02.log 1496099 18-MAY-14 2 8 2 INACTIVE YES /u01/oradata/orcl/redo02b.log 1496099 18-MAY-14 3 9 2 INACTIVE YES /u01/oradata/orcl/redo03b.log 1496180 18-MAY-14 3 9 2 INACTIVE YES /u01/oradata/orcl/redo03.log 1496180 18-MAY-14
6 rows selected.
SYS@orcl>
ORA-01207: File is more recent than control file - old control file Few days ago I faced this issue in my database, due to some problem in my ASM disks, my database closed abruptly and I was getting the following error when I was trying to open my database using STARTUP command.
Errors:- =========== ORA-01122: database file 6 failed verification check ORA-01110: data file 6: '+AMIT_R1/orcl/datafile/amit.271.795743985' ORA-01207: file is more recent than control file - old control file.
Cause :- =========== The information in this file is inconsistent with information from the control file. The datafile header CHECKPOINT count is beyond the controlfile CHECKPOINT count.
Solution :- =========== 1. Mount the database. SQL> startup mount; ORACLE instance started.
Total System Global Area 1025298432 bytes Fixed Size 1341000 bytes Variable Size 322963896 bytes Database Buffers 696254464 bytes Redo Buffers 4739072 bytes Database mounted.
2. Recreate the control file of the database. Please refer to http://amit7oracledba.blogspot.in/2012/10/how-to-recreate-control-file-in-oracle.html only to recreate your control file.
3. After creation of control file, database is in mount stage
SQL> select open_mode from v$database;
OPEN_MODE -------------------- MOUNTED
4. Recover the database. SQL> recover database;
If it does recovery from the redo logs then from above command only your database will be recovered , but if the error is "control file is more recent than the file" then it asks you for archive logs to recover then you have to use below command
SQL> recover database using backup controlfile until cancel;
it will ask you for archive logs, give the path of all archive logs which it needs until it gives you message, MEDIA RECOVERY COMPLETED.
5. Open the database. SQL> alter database open;
Database altered. SQL> select open_mode from v$database;
OPEN_MODE -------------------- READ WRITE
Database recovery complete.
How to recreate a control file in Oracle Database We should only recreate our control file when we are in certain circumstances :-
1. All copies of control files present in database are lost or corrupted. 2. We are restoring a backup in which control file is corrupted or missing. 3. We need to change a hard limit database parameter in the control file. 4. If we are moving our database to another server are files are present in different location. 5. Oracle customer support advices us to do so.
Recreating a control file of that database which is able to mount or open.
1. First we have to generate a ascii dump of the control file.
When database is mounted or open :- SQL> alter database backup controlfile to trace;
Database altered
Trace file will be generated in User_dump directory. SQL> show parameter user_dump_dest
NAME TYPE VALUE ------------------------ --------- ---------------------------- user_dump_dest string /u04/app/cognos/diag/rdbms/orc l/orcl/trace
Navigate to this directory and locate the latest trace file by using ls -ltr [cognos@rac1 ~]$ cd /u04/app/cognos/diag/rdbms/orcl/orcl/trace/ [cognos@rac1 trace]$ ls -ltr
2. Create control file creation script from backup trace file :-
open the trace file named like _orc_1234.trc. It appears like an ordinary trace file but we are interested in the part having create control file script. Modify the trace file, delete every thing above the "CREATE CONTROLFILE" and after the "CHARACTER SET" option.
3. Shut down your database with immediate option. SQL> shu immediate Database closed. Database dismounted. ORACLE instance shut down.
4. Startup the database in nomount mode. SQL> startup nomount; ORACLE instance started.
Total System Global Area 1025298432 bytes Fixed Size 1341000 bytes Variable Size 322963896 bytes Database Buffers 696254464 bytes Redo Buffers 4739072 bytes SQL>
5. Take the control file script and use it to create the control file of the database. SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS NOARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '+AMIT_R1/orcl/onlinelog/group_1.262.790789015', '+AMIT_R1/orcl/onlinelog/group_1.263.790789019' ) SIZE 50M BLOCKSIZE 512, GROUP 2 ( '+AMIT_R1/orcl/onlinelog/group_2.264.790789023', '+AMIT_R1/orcl/onlinelog/group_2.265.790789025' ) SIZE 50M BLOCKSIZE 512, GROUP 3 ( '+AMIT_R1/orcl/onlinelog/group_3.266.790789027', '+AMIT_R1/orcl/onlinelog/group_3.267.790789029' ) SIZE 50M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE '+AMIT_R1/orcl/datafile/system.256.790788811', '+AMIT_R1/orcl/datafile/sysaux.257.790788811', '+AMIT_R1/orcl/datafile/undotbs1.258.790788813', '+AMIT_R1/orcl/datafile/users.259.790788813', '+AMIT_R1/orcl/datafile/example.269.790789095', '+AMIT_R1/orcl/datafile/amit.271.795743985' CHARACTER SET AL32UTF8 ; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Control file created.
Once the control file successfully created database is automatically mounted.
SQL> select open_mode from v$database;
OPEN_MODE -------------------- MOUNTED
6. Once the database is mounted open the database with reset logs option.
SQL> alter database open resetlogs;
Database altered.
We have started the database with resetlogs so it's important to take a backup immediately.
7. After the database is open add the existing temp file
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '+AMIT_R1/orcl/tempfile/temp.268.790789087' size 1429M REUSE;
Tablespace altered.
NOTE :- If we are using this control file creation script for a new database then some change have to be made in control file creation script, instead of "CREATE CONTROLFILE REUSE" we have to use "CREATE CONTROLFILE SET" and instead of "NORESETLOGS" we have to use "RESETLOGS".
Recreating a control file of that database which is not able to mount.
In this scenario when we donot have a control file then :-
1. Restore control file from backup. OR Create a script of control file from beginning