Tabs

Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

Tuesday, March 17, 2015

How to perform Database Point in Time Recovery(DBPITR)



DBPITR abbreviates to Database point in time recovery. When we want to rewind our database back to a previous time then we can use DBPITR to do that.

When we have performed some unwanted changes in our database and we want to undo that, we can perform DBPITR to undo that. 

Only perform DBPITR when you are not able to undo the unwanted change with Flashback technology.


Disadvantages:-


1. It’s a time consuming process as whole database has to be restored from the backup and recovered to an earlier time using archive logs and incremental backups.


2. Unlike TSPITR in which only particular tablespace objects are inaccessible whole database is unavailable during this entire process. 


3. All changes which are made after the TIME or SCN or log sequence which we used in DBPITR will be lost.


Requirements:-


1. Database has to be in archive log mode.

2. A valid backup of full database is needed and all archive logs or incremental backup after that backup will be required.

##NOTE: - When we have to undo those changes which are present in a different incarnation then DBPITR has to be done because we cannot rewind particular objects to a different incarnation, we have to rewind whole database.


Example:-


Consider we create a table named AMIT and AMIT_BCKUP and insert some records in that. Now accidentally we performed a drop command on table. Now we want to rewind our database to a time before drop operation. PFB steps:-

Recovery Manager11.2.0.1.0
RMAN> Backup database plus archivelog;
Starting backup at 17-MAR-15
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=146 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=59 STAMP=874609124
channel ORA_DISK_1: starting piece 1 at 17-MAR-15
channel ORA_DISK_1: finished piece 1 at 17-MAR-15
piece handle=D:\APP\BACKUP\FLASHBACK\ORCL\BACKUPSET\2015_03_17\O1_MF_ANNNN_TAG20150317T185844_BJJC0F3C_.BKP tag=TAG20150317T185844 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 17-MAR-15

Starting backup at 17-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=D:\APP\CYBADMIN\ORADATA\ORCL\SYSTEM01.DBF
input datafile file number=00002 name=D:\APP\CYBADMIN\ORADATA\ORCL\SYSAUX01.DBF
input datafile file number=00003 name=D:\APP\CYBADMIN\ORADATA\ORCL\UNDOTBS01.DBF
input datafile file number=00004 name=D:\APP\CYBADMIN\ORADATA\ORCL\USERS01.DBF
input datafile file number=00005 name=D:\APP\CYBADMIN\ORADATA\ORCL\EXAMPLE01.DBF
channel ORA_DISK_1: starting piece 1 at 17-MAR-15
channel ORA_DISK_1: finished piece 1 at 17-MAR-15
piece handle=D:\APP\BACKUP\FLASHBACK\ORCL\BACKUPSET\2015_03_17\O1_MF_NNNDF_TAG20150317T185846_BJJC0H48_.BKP tag=TAG20150317T185846 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 17-MAR-15
channel ORA_DISK_1: finished piece 1 at 17-MAR-15
piece handle=D:\APP\BACKUP\FLASHBACK\ORCL\BACKUPSET\2015_03_17\O1_MF_NCSNF_TAG20150317T185846_BJJC2VKF_.BKP tag=TAG20150317T185846 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 17-MAR-15

Starting backup at 17-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=60 STAMP=874609205
channel ORA_DISK_1: starting piece 1 at 17-MAR-15
channel ORA_DISK_1: finished piece 1 at 17-MAR-15
piece handle=D:\APP\BACKUP\FLASHBACK\ORCL\BACKUPSET\2015_03_17\O1_MF_ANNNN_TAG20150317T190005_BJJC2XPC_.BKP tag=TAG20150317T190005 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 17-MAR-15
RMAN> EXIT
Recovery Manager complete.
D:\>sqlplus scott
Pasword:
Connected.
SQL> select * from tab;

TNAME                          TABTYPE  CLUSTERID                              
------------------------------ ------- ----------                              
DEPT                           TABLE                                           
EMP                            TABLE                                           
MURALI                         TABLE                                           
TEST                           TABLE                                           

SQL> drop table Murali purge;
Table dropped.

SQL> drop table test purge;
Table dropped.

SQL> drop table EMP purge;
Table dropped.

SQL> drop table DEPT purge;
Table dropped.

SQL> select * from tab;
no rows selected

SQL> conn sys
Password:
Connected.
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1603411968 bytes                                      
Fixed Size                  2176168 bytes                                      
Variable Size            1073744728 bytes                                      
Database Buffers          520093696 bytes                                      
Redo Buffers                7397376 bytes                                      
Database mounted.
SQL> EXIT

