Oracle 18c – Table recovery using RMAN Backup

Oracle 18c – Table recovery using RMAN Backup

Description:-

In this article we are going to see table recovery using RMAN backup.

Let’s start the Demo:-

Steps to recover the table using RMAN backup :-

Step 1:- User creation 

SQL> create user hari identified by "oracle" default tablespace users temporary tablespace temp profile default account unlock

User created.

Step 2:- Provide grant privileges and allocate quota for  “hari” user

SQL> grant create session, create table to hari

Grant succeeded.

SQL> alter user hari quota 500M on users

User altered.

Step 3:- Table creation

SQL> conn hari/oracle

SQL> create table emp(id number);

Table created.

SQL> begin
for i in 1 .. 100000 loop
insert into emp values(i);
end loop;
end;
/

PL/SQL procedure successfully completed.

SQL> select count(*) from emp;

COUNT(*)
----------
100000


SQL> SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW" FROM DUAL;

NOW
-------------------
08-14-2018 21:53:42


Step 4:- Ensure that database in ARCHIVELOG mode and take a whole database backup

SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/18.0.0/dbhome_1/dbs/arch
Oldest online log sequence 2
Current log sequence 4
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1660943808 bytes
Fixed Size 8658368 bytes
Variable Size 1056964608 bytes
Database Buffers 587202560 bytes
Redo Buffers 8118272 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/product/18.0.0/dbhome_1/dbs/arch
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4


SQL> alter database open;

Database altered.

You can’t restore a table that hasn’t been backed up, even if it exists in current archive logs.

Take a full database backup

RMAN> backup database plus archivelog;

Starting backup at 14-AUG-18
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=4 RECID=1 STAMP=984173730
input archived log thread=1 sequence=5 RECID=2 STAMP=984173864
input archived log thread=1 sequence=6 RECID=3 STAMP=984173913
input archived log thread=1 sequence=7 RECID=4 STAMP=984174371
input archived log thread=1 sequence=8 RECID=5 STAMP=984174523
channel ORA_DISK_1: starting piece 1 at 14-AUG-18
channel ORA_DISK_1: finished piece 1 at 14-AUG-18
piece handle=/u01/fra/PROD18C/backupset/2018_08_14/o1_mf_annnn_TAG20180814T214843_fq6073xg_.bkp tag=TAG20180814T214843 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 14-AUG-18

Starting backup at 14-AUG-18
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=/u01/app/oracle/oradata/PROD18C/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD18C/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD18C/undotbs01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/PROD18C/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-AUG-18
channel ORA_DISK_1: finished piece 1 at 14-AUG-18
piece handle=/u01/fra/PROD18C/backupset/2018_08_14/o1_mf_nnndf_TAG20180814T214847_fq60774d_.bkp tag=TAG20180814T214847 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 14-AUG-18

Starting backup at 14-AUG-18
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=9 RECID=6 STAMP=984174572
channel ORA_DISK_1: starting piece 1 at 14-AUG-18
channel ORA_DISK_1: finished piece 1 at 14-AUG-18
piece handle=/u01/fra/PROD18C/backupset/2018_08_14/o1_mf_annnn_TAG20180814T214932_fq608ndg_.bkp tag=TAG20180814T214932 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-AUG-18

Starting Control File and SPFILE Autobackup at 14-AUG-18
piece handle=/u01/fra/PROD18C/autobackup/2018_08_14/o1_mf_s_984174573_fq608owz_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 14-AUG-18

Step 5:- Drop the table

SQL> drop table hari.emp;

Table dropped.

SQL> select * from hari.emp;

no rows selected.

Step 6:- Recover  emp table 

RMAN> recover table hari.emp until time "to_date('2018-08-14 21:53:42','yyyy-mm-dd:hh24:mi:ss')" auxiliary destination '/u01/fra';

