Showing posts with label BACKUP N RECOVERY. Show all posts
Showing posts with label BACKUP N RECOVERY. Show all posts

Wednesday 14 August 2019

Check the last incarnation restore time of oracle database


Check the last incarnation restore time when the database is started with resetlogs command with following command.

Incarnation is the time when the database is started with resetlogs command. If you start the database is the incarnation, then all available archivelog and backup become invalid. If you want to restore old incarnation, then you need to set the incarnation level in RMAN to restore or recover old SCN.

Always take a fresh backup of the database when you start the database in resetlog. Because when the database is open with resetlogs all redo Sequence no is reset and start from one.

It will show you the last incarnation time when the database is up with resetlogs commands.

SELECT incarnation#,
resetlogs_change#,
TO_CHAR(resetlogs_time, 'dd-mon-yyyy hh24:mi:ss') db_restored_time ,
scn_to_timestamp(resetlogs_change#) db_recovery_till_time
FROM v$database_incarnation
WHERE resetlogs_change# !=
(SELECT MIN(resetlogs_change#) FROM v$database_incarnation
);

List of incarnation:

select incarnation#, resetlogs_change# from v$database_incarnation;

List incarnation from RMAN prompt:

RMAN> list incarnation of database;

When you open the database in resetlogs then a new incarnation is created at the database level. If you tried to restore the database before incarnation state, then you got the error:
RMAN-20208: until change is before resetlogs change

Then you need to check the SCN from incarnation commands:
Example:

RMAN> list incarnation of database;

 DB Key Inc Key DB Name DB ID         STATUS  Reset SCN Reset Time
------ ------- ------- ------------- ------- --------- -----------
1      1       ORCL     1235491512   PARENT  1         03-AUG-17
2      2       ORCL     1235491512   PARENT  543000    10-OCT-17
3      3       ORCL     1235491512   CURRENT 548000    10-OCT-17


If I want to restore the SCN no 54700 previous then the current incarnation number, then I will get the rman error:
RMAN-20208: until change is before resetlogs change

run{
set until scn=547000;
restore database;
recover database;
}
executing command: set until clause
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== error message stack follows ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of set command at 10/10/2017 9:10:11
RMAN-20208: until change is before resetlogs change

Solution:
to overcome this problem, we need to set the database to old incarnation:

RMAN> shutdown immediate
RMAN> startup mount
RMAN> reset database to incarnation 2;
database reset to incarnation 2
Then after restore, you can check incarnation status again:

RMAN> run
2> {
3> set until scn=547000;
4> restore database;
5> recover database;
6> }

RMAN> alter database open resetlogs;
database opened
RMAN> list incarnation of database;
using target database control file instead of recovery catalog
List of Database Incarnations

DB Key Inc Key DB Name DB ID         STATUS  Reset SCN Reset Time
------ ------- ------- ------------- ------- --------- -----------
1      1       ORCL     1235491512   PARENT  1         03-AUG-17
2      2       ORCL     1235491512   PARENT  543000    10-OCT-17
4      4       ORCL     1235491512   CURRENT 547000    10-OCT-17
3      3       ORCL     1235491512   ORPHAN  548000    10-OCT-17







I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!

Wednesday 30 September 2015

Move a datafile with RMAN

Using RMAN is the best way before 12c to relocate a datafile with a minimum downtime. The only downtime is for switching from the old datafile to the new one and recover it. That means that the datafile size as no impact on the downtime.

Check schmea report before moving datafile.


Here is the situation before moving the datafile

RMAN> report schema
2> ;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name XE

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 360 SYSTEM *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF
2 650 SYSAUX *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\UNDOTBS1.DBF
3 25 UNDOTBS1 *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSAUX.DBF
4 100 USERS *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF


List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 C:\ORACLEXE\APP\ORACLE\ORADATA\XE\TEMP.DBF


1.Create a copy of datafile to new destination.

The first step is to create a copy of your datafile in the new destination. Here, we will copy the USERS datafile to
C:\ORACLEXE\APP\ORACLE\ORADATA2\XE:


RMAN> copy datafile 4 to 'C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF';

Starting backup at 14-01-27
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF
output file name=C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF tag=TAG20140127T132133 RECID=1 STAMP=837955296
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 14-01-27

2.Take tablespace offline.

Now I hae a copy of my datafile in the new destination, I have to switch from the old datafile to the new one. Of course this operation cannot be done online, I’ll have to put my tablespace offline, this is the begining of the downtime.

RMAN> SQL 'ALTER TABLESPACE USERS OFFLINE';

sql statement: ALTER TABLESPACE USERS OFFLINE

3.Switch old datafile to new datafile.

Now I can switch from the old datafile to the new one:

RMAN> SWITCH DATAFILE 4 TO COPY;

datafile 4 switched to datafile copy "C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF"

4.Recover the datafile.

Now we have to recover the datafile:

RMAN> RECOVER DATAFILE 4;

Starting recover at 14-01-27
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 14-01-27

5.Put tablespace back to online.

And we put back the tablespace USERS online:

RMAN> SQL 'ALTER TABLESPACE USERS ONLINE';

sql statement: ALTER TABLESPACE USERS ONLINE

6. Check status now.

Here is the new situation:

Report of database schema for database with db_unique_name XE

RMAN> report schema

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 360 SYSTEM *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF
2 650 SYSAUX *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\UNDOTBS1.DBF
3 25 UNDOTBS1 *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSAUX.DBF
4 100 USERS *** C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF

List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 C:\ORACLEXE\APP\ORACLE\ORADATA\XE\TEMP.DBF

The old datafile is kept as copy:

7.Check old datafile copy.

RMAN> list copy of datafile 4;

List of Datafile Copies
=======================

Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
2 4 A 14-01-27 379024 14-01-27
Name: C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF

Check 8.Remove old copy if do not need

We can remove it as we no longer need it:

RMAN> DELETE DATAFILECOPY 2;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
List of Datafile Copies
=======================

Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
2 4 A 14-01-27 379024 14-01-27
Name: C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF

Do you really want to delete the above objects (enter YES or NO)? yes
deleted datafile copy
datafile copy file name=C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF RECID=2 STAMP=837955601

Deleted 1 objects


And its done :)




I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!



Thursday 23 July 2015

How to catalog backups / archivelogs / datafile copies / control file copies

RMAN Catalog:It is mainly used for following:
    Can store database backup scripts and backup information to safe place(RMAN Repository)apart from target database control file.
    Can add backup pieces and image copies of backup on disk to the RMAN repository.
    Can record a data file copy as a level 0 incremental backup in the RMAN repository and that can be used foran incremental backup.
    Can record latest user-managed datafile copies to RMAN repository made after the clean shutdown of database.
Limitations and Advantages of Catalog:
To connect to target database using RMAN target database must be mounted or open.
  1. Catalog database must be OPEN if RMAN is connected to catalog database.
  2. RMAN can only catalog a datafile copy, control file copy, archived log or backup piece if these areuser-managed copy (OS level copy).
  3. Catalogis accessible on disk.
  4. File belongs to another database can not be cataloged using CATALOG.
  5. All user managed (File system) backups considered as an IMAGE COPIES by RMAN while cataloged.
  6. RMAN does not check whether the file was correctly copied by the operating system utility; it just reads and checks the header during cataloging but file should be clean(consistent) while copying through OS utilities so .
Cataloging Backups Examples:
1. Cataloging Archived Logs:Here we assumed that archive logs have been moved to other location using operating system utilities (CP/MV/COPY) and we cataloging those moved Archiveloged to RMAN REPOSITORY.
RMAN > CATALOG ARCHIVELOG ‘?/oradata/backup/arch_1.dbf’, ‘?/oradata/backup/arch_9.dbf’;
If you need to catalog multiple archive files then use below simple script which will generate .rcv file and run newly created .rcv file.
[oracle@test ~] echo > catalog.rcv for archivelog in /u01/test/arch/* ; do echo "catalog archivelog '$archivelog';" >> catalog.rcv done
Now connect to rman promt and run .rcv using below command.
[oracle@test ~] Rman target / cmdfile=catalog.rcv
2.Cataloging consistent copy of datafile as an incremental backup:Here we are cataloging datafile copy data01.dbfas an incremental level 0 backup to RMAN repository,
This datafile copy must be consistent and can be either taken by OS copy commands or by RAMN backup as copy command:
CATALOG DATAFILECOPY ‘?/oracle/oradata/data01.dbf’ LEVEL 0;
3.Cataloging controlfile copy in the RMAN Repository tken by user:
a. Take backup of controle file by using below query:
SQL> alter database backup controlfile to ‘/u01/bkp/controlfile01.dbf’;
b. Catalog above controlfile copy to RMAN REPOSITORY using blow query:
RMAN> catalog controlfilecopy ‘oracle/oradata/control01.ctl’;
4.Cataloging all the database file copies present in one Directory:
Below example will catalog all the archivelog copied using OS command to directory /u01/bkp/archlog:
RMAN> CATALOG START WITH ‘/u01/bkp/archlog’;
5.Cataloging Files in the Flash Recovery Area:Below will catalog Flash Recovery Area without prompting to user:
CATALOG RECOVERY AREA NOPROMPT;
6. Cataloging RMAN Backup Pieces:BELOW WILL CATALOG a RMAN backup piece to RMAN Repository which is manually copied using OS commands to default backup location:
CATALOG BACKUPPIECE ‘/u01/bkp/rman/KOKTSV_ORCL_RMAN_ONL_ST’;
7.Below command will catalog the Backup Pieces present in the Location set for DB_RECOVERY_FILE_DEST Parameter:
RMAN> catalog db_recovery_file_dest;
Note:catalog backuppiece, catalog recovery area, catalog start with, catalog db_recovery_file_dest commands are not available in 9i.







I hope this article helped you. Your suggestions/feedbacks are most welcome.

Keep learning... Have a great day!!!


Monday 1 June 2015

Recovery of database using RMAN backup when system datafile is lost

DB Name: TESTDB

[oracle@test dbf]$   ls
redo01.log  redo02.log  redo03.log  sysaux01.dbf  system01.dbf  temp01.dbf  undotbs01.dbf  users01.dbf

[oracle@test dbf]$  rm system01.dbf

SQL> select * from sys.aud$;
select * from sys.aud$
                  *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01116: error in opening database file 1
ORA-01110: data file 1: '/u01/app/oracle/TESTDB/oradata/dbf/system01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


Note: Since the normal shutdown is not possible in this case we shall use shut abort

SQL> shut abort
ORACLE instance shut down
[oracle@test dbf]$ sqlplus / as sysdba
SQL> startup mount


[oracle@test dbf]$ rman target/

RMAN> restore datafile 1;

Starting restore at 25-SEP-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=98 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/TESTDB/oradata/dbf/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/TESTDB/flash_recovery_area/TESTDB/backupset/ORA_rman_full_backup_ttdtest_0lpjddnk_1_1.bck
channel ORA_DISK_1: piece handle=/u01/app/oracle/TESTDB/flash_recovery_area/TESTDB/backupset/ORA_rman_full_backup_ttdtest_0lpjddnk_1_1.bck tag=FULL_OPEN_BACKUP_DISK
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 25-SEP-14



RMAN> recover datafile 1;

Starting recover at 25-SEP-14
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 22 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_22_859142042.arc
archived log for thread 1 with sequence 23 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_23_859142042.arc
archived log for thread 1 with sequence 24 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_24_859142042.arc
archived log for thread 1 with sequence 25 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_25_859142042.arc
archived log for thread 1 with sequence 26 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_26_859142042.arc
archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_27_859142042.arc
archived log for thread 1 with sequence 28 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_28_859142042.arc
archived log for thread 1 with sequence 29 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_29_859142042.arc
archived log for thread 1 with sequence 30 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_30_859142042.arc
archived log for thread 1 with sequence 31 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_31_859142042.arc
archived log for thread 1 with sequence 32 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_32_859142042.arc
archived log for thread 1 with sequence 33 is already on disk as file /u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_33_859142042.arc
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_22_859142042.arc thread=1 sequence=22
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_23_859142042.arc thread=1 sequence=23
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_24_859142042.arc thread=1 sequence=24
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_25_859142042.arc thread=1 sequence=25
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_26_859142042.arc thread=1 sequence=26
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_27_859142042.arc thread=1 sequence=27
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_28_859142042.arc thread=1 sequence=28
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_29_859142042.arc thread=1 sequence=29
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_30_859142042.arc thread=1 sequence=30
archived log file name=/u01/app/oracle/TESTDB/oradata/arch/TESTDB_1_31_859142042.arc thread=1 sequence=31
media recovery complete, elapsed time: 00:00:00
Finished recover at 25-SEP-14


sql>alter database open;



It is suggested to take RMAN backup immediately after the activity is over




I hope this article helped you. Your suggestions/feedbacks are most welcome.

Keep learning... Have a great day!!!

Tuesday 28 April 2015

Restore the database from tape backup of the Database

Suppose the entire server is lost, 
we have the  tape copy of the backup of the database , which includes RMAN backup pieces and control file backup
Assuming that were the case, we would have to rebuild the entire server, reinstall the OS and the Oracle Software, then restore the backup of the database from tape. . If the Archives and online redo are lost, the recovered database will not include all transactions,
but it will be current up to the last backup.

Steps Required
1.copy the tape backup of the database to disk
2.create the init.ora file
3.create the password file
 4.start the instance in nomount
5.restore the spfile from autobackup spfile backup piece
6.shutdown immediate
7.startup nomount
 8.RESTORE CONTROLFILE FROM AUTOBACKUP;
9.alter database mount;
10.catalog all the backup piece into RMAN
11.restore database
12.recover database;
13.alter database open resetlogs;
14. check the status of listener and if any connection issues then workout and fix the problem

Detailed Description of Steps
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@localhost Stasdb_database]$ . oraenv
ORACLE_SID = [statsdb] ?
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle

[oracle@localhost Stasdb_database]$ rman
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jun 13 15:49:57 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect target /
connected to target database (not started)

RMAN> startup nomount
Oracle instance started
Total System Global Area     893562880 bytes
Fixed Size                     2218512 bytes
Variable Size                243271152 bytes
Database Buffers             641728512 bytes
Redo Buffers                   6344704 bytes

RMAN> RESTORE SPFILE FROM '/u02/app/Stasdb_database/c-782188580-20120613-02';
Starting restore at 13-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u02/app/Stasdb_database/c-782188580-20120613-02
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 13-JUN-12

RMAN> shutdown immediate;
Oracle instance shut down

RMAN> startup nomount;

connected to target database (not started)
Oracle instance started
Total System Global Area     893562880 bytes
Fixed Size                     2218512 bytes
Variable Size                243271152 bytes
Database Buffers             641728512 bytes
Redo Buffers                   6344704 bytes

RMAN> RESTORE CONTROLFILE FROM '/u02/app/Stasdb_database/c-782188580-20120613-02';
Starting restore at 13-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/statsdb/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/statsdb/control02.ctl
Finished restore at 13-JUN-12

RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

RMAN> catalog start with '/u01/app/oracle/flash_recovery_area/statsdb';
Starting implicit crosscheck backup at 13-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
Crosschecked 100 objects
Finished implicit crosscheck backup at 13-JUN-12
Starting implicit crosscheck copy at 13-JUN-12
using channel ORA_DISK_1
Finished implicit crosscheck copy at 13-JUN-12
searching for all files in the recovery area
cataloging files...
no files cataloged
searching for all files that match the pattern /u01/app/oracle/flash_recovery_area/statsdb
List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/flash_recovery_area/statsdb/hhndeia8_1_1
File Name: /u01/app/oracle/flash_recovery_area/statsdb/hindeimj_1_1
File Name: /u01/app/oracle/flash_recovery_area/statsdb/hgndeia5_1_1
Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/statsdb/hhndeia8_1_1
File Name: /u01/app/oracle/flash_recovery_area/statsdb/hindeimj_1_1
File Name: /u01/app/oracle/flash_recovery_area/statsdb/hgndeia5_1_1

RMAN> restore database;
Starting restore at 13-JUN-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/statsdb/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/statsdb/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/statsdb/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/statsdb/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/statsdb/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/statsdb/tripointmonitor01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/statsdb/hhndeia8_1_1
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/statsdb/hhndeia8_1_1 tag=TAG20120613T144216
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:05:56
Finished restore at 13-JUN-12

RMAN> recover database;
Starting recover at 13-JUN-12
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=2345
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/statsdb/hindeimj_1_1
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/statsdb/hindeimj_1_1 tag=TAG20120613T144851
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/STATSDB/archivelog/2012_06_13/o1_mf_1_2345_7xl72djp_.arc thread=1 sequence=2345
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/STATSDB/archivelog/2012_06_13/o1_mf_1_2345_7xl72djp_.arc RECID=1851 STAMP=785865820
unable to find archived log
archived log thread=1 sequence=2346
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/13/2012 16:03:42
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 2346 and starting SCN of 92188455

RMAN> alter database open resetlogs;
database opened

RMAN>
Your database is ready to use.




I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!

Wednesday 25 February 2015

Recovery from complete loss of all online redo log files using RMAN


STEP 1: Check database details.

SQL> select instance_name,version from v$instance;

INSTANCE_NAME    VERSION
---------------- -----------------
TEST           11.2.0.3.0

SQL> select member from v$Logfile;

MEMBER
-------------------------------
/u02/ORACLE/TEST/redo03.log
/u02/ORACLE/TEST/redo02.log
/u02/ORACLE/TEST/redo01.log

STEP 2: Delete log files from os level to create scenario.

TEST:/u02/ORACLE/TEST>rm redo*.log


STEP 3: find last archive log sequence.


If one or all of the online redo logfiles are delete then the database hangs and in the alert log file we can see the following error message:

Tue Jan 30 00:47:19 2015
ARC1: Failed to archive thread 1 sequence 93 (0)
Tue Jan 30 00:47:24 2007
Errors in file /opt/oracle/admin/TEST/bdump/TEST_arc0_32722.trc:
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u02/ORACLE/TEST/redo02.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory

The file is missing at the operating system level.

Using RMAN we can recover from this error by restoring the database from the backup and recovering to the last available archived redo logfile.

From the error message in the log file we can get the last archived file in our case it is sequence 92 as the error shows that it fails to archive the log file sequence 93.


SQL> select * from v$Log;

  GROUP#   THREAD#  SEQUENCE#   BYTES    MEMBERS ARC   STATUS    FIRST_CHANGE#   FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---
    1          1         95   52428800          1 NO  CURRENT     3203078        30-JAN-15
    2          1         93   52428800          1 NO  INACTIVE    3202983        30-JAN-15
    3          1         94   52428800          1 NO  INACTIVE    3203074        30-JAN-15

At the operating system also we can find the last archived logfile:

TEST:/u02/ORACLE/TEST/arch> ls –lrt
total 54824
-rw-r-----    1 oracle   dba        714240 Jan 29 16:02 arch_1_90_613129285.dbf
-rw-r-----    1 oracle   dba      46281216 Jan 30 00:37 arch_1_91_613129285.dbf
-rw-r-----    1 oracle   dba         11264 Jan 30 00:41 arch_1_92_613129285.dbf

STEP 4: Shut down the database and startup in Mount stage.

SQL> shutdown immediate;

Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  2069680 bytes
Variable Size              92277584 bytes
Database Buffers           67108864 bytes
Redo Buffers                6316032 bytes
Database mounted.


STEP 5: Connect to rman to Restore and Recover database.

TEST:/u02/ORACLE/TEST>rman target /

Recovery Manager: Release 10.2.0.2.0 - Production on Tue Jan 30 00:53:21 2015

Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: TEST (DBID=1493612009, not open)

RMAN> run {
2> set until sequence 93;
3> restore database;
4> recover database;
5>  alter database open resetlogs;
6> }

executing command: SET until clause

Starting restore at 30-JAN-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=155 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Data Protection for Oracle: version 5.2.4.0

channel ORA_SBT_TAPE_1: starting datafile backupset restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/ORACLE/TEST/system01.dbf
restoring datafile 00002 to /u02/ORACLE/TEST/undotbs01.dbf
restoring datafile 00003 to /u02/ORACLE/TEST/sysaux01.dbf
restoring datafile 00004 to /u02/ORACLE/TEST/users01.dbf
restoring datafile 00005 to /u02/ORACLE/TEST/users02.dbf
restoring datafile 00006 to /u02/ORACLE/TEST/users03.dbf
restoring datafile 00007 to /u02/ORACLE/TEST/users05.dbf
restoring datafile 00008 to /u02/ORACLE/TEST/users06.dbf
restoring datafile 00009 to /u02/ORACLE/TEST/users07.dbf
restoring datafile 00010 to /u02/ORACLE/TEST/users04.dbf
restoring datafile 00011 to /u02/ORACLE/TEST/drtbs1.dbf
restoring datafile 00012 to /u02/ORACLE/TEST/drtbs2.dbf
restoring datafile 00013 to /tmp/undonew.dbf
channel ORA_SBT_TAPE_1: reading from backup piece 5mi8ornj_1_1
channel ORA_SBT_TAPE_1: restored backup piece 1
piece handle=5mi8ornj_1_1 tag=TAG20070130T004019
channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:01:06
Finished restore at 30-JAN-15

Starting recover at 30-JAN-15
using channel ORA_DISK_1
using channel ORA_SBT_TAPE_1

starting media recovery

archive log thread 1 sequence 92 is already on disk as file /u02/ORACLE/TEST/arch/arch_1_92_613129285.dbf
archive log filename=/u02/ORACLE/TEST/arch/arch_1_92_613129285.dbf thread=1 sequence=92
media recovery complete, elapsed time: 00:00:01
Finished recover at 30-JAN-15

database opened

RMAN>exit

STEP 6: Check all the files are created physically.

The recovery process creates the online redo logfiles at the operating system level also.

TEST:/u02/ORACLE/TEST>ls -lrt redo*
-rw-r-----    1 oracle   dba      52429312 Jan 30 01:00 redo03.log
-rw-r-----    1 oracle   dba      52429312 Jan 30 01:00 redo02.log
-rw-r-----    1 oracle   dba      52429312 Jan 30 01:00 redo01.log

Since we have done an incomplete recover with open resetlogs, we should take a fresh complete backup of the database.

NOTE: Please make sure you remove all the old archived logfiles from the archived area.








I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!