D:\app\Backup>rman target sys

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 17 19:04:48 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
target database Password:
connected to target database: ORCL (DBID=1380168819, not open)
RMAN> run
2>  {
3> set until time "sysdate-1/24/60*5";   
########### We rewind our database 5 mins before###########
#set until scn 10023;  
#set until sequence 345 thread 2;  
#set until restore point Murali_RESTORE; 
#######Murali_RESTORE point already created##########
#####Any one of the above set line we can use########### 
4> restore database;
5> recover database;
6> }
Recovery Manager11.2.0.1.0
RMAN> 2> 3> 4> 5> 6>
executing command: SET until clause
Starting restore at 17-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 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 D:\APP\CYBADMIN\ORADATA\ORCL\SYSTEM01.DBF
channel ORA_DISK_1: restoring datafile 00002 to D:\APP\CYBADMIN\ORADATA\ORCL\SYSAUX01.DBF
channel ORA_DISK_1: restoring datafile 00003 to D:\APP\CYBADMIN\ORADATA\ORCL\UNDOTBS01.DBF
channel ORA_DISK_1: restoring datafile 00004 to D:\APP\CYBADMIN\ORADATA\ORCL\USERS01.DBF
channel ORA_DISK_1: restoring datafile 00005 to D:\APP\CYBADMIN\ORADATA\ORCL\EXAMPLE01.DBF
channel ORA_DISK_1: reading from backup piece D:\APP\BACKUP\FLASHBACK\ORCL\BACKUPSET\2015_03_17\O1_MF_NNNDF_TAG20150317T185846_BJJC0H48_.BKP
channel ORA_DISK_1: piece handle=D:\APP\BACKUP\FLASHBACK\ORCL\BACKUPSET\2015_03_17\O1_MF_NNNDF_TAG20150317T185846_BJJC0H48_.BKP tag=TAG20150317T185846
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 17-MAR-15
Starting recover at 17-MAR-15
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:02
Finished recover at 17-MAR-15
RMAN>
RMAN> alter database open resetlogs;
database opened
RMAN>Exit
D:\app\Backup>sqlplus scott
Password:
SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID                             
------------------------------ ------- ----------                             
DEPT                           TABLE                                          
EMP                            TABLE                                          
MURALI                         TABLE                                          
TEST                           TABLE                                          

SQL> select * from DEPT;
    DEPTNO DNAME      LOC                                                     
---------- ---------- ----------                                              
        10 ACCOUNTING NEW YORK                                                
        20 RESEARCH   DALLAS                                                  
        30 SALES      CHICAGO                                                 
        40 OPERATIONS BOSTON                                                  
SQL>

Wednesday, January 14, 2015

RMAN: target database incarnation is not current in recovery catalog

A surprising database backup failure report was delivered to my mailbox, upon checking with the log revealed the below pasted RMAN- errors. This left me wondering as to how come the rman backup would fail for no reason with an error like this, there is something fishy about the situation.

RMAN> 
RMAN-00571: ====================================================
RMAN-00569: ========== ERROR MESSAGE STACK FOLLOWS ============= 
RMAN-00571: ====================================================
RMAN-06004: ORACLE error from recovery catalog database:
RMAN-20011: target database incarnation is not current in recovery catalog

Here are the steps below that were performed to fix the issue of incarnation.

UNIX:~/dba/log > rman target / catalog rman_user/rman_pass@rcat.acme.com

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Jan 26 06:45:20 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: PROD (DBID=2706003900)
connected to recovery catalog database

RMAN>  list incarnation of database;

RMAN> exit
 
as you can see above, no incarnations listed.
 
UNIX:~/dba/log >  . oraenv
ORACLE_SID = [oracle] ? PROD
UNIX:~/dba/log > rman target / nocatalog
 
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Jan 26 06:46:58 2009
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
connected to target database: PROD (DBID=2706003900)
using target database control file instead of recovery catalog
 
RMAN> list incarnation of database;
List of Database Incarnations
DB Key Inc Key DB Name DB ID      STATUS  Reset SCN Reset Time
------ ------- ------- ---------- ------- --------- ----------
  1      1      PROD   2706003900 CURRENT    1      07-FEB-07
 
RMAN> exit

The database PROD with the DBID (2706003900) and DBINC_KEY (875312) has to 
be reset in the recovery catalog and re-registered for its backups to 
resume.
 
UNIX:~/dba/log > rman target / catalog rman_user/rman_pass@rcat.acme.com
 
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Jan 26 07:00:56 2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: PROD (DBID=2706003900)
connected to recovery catalog database
 
