DATABASE RECOVERY
Database Recovery having 2 types.
COMPLETE
- NO DATA LOSS
UNTIL SCN
UNTIL TIME
LOG_MODE
OPEN_MODE
/u03/coldbkp/
SQL> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
SYS> conn sham/sham
Connected.
SHAM> create table tab2 as select * from tab1;
Table created.
SHAM> select count(*) from tab2;
COUNT(*)
---------524288
$ cd /u01/app/oracle/oradata/rose/
$ rm *.*
LOG_MODE
OPEN_MODE
ARCHIVELOG
READ WRITE
$ cd /u01/app/oracle/oradata/rose/
$ cp *.*
/u03/coldbkp/
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
88
90
90
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
104
106
106
$ cd /u01/app/oracle/oradata/rose/
[oracle@oel5 rose]$ rm -rf *
[oracle@oel5 rose]$ ls -l
total 0
SYS> shut immediate;
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/rose/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SYS> shut abort;
ORACLE instance shut down.
$ cd /u03/coldbkp/
[oracle@oel5 coldbkp]$ cp *
/u01/app/oracle/oradata/rose/
CHECKPOINT_CHANGE#
--------- -----------------1
714338
714338
714338
714338
714338
SYS> alter database recover automatic using backup controlfile until cancel;
alter database recover automatic using backup controlfile until cancel
*
ERROR at line 1:
ORA-00279: change 736465 generated at 09/22/2014 19:48:08 needed for thread 1
ORA-00289: suggestion:
/u01/app/oracle/flash_recovery_area/ROSE/archivelog/2014_09_22/o1_mf_1_106_%u_.arc
ORA-00280: change 736465 for thread 1 is in sequence #106
ORA-00278: log file
'/u01/app/oracle/flash_recovery_area/ROSE/archivelog/2014_09_22/o1_mf_1_106_%u_.arc'
no longer needed for this recovery
ORA-00308: cannot open archived log
'/u01/app/oracle/flash_recovery_area/ROSE/archivelog/2014_09_22/o1_mf_1_106_%u_.arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
CHECKPOINT_CHANGE#
---------- ----------------1
736465
736465
736465
736465
736465
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
LOG_MODE
OPEN_MODE
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
67
69
69
/u02/coldbkp/
SYS> startup
ORACLE instance started.
..
[Trimmed]
Database opened.
SHAM> insert into tab1 select * from tab1;
150000 rows created.
SHAM> /
300000 rows created.
SHAM> /
600000 rows created.
SHAM> insert into tab2 select * from tab1;
600000 rows created.
SHAM> /
1200000 rows created.
SHAM> /
1200000 rows created.
SHAM> select count(*) from tab1;
COUNT(*)
---------1200000
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
90
92
92
RECOVER
------------
OFFLINE
ERROR
------------FILE NOT FOUND
$ cd /u02/coldbkp/
$ cp users01.dbf /u01/app/oracle/oradata/rose/
$ sqlplus / as sysdba
SYS> recover datafile 4;
ORA-00279: change 1371836 generated at 09/24/2014 01:47:26 needed for thread 1
ORA-00289: suggestion:
/u01/app/oracle/flash_recovery_area/ROSE/archivelog/2014_09_24/o1_mf_1_68_b23pdcvz_.arc
ORA-00280: change 1371836 for thread 1 is in sequence #68
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
...
...
..
Log applied.
Media recovery complete.
SYS> alter database datafile 4 online;
Database altered.
SYS> conn sham/sham
Connected.
SHAM> select count(*) from tab1;
COUNT(*)
---------1200000
SHAM> select count(*) from tab2;
COUNT(*)
--------2400000
NOTE: If we configure NOARCHIVELOG mode, we cannot do complete Recovery. Because archivelogs are
needed for complete recovery, it needs to be applied.
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
TABTYPE
CLUSTERID
TABLE
TAB2
TABLE
/u02/coldbkp/
SYS> startup
ORACLE instance started.
..
...
[Trimmed]
Database opened.
SYS> conn sham/sham
Connected.
SHAM> create table tab3 as select * from tab1;
Table created.
SHAM> create table tab4 as select * from tab1;
Table created.
SHAM> update tab4 set name='ROSELIN';
1200000 rows updated.
SHAM> update tab3 set name='ROSELIN';
1200000 rows updated.
SYS> archive log list;
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
23
25
25
$ pwd
/u01/app/oracle/oradata/rose
$ rm *.ctl
$ ls
*.ctl
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/rose/system01.dbf'
SYS> recover cancel;
SYS> select member from v$logfile;
MEMBER
----------------------------------------/u01/app/oracle/oradata/rose/redo03.log
/u01/app/oracle/oradata/rose/redo02.log
/u01/app/oracle/oradata/rose/redo01.log
SYS> recover database using backup controlfile until cancel;
ORA-00279: change 1544063 generated at 09/24/2014 15:23:22 needed for thread 1
ORA-00289: suggestion:
/u01/app/oracle/flash_recovery_area/ROSE/archivelog/2014_09_24/o1_mf_1_25_%u_.arc
TABTYPE
CLUSTERID
TABLE
TAB1
TABLE
TAB2
TABLE
TAB3
TABLE
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
THREAD#
SEQUENCE#
NO
CURRENT
YES
UNUSED
YES
UNUSED
TABTYPE
CLUSTERID
TABLE
/u02/coldbkp/
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
SYS> conn sham/sham
Connected.
SHAM> create table tab2 as select * from tab1;
Table created.
SHAM> create table tab3 as select * from tab1;
Table created.
SHAM> create table tab4 as select * from tab1;
Table created.
SHAM> update tab1 set name='JO' where id >= 1 and id <= 20;
20 rows updated.
SHAM> update tab2 set name='JOE' where id >=1 and id <=20;
20 rows updated.
SHAM> update tab3 set name='JYO_JO' where id >= 1 and id <=20;
20 rows updated.
SHAM> commit;
Commit complete.
SHAM> select name from tab4 where id=1 or id=2;
NAME
Jo
Jo
SHAM> update tab4 set name='rosalin' where id>=1 and id <=5;
10 rows updated.
TABTYPE
CLUSTERID
TABLE
TAB2
TABLE
TAB4
TABLE
TAB3
TABLE
LOG_MODE
--------- -----------ROSE
NOARCHIVELOG
TABTYPE
CLUSTERID
TABLE
/u02/coldbkp/
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
SYS> conn sham/sham
Connected.
SHAM> create table tab2 as select * from tab1;
Table created.
SHAM> create table tab3 as select * from tab1;
Table created.
SHAM> create table tab4 as select * from tab1;
Table created.
$ cd /u01/app/oracle/oradata/rose/
[oracle@oel5 rose]$ rm -rf *.log
LOG_MODE
--------- -----------ROSE
ARCHIVELOG
/u02/coldbkp/
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
LOG_MODE
--------- -----------ROSE
ARCHIVELOG
/u03/coldbkp/rose
SYS> startup
ORACLE instance started.
Total System Global Area
746586112 bytes
Fixed Size
1275920 bytes
Variable Size
197134320 bytes
Database Buffers
545259520 bytes
Redo Buffers
2916352 bytes
Database mounted.
Database opened.
SYS> archive log list;
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
DEFAULT_TABLESPACE
------------------------------ ---------------------ROSE
SAMPLE
ROSE> update tab1 set name='JYO' where id >= 5001 and id <=10000;
5000 rows updated.
ROSE> update tab1 set name='JYOTIKA' where id >= 10001 and id <=50000;
40000 rows updated.
ROSE> commit;
Commit complete.
ROSE> create table tab2 as select * from tab1;
create table tab2 as select * from tab1
*
ERROR at line 1:
ORA-01116: error in opening database file 6
ORA-01110: data file 6: '/u01/app/oracle/oradata/rose/sample01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SYS> alter tablespace sample offline immediate;
or
Tablespace altered.
SYS> alter database datafile 6 offline;
Database altered
SYS> alter database create datafile '/u01/app/oracle/oradata/rose/sample01.dbf';
(or)
NAME
-------
QUAL
CITY
-------
MOBILE
--------- ----------
1001
JO
m.sc
chennai
1234554321
1002
JO
m.sc
chennai
1234554321
NAME
QUAL
CITY
MOBILE
ORACLE
m.sc
chennai
1234554321
ORACLE
m.sc
chennai
1234554321
LOG_MODE
--------- -----------ROSE
ARCHIVELOG
TYPE
VALUE
string
AUTO
undo_retention
integer
900
undo_tablespace
string
UNDOTBS1
/u03/coldbkp/rose
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
SYS> conn rose/rose
Connected.
ROSE> update tab1 set name='JO_JYO';
1000000 rows updated.
NAME
STATUS
/u01/app/oracle/oradata/rose/system01.dbf
SYSTEM
/u01/app/oracle/oradata/rose/undotbs01.dbf
RECOVER
/u01/app/oracle/oradata/rose/sysaux01.dbf
ONLINE
/u01/app/oracle/oradata/rose/users01.dbf
ONLINE
/u01/app/oracle/oradata/rose/example01.dbf
ONLINE
$ cd /u03/coldbkp/rose/
$ cp undotbs01.dbf
/u01/app/oracle/oradata/rose/
NAME
STATUS
/u01/app/oracle/oradata/rose/system01.dbf
SYSTEM
/u01/app/oracle/oradata/rose/undotbs01.dbf
ONLINE
/u01/app/oracle/oradata/rose/sysaux01.dbf
ONLINE
/u01/app/oracle/oradata/rose/users01.dbf
ONLINE
/u01/app/oracle/oradata/rose/example01.dbf
ONLINE
POINTS
We cannot "skip" or "exclude" or "drop" the undo datafile for an undo tablespace that was the
active undo tablespace when the database was OPEN. If there was clean shutdown when you dropped
the undo data file then follow different steps that are given below.
TYPE
VALUE
string
AUTO
undo_retention
integer
900
undo_tablespace
string
UNDOTBS1
$ mv undotbs01.dbf
undotbs01.dbfx
TYPE
VALUE
string
MANUAL
undo_retention
integer
900
undo_tablespace
string
UNDOTBS1
(or)
746586112 bytes
..
[Trimmed]
Database mounted.
Database opened.
SYS> show parameter undo;
NAME
TYPE
VALUE
string
AUTO
undo_retention
integer
900
undo_tablespace
string
undotbs
LOG_MODE
--------- -----------ROSE
ARCHIVELOG
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
/u03/coldbkp/rose
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
SHAM> update tab1 set name='JO';
100000 rows updated.
SHAM> update tab2 set name='JYO';
100000 rows updated.
$ mv sysaux01.dbf sysaux01.dbfx
$ ls -l sysaux01.dbfx
-rw-r----- 1 oracle oinstall 251666432 Oct 12 22:27 sysaux01.dbfx
SYS> alter tablespace sysaux offline;
alter tablespace sysaux offline
*
ERROR at line 1:
ORA-01116: error in opening database file 3
ORA-01110: data file 3: '/u01/app/oracle/oradata/rose/sysaux01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
$ cd /u03/coldbkp/rose/
[oracle@oel5 sham]$ cp sysaux01.dbf /u01/app/oracle/oradata/rose/
SYS> recover datafile 3;
ORA-00283: recovery session canceled due to errors
ORA-01124: cannot recover data file 3 - file is in use or recovery
ORA-01110: data file 3: '/u01/app/oracle/oradata/rose/sysaux01.dbf'
/u03/coldbkp/rose
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
SYS> archive log list;
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
NAME
--
--------
rosalin
QUAL
CITY
-------- ------m.sc
chennai
MOBILE
---------1234554321
NAME
---- ------
QUAL
CITY
MOBILE
oracle
m.sc
chennai
1234554321
1000
ORACLEDB
m.sc
chennai
1234554321
POINTS TO NOTE
To recover to a past point in time you have to RESTORE the database from a backup older than the
recovery point in time. Make a new complete backup, as the database is open in a new incarnation
and previous archived log are not relevant.
LOSS OF TEMPORARY TABLESPACE
SYS> select name, log_mode from v$database;
NAME
LOG_MODE
--------- -----------ROSE
ARCHIVELOG
YES NO
YES
1 UNDOTBS1
YES NO
YES
2 SYSAUX
YES NO
YES
4 USERS
YES NO
YES
3 TEMP
NO
NO
YES
6 EXAMPLE
YES NO
YES
6 rows selected.
/u03/coldbkp/rose
/u01/app/oracle/oradata/rose/temp01.dbf
SYS> startup
ORACLE instance started.
..
....
[Trimmed]
Database opened.
$ tail -f /u01/app/oracle/admin/rose/bdump/alert_rose.log
...
Re-creating tempfile /u01/app/oracle/oradata/rose/temp01.dbf
From 10g, Oracle is able to detect the missing temporary file and recreate it on the same location.
SCENARIO II
SYS> select file#, name, status from v$tempfile;
FILE#
NAME
------ ----------------------------------------1
/u01/app/oracle/oradata/rose/temp01.dbf
$ rm
/u01/app/oracle/oradata/rose/temp01.dbf
INC BIG
FLA
ENC
YES
NO
YES
1 UNDOTBS1
YES
NO
YES
2 SYSAUX
YES
NO
YES
4 USERS
YES
NO
YES
6 EXAMPLE
YES
NO
YES
7 TEMPTBS
NO
NO
YES
6 rows selected.
SYS> select name from v$tempfile;
NAME
----------------------------------------/u01/app/oracle/oradata/rose/temp01.dbf
POINTS TO NOTE
UNIX/LINUX provide us with a command that does a safer remove.
$ rm -i <file_name>
$ rm -i undotbs01.dbfx
rm: remove regular file `undotbs01.dbfx'?
until cancel;
USING BACKUP CONTROLFILE tells Oracle to assume that there are transactions and redo beyond the
controlfile that is used. i.e. It tells to oracle that you don't have the current control file.
So the recovery should continue beyond what is recorded in the control file. And you will need
to open resetlogs at the end to restart a redo log sequence.
When startup database we would get ora-1157 & ora-1110 and the name of the missing datafile, the
database will be remained in mount phase, then use OS command cp to restore the missing datafile
to its original location,
STEP 1 $ cp -p /u03/coldbkp/rose/users01.dbf
/u01/app/oracle/ordata/rose/