Search This Blog

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

Wednesday, September 7, 2011

Clone Database on 11g with Duplicate RMAN on same host

Clone database of PRODUCATION on same host is a quite frequent to do task of DBA's.
Use the following simple step to achieve the same.
Step:
1. backup source database through RMAN
2. create needful administration directories (like ORADATA)
3. create init parameter file for duplicate database (using any text editor create the init.ora file)
4. create oracle services via oradim utility
5. create password file for duplicate database via ORAPWD utility
6. configure tns entry for source and target database
7. startup duplicate database in nomount mode with the help of init.ora file
8. connect rman client with target and auxiliary database
9. execute duplicate database command
10. You have done it successfully.
11. create the SPFILE for duplicate database.
12. take backup of duplicate database (optional)


OS: WINDOWS 2003
SOURCE DB: ORG
TARGET DB: DUP


NOTE: 1. FLASH RECOVERY AREA IS NOT CONFIGURED SO BACKUP WILL STORE IN THE %ORACLE_HOME%/database folder
2. OEM is not configured. (FYI)



1. backup source database through RMAN

CMD> set oracle_sid=org
CMD> rman target sys
password: xxxxxxx


RMAN> backup database plus archivelog;




2. create needful administration directories (like ORADATA)
In the 11g , you just need to create directories for ORADATA


3. create init parameter file for duplicate database (using any text editor create the init.ora file)
The following parameter is required. (mandatory)

DB_NAME=dup
control_files=D:\APP\ADMINISTRATOR\ORADATA\dup\CONTROL01.CTL, D:\APP\ADMINISTRATOR\ORADATA\dup\CONTROL02.CTL
db_block_size=8192
db_file_name_convert='D:\app\Administrator\oradata\org','D:\app\Administrator\oradata\dup'
LOG_file_name_convert='D:\app\Administrator\oradata\org','D:\app\Administrator\oradata\dup'





4. create oracle services via oradim utility
CMD>ORADIM -NEW -SID DUP -STARTMODE manual




5. create password file for duplicate database via ORAPWD utility
CMD>ORAPWD FILE=%ORACLE_HOME%\database\pwddup.ora password=oracle




6. configure tns entry for source and target database

ORG =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.4.78)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = org)
    )
  )


7. startup duplicate database in nomount mode with the help of init.ora file
CMD> set oracle_sid=dup
CMD> sqlplus sys/oracle as sysdba
SQL> startup nomount pfile='c:\init_dup.ora' -- my pfile is located under c: drive




8. connect rman client with target and auxiliary database
CMD> rman target sys@org auxiliary sys 
NOTE: i used tns entry to connect to source database and auxiliary database at same time.




9. execute duplicate database command

C:\>rman target sys@org  auxiliary sys


Recovery Manager: Release 11.2.0.2.0 - Production on Wed Sep 7 12:16:14 2011


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


target database Password:
connected to target database: ORG (DBID=1479245426)
auxiliary database Password:
connected to auxiliary database: DUP (not mounted)


RMAN> run
2> {
3> set until sequence 4 thread 1;
4> duplicate target database to dup;
5> }


executing command: SET until clause


Starting Duplicate Db at 07-SEP-11
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=96 device type=DISK


contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script


sql statement: create spfile from memory


contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script


Oracle instance shut down


connected to auxiliary database (not started)
Oracle instance started


Total System Global Area     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes


contents of Memory Script:
{
   set until scn  769666;
   sql clone "alter system set  db_name =
 ''ORG'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''DUP'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script


executing command: SET until clause


sql statement: alter system set  db_name =  ''ORG'' comment= ''Modified by RMAN
duplicate'' scope=spfile


sql statement: alter system set  db_unique_name =  ''DUP'' comment= ''Modified b
y RMAN duplicate'' scope=spfile


Oracle instance shut down


Oracle instance started


Total System Global Area     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes


Starting restore at 07-SEP-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=95 device type=DISK


channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\ADMINISTRATOR\11.2.0\DB
\DATABASE\03MLUO8R_1_1
channel ORA_AUX_DISK_1: piece handle=D:\APP\ADMINISTRATOR\11.2.0\DB\DATABASE\03M
LUO8R_1_1 tag=TAG20110907T113023
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\CONTROL01.CTL
output file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\CONTROL02.CTL
Finished restore at 07-SEP-11


database mounted


contents of Memory Script:
{
   set until scn  769666;
   set newname for datafile  1 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSTEM01.DBF";
   set newname for datafile  2 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSAUX01.DBF";
   set newname for datafile  3 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\UNDOTBS01.DBF";
   set newname for datafile  4 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\USERS01.DBF";
   restore
   clone database
   ;
}
executing Memory Script


executing command: SET until clause


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


Starting restore at 07-SEP-11
using channel ORA_AUX_DISK_1


channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\SYSTEM01.DBF
channel ORA_AUX_DISK_1: restoring datafile 00002 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\SYSAUX01.DBF
channel ORA_AUX_DISK_1: restoring datafile 00003 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\UNDOTBS01.DBF
channel ORA_AUX_DISK_1: restoring datafile 00004 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\USERS01.DBF
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\ADMINISTRATOR\11.2.0\DB
\DATABASE\02MLUO6F_1_1
channel ORA_AUX_DISK_1: piece handle=D:\APP\ADMINISTRATOR\11.2.0\DB\DATABASE\02M
LUO6F_1_1 tag=TAG20110907T113023
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 07-SEP-11


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script


datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=761228440 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\SYSTEM01.DBF
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=761228441 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\SYSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=761228441 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\UNDOTBS01.DBF
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=761228441 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\USERS01.DBF


contents of Memory Script:
{
   set until scn  769666;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script


executing command: SET until clause


Starting recover at 07-SEP-11
using channel ORA_AUX_DISK_1


starting media recovery


archived log for thread 1 with sequence 3 is already on disk as file C:\ARCH\ARC
0000000003_0761225013.0001
archived log file name=C:\ARCH\ARC0000000003_0761225013.0001 thread=1 sequence=3


media recovery complete, elapsed time: 00:00:02
Finished recover at 07-SEP-11
Oracle instance started


Total System Global Area     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes


contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''DUP'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script


sql statement: alter system set  db_name =  ''DUP'' comment= ''Reset to original
 value by RMAN'' scope=spfile


sql statement: alter system reset  db_unique_name scope=spfile


Oracle instance shut down


connected to auxiliary database (not started)
Oracle instance started


Total System Global Area     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG


  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( 'D:\APP\ADMINISTRATOR\ORADATA\DUP\REDO01.LOG' ) SIZE 50 M  REUSE,
  GROUP  2 ( 'D:\APP\ADMINISTRATOR\ORADATA\DUP\REDO02.LOG' ) SIZE 50 M  REUSE,
  GROUP  3 ( 'D:\APP\ADMINISTRATOR\ORADATA\DUP\REDO03.LOG' ) SIZE 50 M  REUSE
 DATAFILE
  'D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSTEM01.DBF'
 CHARACTER SET WE8MSWIN1252




contents of Memory Script:
{
   set newname for tempfile  1 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\TEMP01.DBF";
   switch clone tempfile all;
   catalog clone datafilecopy  "D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSAUX01.DBF",


 "D:\APP\ADMINISTRATOR\ORADATA\DUP\UNDOTBS01.DBF",
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\USERS01.DBF";
   switch clone datafile all;
}
executing Memory Script


executing command: SET NEWNAME


renamed tempfile 1 to D:\APP\ADMINISTRATOR\ORADATA\DUP\TEMP01.DBF in control fil
e


cataloged datafile copy
datafile copy file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSAUX01.DBF RECID=1 ST
AMP=761228527
cataloged datafile copy
datafile copy file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\UNDOTBS01.DBF RECID=2 S
TAMP=761228527
cataloged datafile copy
datafile copy file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\USERS01.DBF RECID=3 STA
MP=761228527


datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=761228527 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\SYSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=761228527 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\UNDOTBS01.DBF
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=761228527 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\USERS01.DBF


contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script


database opened
Finished Duplicate Db at 07-SEP-11





10. You have done it successfully.

C:\>set oracle_sid=dup


C:\>sqlplus sys/oracle as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Wed Sep 7 12:22:53 2011


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




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select dbid,name from v$database;


      DBID NAME
---------- ---------
 132033645 DUP


SQL> conn sys@org/oracle as sysdba
Connected.
SQL> select dbid,name from v$database;


      DBID NAME
---------- ---------
1479245426 ORG


SQL> conn sys/oracle as sysdba
Connected.
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            D:\app\Administrator\11.2.0\db\RDBMS
Oldest online log sequence     1
Next log sequence to archive   1
Current log sequence           1
SQL>





11. create SPFILE for the duplicate database

C:\>set oracle_sid=dup


C:\>sqlplus sys/oracle as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Wed Sep 7 12:54:10 2011


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




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> create spfile from pfile;
create spfile from pfile
*
ERROR at line 1:
ORA-32002: cannot create SPFILE already being used by the instance




SQL> --if you check physical then file is not exist becuase duplicate db
SQL> --started with clone spfile
SQL> --therefore shutdown the db and create spfile and start with spfile
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile='c:\init_dup.ora';


File created.


SQL> startup
ORACLE instance started.


Total System Global Area  150667264 bytes
Fixed Size                  1382112 bytes
Variable Size              92277024 bytes
Database Buffers           50331648 bytes
Redo Buffers                6676480 bytes
Database mounted.
Database opened.



12. take backup of duplicate database (optional)


write me email in case of any queries at askdbataj

Tuesday, July 26, 2011

Redo Log Recovery

Tips:
Oracle Certification - Tips

DBA Preparation - Tips

Practical DBA - Tips



Oracle Version: 10.1.0.5.0
OS: Windows
Archivelog ENABLE
Backup Method RMAN

The method of recovery from loss of all members of an online log group depends on a number of factors, such as:


1. The state of the database (open, crashed, closed consistently, and so on)



If you lose the current group, and the database is not closed consistently (either it is open, or it has crashed), then you will have to restore an old backup and perform point-in-time recovery, followed by OPEN RESETLOGS. You will lose all transactions that were in the lost log. You should take a new full database backup immediately after the OPEN RESETLOGS. Backups from before the OPEN RESETLOGS will not be recoverable because of the lost log.



Error found in ALERT.LOG file



Mon Aug 13 16:45:58 2007
Errors in file c:\oracle\product\10.1.0\admin\orcl\udump\orcl_ora_4044.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: 'C:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\REDO03.LOG'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.


First check LOST redo group is current or non-current.


SQL> select group#,status from v$Log;

GROUP# STATUS
---------- ----------------
1 INACTIVE
2 INACTIVE
3 CURRENT ----> lost group


Note: Lost group is related to current.


Logon to RMAN

RMAN>run
{
restore database;
recover database;
}



Log on to sqlplus prompt

SQL>recover database until cancel;
cancel;

SQL>alter database open resetlogs;







2. whether the lost redo log group was current



If you lose the current redo log group, and if the database is closed consistently, then you can perform OPEN RESETLOGS with no transaction loss. However, you should take a new full database backup. Backups from before the OPEN RESETLOGS will not be recoverable because of the lost log.



3. Whether the lost redo log group was archived



If you lose a noncurrent redo log group, then you can use the ALTER DATABASE CLEAR LOGFILE statement to re-create all members in the group. No transactions are lost. If the lost redo log group was archived before it was lost, then nothing further is required. Otherwise, you should immediately take a new full backup of your database. Backups from before the log was lost will not be recoverable because of the lost log.


Below Error message found in ALERT.LOG file and database is stop(SHUTDOWN ABORT) ...


Mon Aug 13 12:50:50 2007
Errors in file c:\oracle\product\10.1.0\admin\orcl\bdump\orcl_lgwr_3904.trc:
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: 'C:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\REDO02.LOG'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.


How to recover redo log files.

Note: We have last valid backup and all archivelog files.


Logon to SQL prompt with SYS user


SQL>conn / as sysdba
connected to idle instance

SQL>startup mount


SQL>--First check which REDO group is lost.


SQL> select group#, status from v$log;

GROUP# STATUS
---------- ----------------
1 INVALIDATED
2 UNUSED------>lost group
3 INACTIVE

SQL> --Note current REDOGRP is 1 and lost REDOLOG GRP 2.
Note: NON-Current group is LOST.


SQL> --Note current REDOGRP is 1 and lost REDOLOG GRP 2.


SQL> alter database clear logfile group 2;

Database altered.

SQL> alter database open;

Database altered.



Logon to RMAN


RMAN> run
2> {
3> restore database;
4> recover database;
5> }

Tuesday, July 29, 2008

Oracle Block Change Tracking

RMAN block change tracking

With Oracle 10gr1 Enterprise Edition Oracle introduce Block change tracking feature which use to FAST / Speed up RMAN Incremental Backup.

What is BLOCK CHANGE TRACKING?

RMAN's change tracking feature for incremental backups improves incremental backup performance by recording changed blocks in each datafile in a change tracking file. If change tracking is enabled, RMAN uses the change tracking file to identify changed blocks for incremental backup, thus avoiding the need to scan every block in the datafile.

After enabling change tracking, the first level 0 incremental backup still has to scan the entire datafile, as the change tracking file does not yet reflect the status of the blocks. Subsequent incremental backup that use this level 0 as parent will take advantage of the change tracking file.

Source: Oracle documentation

1. Enable Block Change tracking and set location

Before enabling we must to set/specify block change tracking location.There is two way to specify block change tracking location1. using DB_CREATE_FILE_DEST parameter which use OMF file name.

SQL> alter system set db_create_file_dest='location' SCOPE=BOTH;

SQL> alter database enable block change tracking;

2. Manually specify location for the block change tracking

SQL>alter database enable block change tracking using file 'location';

2. Disable block change tracking

SQL> alter database disable block change tracking;

NOTE: BCT files deleted automatically by oracle when BCT is disabled.

3. Reset the location of Block change tracking file

There are two options for this

1. shutdown the database and set the new location

SQL> shutdown database

SQL> move BCT file to new location

SQL> startup mount

SQL> alter database rename file 'old_location' TO 'new_location';

SQL> alter database open;

or


2. disable the block change tracking / set the new location / enable BCT

SQL> alter database DISABLE block change tracking;

SQL> alter database enable block change tracking using FILE 'NEW_LOCATION';

After that RMAN use new location for the BCT.

4. Checking the information about block change tracking enable or disable

Check v$BLOCK_CHANGE_TRACKING view

5. BCT file is important for restore and recovery of database.

Answer: No, it is doesn't require for Database Recovery of database

6. What happen if BCT file is lost and corrupted.

Answer: That is very interesting case here, suppose oracle found if BCT file is corrupted or missing then oracle will automatically recreate new BCT file.

Let see some practial view...

1. Enable BCT

SQL> alter database enable block change tracking using file 'e:\bct.dbf';
Database altered.

2. Check the status and default size.

SQL> select * from v$block_change_tracking;
STATUS FILENAME BYTES

---------- ---------------------------------------- ----------

ENABLED E:\BCT.DBF 11599872

NOTE: Filesize created is 11 mb by default.

3. Now check alertsid log file what entries we found.

Mon Jul 28 20:06:53 2008

alter database enable block change tracking using file 'e:\bct.dbf'

Block change tracking file is current.

Starting background process CTWR

Mon Jul 28 20:06:54 2008

CTWR started with pid=20, OS id=464

Block change tracking service is active.

Completed: alter database enable block change tracking using file 'e:\bct.dbf'


4. Disable BCT

SQL> alter database disable block change tracking;
Database altered.

SQL> select * from v$block_change_tracking;
STATUS FILENAME BYTES

---------- ---------------------------------------- ----------

DISABLED

5. Check alertsid log file

Mon Jul 28 20:12:41 2008

alter database disable block change tracking

Mon Jul 28 20:12:41 2008

Block change tracking service stopping.

Stopping background process CTWR

Deleted file E:\BCT.DBF

Completed: alter database disable block change tracking

6. Suppose BCT file lost or missing then what oracle will do...

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> host del c:\bct.dbf

SQL> startup

ORACLE instance started.
[output cut]

Database mounted.

Database opened.

Now check the alertlog file for more information about how oracle create new BCT file when missing or lost.

Mon Jul 28 20:16:54 2008

ALTER DATABASE OPEN

CHANGE TRACKING is enabled for this database, but the

change tracking file can not be found. Recreating the file.

Change tracking file recreated.

Block change tracking file is current.

See Also: Incremental Backup Algorithm

Sunday, July 27, 2008

Oracle RMAN TSPITR

Oracle RMAN TSPITR

Oracle RMAN TSPITR through we can recover one or more tablespace or other database objects without any trouble or affect rest of database objects.


We can use RMAN TSPITR in the following conditions

1. Recovering data lost after an erroneous TRUNCATE TABLE statement;
2. Recovering from logical corruption of a table;
3. Undoing the effects of an incorrect batch job or other DML statement that has affected only a subset of the database;
4. Recovering a logical schema to a point different from the rest of the physical database, when multiple schemas exist in separate tablespaces of one physical database.

Limitations of TSPITR

http://download.oracle.com/docs/cd/B19306_01/backup.102/b14191/rcmtspit001.htm#ABC1041015
Choosing the Right Target Time for TSPITR

It is extremely important that we choose the right target time or SCN for TSPITR. becuase once we bring tablespace ONLINE after TSPITR, we can't use any backup from a time earlier than the moment we brought the tablespace online.

Basic RMAN TSPITR

There are three options available for TSPITR

1. Fully automated TSPITR

2. Customized TSPITR with an automatic auxiliary instance

3. TSPITR with our own auxiliary instance

NOTE: Oracle recommended to use FULLY AUTOMATED TSPITR.

In Fully automated TSPITR oracle done entire process, there are two requirement which we need to prepare.

1. Specify auxiliary destination

2. Manually configure rman channel for auxiliary instance

Let see how RMAN TSPITR help us to recover one or more objects in

database with few commands

Deni working as an Oracle DBA in ABC bank, there developement team by mistake run wrong script which update all tables with wrong entries in particular schema.

Here I am using "scott" schema or "USERS" tablespace

NOTE: Must You have valid database backup & DB run in Archivelog mode to perform TSPITR.

Wrong script truncate all tables in Scott Schema, Now deni have task to recover all tables.

17:53:33 SQL> truncate table SCOTT.SALGRADE;
Table truncated.

For example above salgrade table is truncated by mistake from development team.

17:53:44 SQL> host rman target /
Recovery Manager: Release 10.1.0.2.0 - Production
Copyright (c) 1995, 2004, Oracle. All rights reserved.
connected to target database: TEST (DBID=1959343326)

RMAN> recover tablespace USERS until time "to_date('27-JUL-2008 17:53:23','DD-MON-YYYY HH24:MI:SS')" AUXILIARY DESTINATION='f:\auxiliary';

Starting recover at 27-JUL-08

using target database controlfile instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=143 devtype=DISK

Creating automatic instance
initialization parameters used for automatic instance:db_name=TEST

compatible=10.1.0.2.0

db_block_size=8192

db_unique_name=tspitr_TEST_rmzx

large_pool_size=1M

#No auxiliary parameter file used

db_create_file_dest=f:\auxiliary

control_files=f:\auxiliary/cntrl_tspitr_TEST_rmzx.f

starting up automatic instance TEST
Oracle instance started

Total System Global Area 117440512 bytes
Fixed Size 787728 bytes

Variable Size 65272560 bytes

Database Buffers 50331648 bytes

Redo Buffers 1048576 bytes

Automatic instance created
contents of Memory Script:{

# set the until clauseset until time "to_date('27-JUL-2008 17:53:23','DD-MON-YYYY HH24:MI:SS')";

# restore the controlfile

restore clone controlfile;

# mount the controlfile

sql clone 'alter database mount clone database';

# archive current online log for tspitr to a resent until time

sql 'alter system archive log current';

# avoid unnecessary autobackups for structural changes during TSPITR

sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';}executing Memory Script
executing command: SET until clause
Starting restore at 27-JUL-08

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=29 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore

channel ORA_AUX_DISK_1: restoring controlfile

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=F:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\TEST\BACKUPSET\2008_07_27\O1_MF_NCSNF_TAG20080727T175226_48RZFO1D_.BKP tag=TAG20080727T175226

channel ORA_AUX_DISK_1: restore complete

output filename=F:\AUXILIARY\CNTRL_TSPITR_TEST_RMZX.F

Finished restore at 27-JUL-08

sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
contents of Memory Script:{

# generated tablespace point-in-time recovery script

# set the until clauseset until time "to_date('27-JUL-2008 17:53:23','DD-MON-YYYY HH24:MI:SS')";plsql <<<-- tspitr_2

declare sql

statement varchar2(512); offline_not_needed exception; pragma exception_init(offline_not_needed, -01539);begin sqlstatement := 'alter tablespace ' 'USERS' ' offline for recover'; krmicd.writeMsg(6162, sqlstatement); krmicd.execSql(sqlstatement);exception when offline_not_needed then null;end; >>>;

# set an omf destination filename for restoreset newname for clone datafile 1 to new;

# set an omf destination filename for restoreset newname for clone datafile 2 to new;

# set a destination filename for restoreset newname for datafile 4 to "F:\ORACLE\PRODUCT\10.1.0\ORADATA\TEST\USERS01.DBF";

# restore the tablespaces in the recovery set plus the auxilliary tablespacesrestore clone datafile 1, 2, 4;

switch clone datafile all;

#online the datafiles restored or flipped

sql clone "alter database datafile 1 online";

#online the datafiles restored or flipped

sql clone "alter database datafile 2 online";

#online the datafiles restored or flipped

sql clone "alter database datafile 4 online";

# make the controlfile point at the restored datafiles, then recover themrecover clone database tablespace "USERS", "SYSTEM", "UNDOTBS1" delete archivelog;alter clone database open resetlogs;

# PLUG HERE the creation of a temporary tablespace if export fails due to lack of temporary space.

# For example in Windows these two lines would do that:

#sql clone "create tablespace aux_tspitr_tmp

# datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";

sql clone "alter tablespace temp

add tempfile ''f:/tmp/aux_tspitr_tmp.dbf'' size 5M";

}

executing Memory Script
executing command: SET until clause
sql statement: alter tablespace USERS offline for recover
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 27-JUL-08using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restorechannel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup setrestoring datafile 00001 to F:\AUXILIARY\TSPITR_T\DATAFILE\O1_MF_SYSTEM_%U_.DBFrestoring datafile 00002 to F:\AUXILIARY\TSPITR_T\DATAFILE\O1_MF_UNDOTBS1_%U_.DBFrestoring datafile 00004 to F:\ORACLE\PRODUCT\10.1.0\ORADATA\TEST\USERS01.DBFchannel ORA_AUX_DISK_1: restored backup piece 1piece handle=F:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\TEST\BACKUPSET\2008_07_27\O1_MF_NNNDF_TAG20080727T175226_48RZDV59_.BKP tag=TAG20080727T175226channel ORA_AUX_DISK_1: restore completeFinished restore at 27-JUL-08
datafile 1 switched to datafile copyinput datafilecopy recid=3 stamp=661197349 filename=F:\AUXILIARY\TSPITR_T\DATAFILE\O1_MF_SYSTEM_48RZLD8P_.DBFdatafile 2 switched to datafile copyinput datafilecopy recid=2 stamp=661197327 filename=F:\AUXILIARY\TSPITR_T\DATAFILE\O1_MF_UNDOTBS1_48RZLDB5_.DBF
sql statement: alter database datafile 1 online
sql statement: alter database datafile 2 online
sql statement: alter database datafile 4 online
Starting recover at 27-JUL-08using channel ORA_AUX_DISK_1
starting media recovery
archive log thread 1 sequence 5 is already on disk as file F:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2008_07_27\O1_MF_1_5_48RZL9PD_.ARCarchive log filename=F:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2008_07_27\O1_MF_1_5_48RZL9PD_.ARC thread=1 sequence=5

media recovery complete

Finished recover at 27-JUL-08
database opened
sql statement: alter tablespace temp add tempfile ''f:/tmp/aux_tspitr_tmp.dbf''size 5M
contents of Memory Script:{

# export the tablespaces in the recovery set

host 'exp userid =\"/@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=oracle)(ARGV0[/a]=oraclermzx)(ARGS=^'(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))^')(ENVS=^'ORACLE_SID=rmzx^'))(CONNECT_DATA=(SID=rmzx))) as sysdba\" point_in_time_recover=y tablespaces= USERS file=tspitr_a.dmp';

# shutdown clone before import

shutdown clone immediate

# import the tablespaces in the recovery set

host 'imp userid =\"/@ as sysdba\" point_in_time_recover=y file=tspitr_a.dmp';

# online/offline the tablespace importedsql "alter tablespace USERS online";sql "alter tablespace USERS offline";

# enable autobackups in case user does open resetlogs from RMAN after TSPITR

sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';}executing Memory Script

Export: Release 10.1.0.2.0 - Production on Sun Jul 27 17:56:06 2008
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsExport done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character setNote: table data (rows) will not be exported
About to export Tablespace Point-in-time Recovery objects...

For tablespace USERS ....

exporting cluster definitions.

exporting table definitions. .

exporting table DEPT. .

exporting table EMP. .

exporting table BONUS. .

exporting table SALGRADE.

exporting referential integrity constraints.

exporting triggers. end point-in-time recovery

Export terminated successfully without warnings.

host command complete
database closed

database dismounted

Oracle instance shut down

Import: Release 10.1.0.2.0 - Production on Sun Jul 27 17:56:21 2008
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production

With the Partitioning, OLAP and Data Mining options
Export file created by EXPORT:V10.01.00 via conventional pathAbout to import Tablespace Point-in-time Recovery objects...

import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set.

importing SCOTT's objects into SCOTT. .

importing table "DEPT". .

importing table "EMP". .

importing table "BONUS". .

importing table "SALGRADE".

importing SYS's objects into SYS

Import terminated successfully without warnings.

host command complete
sql statement: alter tablespace USERS online
sql statement: alter tablespace USERS offline
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
Removing automatic instanceAutomatic instance removedauxiliary instance datafile F:\AUXILIARY\CNTRL_TSPITR_TEST_RMZX.F deletedauxiliary instance datafile F:\AUXILIARY\TSPITR_T\DATAFILE\O1_MF_SYSTEM_48RZLD8P_.DBF deletedauxiliary instance datafile F:\AUXILIARY\TSPITR_T\DATAFILE\O1_MF_UNDOTBS1_48RZLDB5_.DBF deletedauxiliary instance datafile F:\AUXILIARY\TSPITR_T\ONLINELOG\O1_MF_1_48RZMKWQ_.LOG deletedauxiliary instance datafile F:\AUXILIARY\TSPITR_T\ONLINELOG\O1_MF_2_48RZML59_.LOG deletedauxiliary instance datafile F:\AUXILIARY\TSPITR_T\ONLINELOG\O1_MF_3_48RZMLDM_.LOG deletedFinished recover at 27-JUL-08

RMAN> backup tablespace USERS;

NOTE: Oracle Recommended to Take tablespace backup

Starting backup at 27-JUL-08

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupsetinput datafile fno=00004 name=F:\ORACLE\PRODUCT\10.1.0\ORADATA\TEST\USERS01.DBFchannel ORA_DISK_1: starting piece 1 at 27-JUL-08channel ORA_DISK_1: finished piece 1 at 27-JUL-08piece handle=F:\ORACLE\PRODUCT\10.1.0\FLASH_RECOVERY_AREA\TEST\BACKUPSET\2008_07_27\O1_MF_NNNDF_TAG20080727T175710_48RZOPXP_.BKP comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01Finished backup at 27-JUL-08

RMAN> sql "alter tablespace USERS online";
sql statement: alter tablespace USERS online

NOTE: Now take tablespace ONLINE.

RMAN> exit
Recovery Manager complete.

17:57:45 SQL> select count(*) from scott.salgrade;
COUNT(*)

----------

5

User sysdba connect must be use Operating system authentication otherwise following error occurs.

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 07/27/2008 18:11:19RMAN-04006: error from auxiliary database:

ORA-01031: insufficient privileges

If your getting below error

About to export Tablespace Point-in-time Recovery objects...
EXP-00008: ORACLE error 25153 encountered
ORA-25153: Temporary Tablespace is Empty
ORA-06512: at "SYS.DBMS_PITR", line 887
ORA-06512: at line 1
EXP-00000: Export terminated unsuccessfully
host command complete

check solution: http://dbataj.blogspot.com/2008/07/rman-tspitr-ora-25153.html