RMAN> RESET DATABASE TO INCARNATION 875312;
 
database reset to incarnation 875312
 
RMAN> register database;
 
starting full resync of recovery catalog
  
full resync complete
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of register command on default channel at 05/26/2009 07:40:05
RMAN-20002: target database already registered in recovery catalog
 
RMAN>
RMAN> list incarnation of database; 
List of Database Incarnations 

DB Key Inc Key DB Name DB ID      STATUS    Reset SCN  Reset Time
------ ------- ------- ---------- ------- ------------ ----------
875311 875312  PROD    2706003900 CURRENT            1  07-FEB-07
875311 9179422 PROD2   2706003900 ORPHAN 6203845546338 24-MAY-09 

RMAN> exit 
Recovery Manager complete.

Tuesday, January 13, 2015

How to Move datafile into Oracle ASM using RMAN

How to move a datafile that was created on the OS to ASM.

Issue:
Datafile created on the OS instead of in ASM

Given:
RAC 3 nodes
tablespace has multiple datafiles 

 Check the status of the file:
select df.file#,to_char(df.creation_time,'mm-dd-yyyy hh24:mi:ss') created,df.name,ts.name,df.status from v$datafile df,v$tablespace ts where df.ts#=ts.ts# and df.file#=127;


FILE# CREATION_TIME       NAME                        TS_NAME        STATUS
----- ------------------- --------------------------- -------------- ------
127   12-10-2015 05:06:27 dbhome_1/dbs/DBNAME_DATA_01 APPS_TS_TX_IDX ONLINE


RMAN> connect target /

connected to target database: DBNAME (DBID=2919937482)

RMAN> copy datafile 127 to '+DBNAME_DATA_01';
Starting backup at 10-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=854 instance=DBNAME1 device type=DISK
allocated channel: ORA_DISK_2

channel ORA_DISK_1: starting datafile copy
input datafile file number=00127 name=/icm01/u0001/app/oracle/product/11.2.0/dbhome_1/dbs/DBNAME_DATA_01
output file name=+DBNAME_DATA_01/DBNAME/datafile/apps_ts_tx_idx.480.801661731 tag=TAG20121210T114844 RECID=54 STAMP=801661781
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:56
Finished backup at 10-DEC-12

Starting Control File and SPFILE Autobackup at 10-DEC-12
piece handle=+DBNAME_FRA_01/DBNAME/autobackup/2012_12_10/s_801661785.5682.801661787 comment=NONE
Finished Control File and SPFILE Autobackup at 10-DEC-12

RMAN> switch datafile 127 to copy;
datafile 127 switched to datafile copy "+DBNAME_DATA_01/DBNAME/datafile/apps_ts_tx_idx.480.801661731"

RMAN> exit


Recovery Manager complete.


SQL*Plus: Release 11.2.0.1.0 Production on Mon Dec 10 11:50:32 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options




FILE# CREATION_TIME       NAME                     TS_NAME          STATUS
----- ------------------- ------------------------ ---------------- -------
127   12-10-2015 05:06:27
+apps_ts_tx_idx.480.   APPS_TS_TX_IDX RECOVER
                        801661731

>rman

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Dec 10 11:51:22 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect target /

connected to target database: DBNAME (DBID=2919937482)

RMAN> recover datafile 127;

Starting recover at 10-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=3679 instance=DBNAME1 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=3955 instance=DBNAME1 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=4524 instance=DBNAME1 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=4799 instance=DBNAME1 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=5082 instance=DBNAME1 device type=DISK

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

Finished recover at 10-DEC-12

RMAN> exit
Recovery Manager complete.

SQL*Plus: Release 11.2.0.1.0 Production on Mon Dec 10 11:52:06 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options



FILE# CREATION_TIME       NAME                     TS_NAME          STATUS
----- ------------------- ------------------------ ---------------- -------
127   12-10-2015 05:06:27
+apps_ts_tx_idx.480.   APPS_TS_TX_IDX OFFLINE
                        801661731


SQL> alter database datafile 127 online;
Database altered.

SQL>

FILE# CREATION_TIME       NAME                     TS_NAME          STATUS
----- ------------------- ------------------------ ---------------- -------
127   12-10-2015 05:06:27
+apps_ts_tx_idx.480.   APPS_TS_TX_IDX ONLINE
                        801661731

DBNAMEb01cdp(DBNAME1)  /icm01/u0001/app/oracle/product/11.2.0/dbhome_1/dbs
>rm DBNAME_DATA_01