Starting recover at 14-AUG-18
using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=72 device type=DISK
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID='sAyh'
initialization parameters used for automatic instance:
db_name=PROD18C
db_unique_name=sAyh_pitr_PROD18C
compatible=18.0.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1584M
processes=200
db_create_file_dest=/u01/fra
log_archive_dest_1='location=/u01/fra'
#No auxiliary parameter file used
starting up automatic instance PROD18C
Oracle instance started
Total System Global Area 1660943808 bytes
Fixed Size 8658368 bytes
Variable Size 419430400 bytes
Database Buffers 1224736768 bytes
Redo Buffers 8118272 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2018-08-14 21:53:42','yyyy-mm-dd:hh24:mi:ss')";
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET until clause
Starting restore at 14-AUG-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=8 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 /u01/fra/PROD18C/autobackup/2018_08_14/o1_mf_s_984174811_fq60j3or_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fra/PROD18C/autobackup/2018_08_14/o1_mf_s_984174811_fq60j3or_.bkp tag=TAG20180814T215331
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/fra/PROD18C/controlfile/o1_mf_fq60txkl_.ctl
Finished restore at 14-AUG-18

sql statement: alter database mount clone database
sql statement: alter system archive log current
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2018-08-14 21:53:42','yyyy-mm-dd:hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 3 to new;
set newname for clone tempfile 1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 4, 3;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /u01/fra/PROD18C/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 14-AUG-18
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 /u01/fra/PROD18C/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/fra/PROD18C/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/fra/PROD18C/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/fra/PROD18C/backupset/2018_08_14/o1_mf_nnndf_TAG20180814T215243_fq60gmvn_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fra/PROD18C/backupset/2018_08_14/o1_mf_nnndf_TAG20180814T215243_fq60gmvn_.bkp tag=TAG20180814T215243
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:17
Finished restore at 14-AUG-18
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=984175242 file name=/u01/fra/PROD18C/datafile/o1_mf_system_fq60v51s_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=984175242 file name=/u01/fra/PROD18C/datafile/o1_mf_undotbs1_fq60v52y_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=984175242 file name=/u01/fra/PROD18C/datafile/o1_mf_sysaux_fq60v52l_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2018-08-14 21:53:42','yyyy-mm-dd:hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 4 online";
sql clone "alter database datafile 3 online";
# recover and open database read only
recover clone database tablespace "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 4 online
sql statement: alter database datafile 3 online
Starting recover at 14-AUG-18
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 11 is already on disk as file /u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_11_fq60j1vs_.arc
archived log for thread 1 with sequence 12 is already on disk as file /u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_12_fq60t0xc_.arc
archived log file name=/u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_11_fq60j1vs_.arc thread=1 sequence=11
archived log file name=/u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_12_fq60t0xc_.arc thread=1 sequence=12
media recovery complete, elapsed time: 00:00:01
Finished recover at 14-AUG-18
sql statement: alter database open read only
contents of Memory Script:
{
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
''/u01/fra/PROD18C/controlfile/o1_mf_fq60txkl_.ctl'' comment=
''RMAN set'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script
sql statement: create spfile from memory
database closed
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1660943808 bytes
Fixed Size 8658368 bytes
Variable Size 419430400 bytes
Database Buffers 1224736768 bytes
Redo Buffers 8118272 bytes
sql statement: alter system set control_files = ''/u01/fra/PROD18C/controlfile/o1_mf_fq60txkl_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1660943808 bytes
Fixed Size 8658368 bytes
Variable Size 419430400 bytes
Database Buffers 1224736768 bytes
Redo Buffers 8118272 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2018-08-14 21:53:42','yyyy-mm-dd:hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 7 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 7;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 14-AUG-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=34 device type=DISK
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 00007 to /u01/fra/SAYH_PITR_PROD18C/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/fra/PROD18C/backupset/2018_08_14/o1_mf_nnndf_TAG20180814T215243_fq60gmvn_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fra/PROD18C/backupset/2018_08_14/o1_mf_nnndf_TAG20180814T215243_fq60gmvn_.bkp tag=TAG20180814T215243
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 14-AUG-18
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=984175357 file name=/u01/fra/SAYH_PITR_PROD18C/datafile/o1_mf_users_fq6112n9_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2018-08-14 21:53:42','yyyy-mm-dd:hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 7 online";
# recover and open resetlogs
recover clone database tablespace "USERS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 7 online
Starting recover at 14-AUG-18
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 11 is already on disk as file /u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_11_fq60j1vs_.arc
archived log for thread 1 with sequence 12 is already on disk as file /u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_12_fq60t0xc_.arc
archived log file name=/u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_11_fq60j1vs_.arc thread=1 sequence=11
archived log file name=/u01/fra/PROD18C/archivelog/2018_08_14/o1_mf_1_12_fq60t0xc_.arc thread=1 sequence=12
media recovery complete, elapsed time: 00:00:00
Finished recover at 14-AUG-18
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/fra''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/fra''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/fra''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/fra''

Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_sAyh_zwzh":
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> . . exported "HARI"."EMP" 873.1 KB 100000 rows
EXPDP> Master table "SYS"."TSPITR_EXP_sAyh_zwzh" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_sAyh_zwzh is:
EXPDP> /u01/fra/tspitr_sAyh_75879.dmp
EXPDP> Job "SYS"."TSPITR_EXP_sAyh_zwzh" successfully completed at Tue Aug 14 22:06:43 2018 elapsed 0 00:02:52
Export completed

contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script

Oracle instance shut down

Performing import of tables...
IMPDP> Master table "SYS"."TSPITR_IMP_sAyh_zBwj" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_sAyh_zBwj":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "HARI"."EMP" 873.1 KB 100000 rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
IMPDP> Job "SYS"."TSPITR_IMP_sAyh_zBwj" successfully completed at Tue Aug 14 22:07:30 2018 elapsed 0 00:00:35
Import completed

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/fra/PROD18C/datafile/o1_mf_temp_fq60xs6s_.tmp deleted
auxiliary instance file /u01/fra/SAYH_PITR_PROD18C/onlinelog/o1_mf_3_fq611jxw_.log deleted
auxiliary instance file /u01/fra/SAYH_PITR_PROD18C/onlinelog/o1_mf_2_fq6118dc_.log deleted
auxiliary instance file /u01/fra/SAYH_PITR_PROD18C/onlinelog/o1_mf_1_fq61189k_.log deleted
auxiliary instance file /u01/fra/SAYH_PITR_PROD18C/datafile/o1_mf_users_fq6112n9_.dbf deleted
auxiliary instance file /u01/fra/PROD18C/datafile/o1_mf_sysaux_fq60v52l_.dbf deleted
auxiliary instance file /u01/fra/PROD18C/datafile/o1_mf_undotbs1_fq60v52y_.dbf deleted
auxiliary instance file /u01/fra/PROD18C/datafile/o1_mf_system_fq60v51s_.dbf deleted
auxiliary instance file /u01/fra/PROD18C/controlfile/o1_mf_fq60txkl_.ctl deleted
auxiliary instance file tspitr_sAyh_75879.dmp deleted
Finished recover at 14-AUG-18

Step 7:- Check the table count

 SQL> select count(*) from hari.emp;

COUNT(*)
---------
100000

Catch Me On:- Hariprasath Rajaram

Telegram:https://t.me/joinchat/I_f4DhGF_Zifr9YZvvMkRg
LinkedIn:https://www.linkedin.com/in/hari-prasath-aa65bb19/
Facebook:https://www.facebook.com/HariPrasathdba
FB Group:https://www.facebook.com/groups/894402327369506/
FB Page: https://www.facebook.com/dbahariprasath/?
Twitter: https://twitter.com/hariprasathdba

Duplicate a Database Using RMAN in Oracle Database 12c Release 2

Description:-

This is the article which will guide you step-by-step Duplicating a Database Using RMAN in Oracle Database 12c Release 2

SOURCE DATABASE (ORCL):

Step1:-Copy the password file to target database 

oracle:dbs] scp orapworcl oracle@clone:$ORACLE_HOME/dbs/orapwclone
orapworcl 100% 3584 3.5KB/s 00:00

Step2:-Create pfile from SOURCE database for TARGET database

SQL> show parameter spfile;
NAME     TYPE    VALUE
———————————— ———————
spfile    string /oradb/app/oracle/product/12.2.0.1/db_1/dbs/spfileorcl.ora

SQL> create pfile from spfile;
File created.

Step3:-Copy the pfile to the target database

[oracle@orcl:dbs] scp initorcl.ora oracle@clone:$ORACLE_HOME/dbs/initclone.ora
initorcl.ora 100% 1095 1.1KB/s 00:00

TARGET DATABASE:

Step 4:-Create required directories in the TARGET location

Create adump,datafiles and logfiles location

mkdir -p /oradb/app/oracle/admin/clone/adump
mkdir -p /oradb/app/oracle/oradata/clone/

 

Step 5:-Edit the db_name and necessary directories name in pfile.

  • Edit db_name to new database name
  • Add the below the entries for datafiles and logfiles creation

*.db_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’
*.log_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’

vi initclone.ora (PFILE Target Database Clone)

*.audit_file_dest=’/oradb/app/oracle/admin/clone/adump’
*.db_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’

*.log_file_name_convert=’/oradb/app/oracle/oradata/orcl’,’/oradb/app/oracle/oradata/clone’

*.control_files=’/oradb/app/oracle/oradata/clone/control01.ctl’,’/oradb/app/oracle/oradata/clone/control02.ctl’

*.db_name=’clone’

Step 6:-Set the Environment for CLONE database,

clone()
{
ORACLE_HOME=/oradb/app/oracle/product/12.2.0.1/db_1
export ORACLE_HOME
ORACLE_BASE=/oradb/app/oracle
export ORACLE_BASE
ORACLE_SID=clone
export ORACLE_SID
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:.
export LD_LIBRARY_PATH
LIBPATH=$ORACLE_HOME/lib32:$ORACLE_HOME/lib:/usr/lib:/lib
export LIBPATH
TNS_ADMIN=${ORACLE_HOME}/network/admin
export TNS_ADMIN
PATH=$ORACLE_HOME/bin:$PATH:.
export PATH
}

Step 7:-Open the CLONE database in NOMOUNT state using modified pfile,

SQL>startup pfile nomount=’$ORACLE_HOME/dbs/initclone.ora’
ORACLE instance started.

Total System Global Area 1610612736 bytes
Fixed Size 8621232 bytes
Variable Size 1040188240 bytes
Database Buffers 553648128 bytes
Redo Buffers 8155136 bytes

Step 8:-Configure the listener & tnsnames on both server

cd $ORACLE_HOME/network/admin

LISTENER ENTRY:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcl.localdomain.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = clone.localdomain.com)(PORT = 1521))
)

TNSNAMES ENTRY:

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcl.localdomain.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.localdomain.com)
)
)

CLONE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = clone.localdomain.com)(PORT = 1521))
(CONNECT_DATA =
(out = DEDICATED)
(SERVICE_NAME = clone.localdomain.com)
)
)

RMAN Active Duplication:

NOFILENAMECHECK: If you want the duplicate filenames to be the same as the target filenames, and if the databases are in different hosts, then you must specify NOFILENAMECHECK

db_file_name_convert: This parameter specifies from where to where the datafiles should be cloned.

log_file_name_convert:This parameter specifies from where to where the redo logfiles should be cloned

Connect as auxiliary database to create a new database in TARGET location

[oracle@clone:admin clone] rman target sys/oracle@orcl auxiliary sys/oracle

Recovery Manager: Release 12.2.0.1.0 – Production on Fri May 25 23:17:41 2018
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1504791090)
connected to auxiliary database: CLONE (not mounted)

RMAN> duplicate database to ‘clone’ from active database NOFILENAMECHECK;

Starting Duplicate Db at 25-MAY-18 23:17:57
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=35 device type=DISK
current log archived
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 1610612736 bytes
Fixed Size 8621232 bytes
Variable Size 1040188240 bytes
Database Buffers 553648128 bytes
Redo Buffers 8155136 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''ORCL'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''clone'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone from service 'ORCL' primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''clone'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1610612736 bytes
Fixed Size 8621232 bytes
Variable Size 1040188240 bytes
Database Buffers 553648128 bytes
Redo Buffers 8155136 bytes
Starting restore at 25-MAY-18 23:18:46
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=34 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oradb/app/oracle/oradata/clone/control01.ctl
output file name=/oradb/app/oracle/oradata/clone/control02.ctl
Finished restore at 25-MAY-18 23:18:47
database mounted
contents of Memory Script:
{
set newname for datafile 1 to
"/oradb/app/oracle/oradata/clone/system01.dbf";
set newname for datafile 3 to
"/oradb/app/oracle/oradata/clone/sysaux01.dbf";
set newname for datafile 4 to
"/oradb/app/oracle/oradata/clone/undotbs01.dbf";
set newname for datafile 7 to
"/oradb/app/oracle/oradata/clone/users01.dbf";
restore
from nonsparse from service
'ORCL' clone database;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 25-MAY-18 23:18:52
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oradb/app/oracle/oradata/clone/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:37
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oradb/app/oracle/oradata/clone/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:26
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oradb/app/oracle/oradata/clone/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:05
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oradb/app/oracle/oradata/clone/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 25-MAY-18 23:20:01
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'ORCL'
archivelog from scn 1788668;
switch clone datafile all;
}
executing Memory Script
Starting restore at 25-MAY-18 23:20:02
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=16
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service ORCL
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 25-MAY-18 23:20:05
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=977095205 file name=/oradb/app/oracle/oradata/clone/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=977095205 file name=/oradb/app/oracle/oradata/clone/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=977095205 file name=/oradb/app/oracle/oradata/clone/undotbs01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=977095205 file name=/oradb/app/oracle/oradata/clone/users01.dbf
contents of Memory Script:
{
set until scn 1789727;
recover
clone database
delete archivelog;
}
executing Memory Script
executing command: SET until clause
Starting recover at 25-MAY-18 23:20:05
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 16 is already on disk as file /oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_16_977010357.dbf
archived log for thread 1 with sequence 17 is already on disk as file /oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_17_977010357.dbf
archived log file name=/oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_16_977010357.dbf thread=1 sequence=16
archived log file name=/oradb/app/oracle/product/12.2.0.1/db_1/dbs/arch1_17_977010357.dbf thread=1 sequence=17
media recovery complete, elapsed time: 00:00:00
Finished recover at 25-MAY-18 23:20:06
Oracle instance started
Total System Global Area 1610612736 bytes
Fixed Size 8621232 bytes
Variable Size 1040188240 bytes
Database Buffers 553648128 bytes
Redo Buffers 8155136 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''CLONE'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
}
executing Memory Script
sql statement: alter system set db_name = ''CLONE'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance started
Total System Global Area 1610612736 bytes
Fixed Size 8621232 bytes
Variable Size 1040188240 bytes
Database Buffers 553648128 bytes
Redo Buffers 8155136 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CLONE" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/oradb/app/oracle/oradata/clone/redo01.log' ) SIZE 200 M REUSE,
GROUP 2 ( '/oradb/app/oracle/oradata/clone/redo02.log' ) SIZE 200 M REUSE,
GROUP 3 ( '/oradb/app/oracle/oradata/clone/redo03.log' ) SIZE 200 M REUSE
DATAFILE
'/oradb/app/oracle/oradata/clone/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for tempfile 1 to
"/oradb/app/oracle/oradata/clone/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/oradb/app/oracle/oradata/clone/sysaux01.dbf",
"/oradb/app/oracle/oradata/clone/undotbs01.dbf",
"/oradb/app/oracle/oradata/clone/users01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /oradb/app/oracle/oradata/clone/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/oradb/app/oracle/oradata/clone/sysaux01.dbf RECID=1 STAMP=977095231
cataloged datafile copy
datafile copy file name=/oradb/app/oracle/oradata/clone/undotbs01.dbf RECID=2 STAMP=977095231
cataloged datafile copy
datafile copy file name=/oradb/app/oracle/oradata/clone/users01.dbf RECID=3 STAMP=977095231
datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=977095231 file name=/oradb/app/oracle/oradata/clone/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=977095231 file name=/oradb/app/oracle/oradata/clone/undotbs01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=3 STAMP=977095231 file name=/oradb/app/oracle/oradata/clone/users01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 25-MAY-18 23:21:07

Step 9:-Verify the status of TARGET database status,

SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
——   — ——–
CLONE     READ WRITE

Reference:-

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/bradv/rman-duplicating-databases.html#GUID-D8CFCA95-85F7-4824-B2CC-32C37A42F9FF

Catch Me On:- Hariprasath Rajaram

LinkedIn:                  https://www.linkedin.com/in/hari-prasath-aa65bb19/
Facebook:                 https://www.facebook.com/HariPrasathdba
Facebook Group:   https://www.facebook.com/groups/894402327369506/
Facebook Page:      https://www.facebook.com/dbahariprasath/?
Twitter:                     https://twitter.com/hariprasathdba