About Me

My photo
Bangalore, India
I am an Oracle Certified Professional working in SAP Labs. Everything written on my blog has been tested on my local environment, Please test before implementing or running in production. You can contact me at amit.rath0708@gmail.com.

Friday, December 19, 2014

How to create a Standby Database in RAC using RMAN Duplicate command

We can also use RMAN duplicate command to create a STANDBY RAC database from Production Standalone/RAC database. We can either use Backups of Production Database or we can create from Active Database also.

PFB steps to create a Standby Database in RAC using Active Database Duplication Method :-

Primary Database is TEST
Standby Database is STBY(RAC)

Changes to be done on Primary side :-

1. Database has to be archive log mode

SQL> SELECT log_mode FROM v$database;

LOG_MODE
------------
ARCHIVELOG

2. Change primary database to Force Logging mode :-

SQL> ALTER DATABASE FORCE LOGGING;

Database altered.

3. Initialization parameters in Primary database :-

SQL>  show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      TEST
SQL> show parameter db_unique_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string      TEST

4. Set the DG_CONFIG setting of LOG_ARCHIVE_CONFIG parameter. for this DB_UNIQUE_NAME of  Standby database has to be different from primary.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(TEST,STBY)';

System altered.

5. Set suitable remote archivelog destinations.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=STBY NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=STBY';

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

System altered.

-- NOTE :- Service and DB_UNIQUE_NAME has to be of Standby database

6. Set parameters related to LOG_ARCHIVE and password file parameters :-

SQL> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE;

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=8;

System altered.

SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;

System altered.

7. It is recommended to make sure that Primary can switch roles to become a Standby. For that we need to set some -convert parameters if there are path differences between the servers :-

SQL> ALTER SYSTEM SET FAL_SERVER=STBY;

System altered.

SQL> ALTER SYSTEM SET DB_FILE_NAME_CONVERT=' ',' ' SCOPE=SPFILE;   -- Primay server destination and Standby server destination

System altered.

SQL> ALTER SYSTEM SET LOG_FILE_NAME_CONVERT=' ',' '  SCOPE=SPFILE;  -- Primay server destination and Standby server destination

System altered.

SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

8. As some parameters cannot be changed while database is open , we need to restart database to before they take effect :-

SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup
ORACLE instance started.

Total System Global Area  960495616 bytes
Fixed Size                  1222816 bytes
Variable Size             247465824 bytes
Database Buffers          700448768 bytes
Redo Buffers               11358208 bytes
Database mounted.
Database opened.
SQL>

9. In both servers entries of Primary as well as Standby are needed in tnsnames.ora file and we are able to do  tnsping.

###################ORACLE_DATA_GAURD############################

TEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary_server)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

STBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = SCAN-IP)(PORT = 9010))
    (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = STBY.wellsfargo.com)
    )
  )

STBY1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = VIP-Firstnode)(PORT = 9001))
    (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = STBY.wellsfargo.com)
       (INSTANCE_NAME = STBY1)
    )
  )
STBY2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = VIP-SECONDnode)(PORT = 9001))
    (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = STBY.wellsfargo.com)
       (INSTANCE_NAME = STBY2)
    )
  )

TEST_DGMGRL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary_server)(PORT = 9001))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST_DGMGRL)
    )
  )
STBY_DGMGRL =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = SCAN-IP)(PORT = 9001))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = STBY_DGMGRL)
    )
  )
###################ORACLE_DATA_GAURD############################

10. Add static entries to listener.ora file

PRIMARY

  (SID_DESC =
 (GLOBAL_DBNAME = test.db.com)
 (SID_NAME = TEST)
 (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
   )
   (SID_DESC =
   (GLOBAL_DBNAME=TEST_DGMGRL)
   (ORACLE_HOME=/opt/oracle/product/database/11.2.0.4)
   (SID_NAME=test)
   )

STANDBY

  First node :-

 (SID_DESC =
    (GLOBAL_DBNAME = STBY.wellsfargo.com)
    (SID_NAME = STBY1)
    (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
  )
 (SID_DESC =
    (GLOBAL_DBNAME = STBY_DGMGRL.wellsfargo.com)
    (SID_NAME = STBY1)
    (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
  )

Second Node :-

  (SID_DESC =
    (GLOBAL_DBNAME = STBY.wellsfargo.com)
    (SID_NAME = STBY2)
    (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
  )
  (SID_DESC =
    (GLOBAL_DBNAME = STBY_DGMGRL.wellsfargo.com)
    (SID_NAME = STBY2)
    (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
  )

11. Reload listener after adding these entries

Lsnrctl reload

12. Add Standby redo logs to primary database :-

ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo01.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo02.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo03.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo04.log') SIZE 50M;

13. Copy the passw0rd file from Primary and copy to Standby

14. Copy the init.ora file from primary and change below parameters :-

CREATE PFILE='/initTEST.ora' from spfile;

scp orapwTEST user@STBY_server:$ORACLE_HOME/dbs/orapwSTBY1
scp initTEST.ora user@STBY_server:$ORACLE_HOME/dbs/initSTBY1.ora

Steps to be done in STANDBY Side :-

15 . Update Pfile for below parameters for Standby server

    *.audit_file_dest='/ora_backup/duplicate_test/STBY/adump'
    *.diagnostic_dest='/ora_backup/duplicate_test/STBY/diag'

16. Start the STANDBY database with above pfile

export ORACLE_SID=STBY1
sql> startup nomount pfile='$ORACLE_HOME/dbs/initSTBY1.ora'
ORACLE instance started.

Total System Global Area  960495616 bytes
Fixed Size                  1222816 bytes
Variable Size             264243040 bytes
Database Buffers          683671552 bytes
Redo Buffers               11358208 bytes
               
17. Connect to RMAN and use RMAN duplicate command to create STANDBY


rman target sys/****@TEST_DGMGRL auxiliary sys/****@STBY_DGMGRL
run
{
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
allocate auxiliary channel ch3 device type disk;
allocate auxiliary channel ch4 device type disk;
DUPLICATE TARGET DATABASE
  FOR STANDBY
  from active database
   DORECOVER
   spFILE
        SET db_unique_name='STBY' COMMENT 'Is STANDBY'
    SET LOG_ARCHIVE_DEST_2='SERVICE=TEST ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=TEST'
                set control_files='+DATA_0220/STBY/controlfile/control01.ctl','+FRA_0220/STBY/controlfile/control02.ctl'
                set db_create_file_dest='+DATA_0220/'
                set db_create_online_log_dest_1='+DATA_0220/'
                set diagnostic_dest='/ora_backup/duplicate_test/STBY/diag'
                set audit_file_dest='/ora_backup/duplicate_test/STBY/adump'
                set db_recovery_file_dest='+FRA_0220/'
                set db_file_name_convert='/ora_backup/TEST1/restore_test/TEST/DATA/','+DATA_0220/STBY/'
                set log_file_name_convert='/ora_backup/TEST1/restore_test/TEST/','+DATA_0220/STBY/'
                set FAL_SERVER='TEST'
set cluster_database='false'
set instance_number='1'
set LOG_ARCHIVE_DEST_1='location=+FRA_0220/STBY/';

}  

Above command will create the STANDBY database

18. Create pfile from spfile

        create pfile='/ora_backup/duplicate_test/STBY/initTEST.ora' from spfile;

19. Add the below parametErs for RAC database

STBY1.log_archive_format='%t_%s_%r.dbf'
STBY2.log_archive_format='%t_%s_%r.dbf'
STBY2.thread=2
STBY1.thread=1
STBY1.undo_tablespace='UNDOTBS1'
STBY2.undo_tablespace='UNDOTBS2'
STBY2.instance_number=2
STBY1.instance_number=1
STBY1.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = first_node)(PORT = 9001))'
STBY2. local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = second_node)(PORT = 9001))'
*.cluster_database=TRUE

20. Start the instance with above pfile

==>sqlplus

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 18 12:51:57 2014

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

Enter user-name: /as sysdba

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

SQL> startup force pfile='/ora_backup/duplicate_test/STBY/initTEST.ora';
ORACLE instance started.

Total System Global Area 1060585472 bytes
Fixed Size                  2260000 bytes
Variable Size             679478240 bytes
Database Buffers          369098752 bytes
Redo Buffers                9748480 bytes
Database mounted.
Database opened.
SQL>
SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
TEST     READ ONLY

SQL> create spfile='+DATA_0220/STBY/spfileSTBY.ora' from pfile='/ora_backup/duplicate_test/STBY/initTEST.ora';

File created.

SQL> startup force
ORACLE instance started.

Total System Global Area 1060585472 bytes
Fixed Size                  2260000 bytes
Variable Size             679478240 bytes
Database Buffers          369098752 bytes
Redo Buffers                9748480 bytes
Database mounted.
Database opened.

SQL> show parameter cluster

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cluster_database                     boolean     TRUE
cluster_database_instances           integer     2
cluster_interconnects                string
SQL>
SQL> show parameter listenner
SQL> show parameter listener

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
listener_networks                    string
local_listener                       string      (ADDRESS = (PROTOCOL = TCP)(HO
                                                 ST = first_node)(PORT = 9001))
remote_listener                      string      scan_ip:9010

21. Login to second instance 

Export ORACLE_SID=STBY2
==>sqlplus

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 18 13:01:32 2014

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

Enter user-name: /as sysdba
Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1060585472 bytes
Fixed Size                  2260000 bytes
Variable Size             679478240 bytes
Database Buffers          369098752 bytes
Redo Buffers                9748480 bytes
Database mounted.
Database opened.

SQL> select name,open_mode,database_role from v$database;

NAME      OPEN_MODE            DATABASE_ROLE
--------- -------------------- ----------------
TEST        READ ONLY WITH APPLY PHYSICAL STANDBY

SQL> select INST_ID,INSTANCE_NAME,HOST_NAME,VERSION,LOGINS from gv$instance;

   INST_ID INSTANCE_NAME    HOST_NAME                 VERSION           LOGINS
---------- ---------------- ------------------------- ----------------- ----------
         2 STBY2         wuprd02a0220              11.2.0.4.0        ALLOWED
         1 STBY1         wuprd01a0220              11.2.0.4.0        ALLOWED

SQL> show parameter listener

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
listener_networks                    string
local_listener                       string      (ADDRESS = (PROTOCOL = TCP)(HO
                                                 ST = second_node)(PORT = 9001))
remote_listener                      string      scan_ip:9010
SQL>

Check all the parameters in both instances are same or not

22. Start the recovery process

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

23. Add the details of Standby database in OCR

Srvctl add database –d STBY –o $ORACLE_HOME -p 
Srvctl add instance –d STBY –i STBY1-n firstnode
Srvctl add instance –d STBY –I STBY2 –n secondnode
Srvctl status database –d STBY

24. Create the broker configuration details ( for both Primary and Standby):-

SQL>  alter system set dg_broker_start=FALSE;

System altered.

SQL> alter system set dg_broker_config_file1='/opt/oracle/product/database/11.2.0.4/dbs/dr1STBY.dat';

SQL> alter system set dg_broker_config_file2='/opt/oracle/product/database/11.2.0.4/dbs/dr2STBY.dat';

System altered.

SQL> alter system set dg_broker_start=TRUE;

System altered.

Create the configuation

DGMGRL> connect /
Connected.
DGMGRL> create configuration DR as primary database is TEST connect identifier is TEST;
Configuration "dr" created with primary database "TEST"

DGMGRL> add database STBY as connect identifier is STBY  maintained as physical;
Database "STBY" added
DGMGRL> show configuration

Configuration - dr

  Protection Mode: MaxPerformance
  Databases:
    TEST   - Primary database
    STBY - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
DISABLED

DGMGRL> enable configuration
Enabled.

Check if every thing is fine by checking Standby Database details 

DGMGRL> show database STBY

Database - STBY

  Role:            PHYSICAL STANDBY
  Intended State:  APPLY-ON
  Transport Lag:   0 seconds (computed 1 second ago)
  Apply Lag:       0 seconds (computed 1 second ago)
  Apply Rate:      0 Byte/s
  Real Time Query: ON
  Instance(s):
    STBY1 (apply instance)
    STBY2

Database Status:
SUCCESS

DGMGRL> exit

Standby Creation in RAC using RMAN duplicate command completed.

Standby creation for standalone using RMAN duplicate command

I hope this article helped you

Regards,
Amit Rath

Wednesday, December 17, 2014

RMAN-06136: ORACLE error from auxiliary database: ORA-01503: CREATE CONTROLFILE failed

Yesterday I was doing a duplicate of a RAC database using RMAN Duplicate command and I got below error :-

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "RASTAND" RESETLOGS ARCHIVELOG
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY     4672
 LOGFILE
  GROUP   1  SIZE 256 M ,
  GROUP   2  SIZE 256 M ,
  GROUP  10  SIZE 256 M
 DATAFILE
  '+DATA_0110/rastand/datafile/system.327.866524759'
 CHARACTER SET AL32UTF8

released channel: ch1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 12/17/2014 05:20:32
RMAN-05501: aborting duplication of target database
RMAN-06136: ORACLE error from auxiliary database: ORA-01503: CREATE CONTROLFILE failed
ORA-12720: operation requires database is in EXCLUSIVE mode

Problem :-

It seems while trying to create control file for a RAC database it failed by giving above error.

Reason :-

When we do a RMAN Dupliacate for a RAC Database , while creating control file for Auxiliary instance , it needs the database in Exclusive mode to create controlfile

Solution :-

In duplicate command mention Cluster_Database parameter to FALSE and it will resolve the issue. PFB :-

run
{
allocate auxiliary channel ch1 type disk;
duplicate target database to 'RASTAND'
backup location '/ora_backup/duplicate_test/RASTAND/backup/2014_12_16'
spfile
set cluster_database='FALSE'
set instance_number='1'
set db_file_name_convert='/ora_backup/TEST1/restore_test/AMIT/DATA','+DATA_0110';
}

We can also change the Cluster_database parameter in pfile also with which we start our auxiliary instance then command to do the Duplicate will be 

run
{
allocate auxiliary channel ch1 type disk;
duplicate target database to 'RASTAND'
backup location '/ora_backup/duplicate_test/RASTAND/backup/2014_12_16';
}

I hope this article helped you.

Regards,
Amit Rath

How to Create a STANDBY database using RMAN Duplicate command in Oracle

We can also use RMAN duplicate command to create a STANDBY database from Production database. We can either use Backups of Production Database or we can create from Active Database also.

PFB steps to create a standby Database using Active Database Duplication Method :-

Primary Database is TEST
Standby Database is STBY

Changes to be done on Primary side :-

1. Database has to be archive log mode

SQL> SELECT log_mode FROM v$database;

LOG_MODE
------------
ARCHIVELOG

2. Change primary database to Force Logging mode :-

SQL> ALTER DATABASE FORCE LOGGING;

Database altered.

3. Initialization parameters in Primary database :-

SQL>  show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      TEST
SQL> show parameter db_unique_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string      TEST

4. Set the DG_CONFIG setting of LOG_ARCHIVE_CONFIG parameter. for this DB_UNIQUE_NAME of  Standby database has to be different from primary.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(TEST,STBY)';

System altered.

5. Set suitable remote archivelog destinations.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=STBY NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=STBY';

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

System altered.

-- NOTE :- Service and DB_UNIQUE_NAME has to be of Standby database

6. Set parameters related to LOG_ARCHIVE and password file parameters :-

SQL> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE;

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=8;

System altered.

SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;

System altered.

7. It is recommended to make sure that Primary can switch roles to become a Standby. For that we need to set some -convert parameters if there are path differences between the servers :-

SQL> ALTER SYSTEM SET FAL_SERVER=STBY;

System altered.

SQL> ALTER SYSTEM SET DB_FILE_NAME_CONVERT=' ',' ' SCOPE=SPFILE;   -- Primay server destination and Standby server destination

System altered.

SQL> ALTER SYSTEM SET LOG_FILE_NAME_CONVERT=' ',' '  SCOPE=SPFILE;  -- Primay server destination and Standby server destination

System altered.

SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

8. As some parameters cannot be changed while database is open , we need to restart database to before they take effect :-

SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup
ORACLE instance started.

Total System Global Area  960495616 bytes
Fixed Size                  1222816 bytes
Variable Size             247465824 bytes
Database Buffers          700448768 bytes
Redo Buffers               11358208 bytes
Database mounted.
Database opened.
SQL>

9. In both servers entries of Primary as well as Standby are needed in tnsnames.ora file and we are able to do  tnsping.

###################ORACLE_DATA_GAURD############################

TEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary_server)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

STBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = STBY_server)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = STBY)
    )
  )

TEST_DGMGRL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary_server)(PORT = 9001))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST_DGMGRL)
    )
  )
STBY_DGMGRL =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = STBY_server)(PORT = 9001))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = STBY_DGMGRL)
    )
  )

###################ORACLE_DATA_GAURD############################

10. Add static entries to listener.ora file

PRIMARY

        (SID_DESC =
      (GLOBAL_DBNAME = test.db.com)
      (SID_NAME = TEST)
      (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
        )
        (SID_DESC =
        (GLOBAL_DBNAME=TEST_DGMGRL)
        (ORACLE_HOME=/opt/oracle/product/database/11.2.0.4)
        (SID_NAME=test)
        )

STANDBY

      (SID_DESC =
      (GLOBAL_DBNAME = STBY.db.com)
      (SID_NAME = STBY)
      (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
    )
      (SID_DESC =
      (GLOBAL_DBNAME = STBY_DGMGRL)
      (SID_NAME = STBY)
      (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
    )

11. Reload listener after adding these entries

Lsnrctl reload

12. Add Standby redo logs to primary database :-

ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo01.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo02.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo03.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/STBY_redo04.log') SIZE 50M;

13. Copy the passw0rd file from Primary and copy to Standby

14. Copy the init.ora file from primary and change below parameters :-

CREATE PFILE='/initTEST.ora' from spfile;

scp orapwTEST user@STBY_server:$ORACLE_HOME/dbs/orapwSTBY
scp initTEST.ora user@STBY_server:$ORACLE_HOME/dbs/initSTBY.ora

Steps to be done in STANDBY Side :-

15. Start the STANDBY database with above pfile

export ORACLE_SID=STBY
sql> startup nomount pfile='$ORACLE_HOME/dbs/initSTBY.ora'
ORACLE instance started.

Total System Global Area  960495616 bytes
Fixed Size                  1222816 bytes
Variable Size             264243040 bytes
Database Buffers          683671552 bytes
Redo Buffers               11358208 bytes
               
16. Connect to RMAN and use RMAN duplicate command to create STANDBY

rman target sys/****@TEST_DGMGRL auxiliary sys/****@STBY_DGMGRL
DUPLICATE TARGET DATABASE
  FOR STANDBY
  FROM ACTIVE DATABASE
  DORECOVER
  SPFILE
    SET db_unique_name='STBY' COMMENT 'Is STANDBY'
    SET LOG_ARCHIVE_DEST_2='SERVICE=TEST ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=TEST'
                set control_files='/ora_backup/TEST/duplicate_test/STBY/control01.ctl','/ora_backup/TEST/duplicate_test/STBY/control02.ctl'
                set db_create_file_dest='/ora_backup/TEST/duplicate_test/STBY/DATA/'
                set db_create_online_log_dest_1='/ora_backup/TEST/duplicate_test/STBY/LOG/'
                set diagnostic_dest='/ora_backup/TEST/duplicate_test/STBY/diag'
                set audit_file_dest='/ora_backup/TEST/duplicate_test/STBY/adump'
                set db_recovery_file_dest='/ora_backup/TEST/duplicate_test/STBY/FRA'
                set db_file_name_convert='/ora_backup/TEST1/restore_test/TEST/DATA/','/ora_backup/TEST/duplicate_test/STBY/DATA/'
                set log_file_name_convert='/ora_backup/TEST1/restore_test/TEST/','/ora_backup/TEST/duplicate_test/STBY/'
                set log_archive_dest_1='location=/ora_backup/TEST1/duplicate_test/STBY/FRA/'
                set FAL_SEVER=TEST
   ;

Above command will create the STANDBY database

17. Create the broker configuration details ( for both Primary and Standby):-

SQL>  alter system set dg_broker_start=FALSE;

System altered.

SQL> alter system set dg_broker_config_file1='/opt/oracle/product/database/11.2.0.4/dbs/dr1STBY.dat';

System altered.

SQL> alter system set dg_broker_start=TRUE;

System altered.

Create the configuation

Create configuration DR as primary database is TEST connect identifier is TEST;
Add database STBY as connect identifier is STBY maintained as physical;

show configuration
enable configuration

EDIT DATABASE STBY SET STATE = 'APPLY-ON' [WITH APPLY INSTANCE = ];  -- For RAC database

Check if every thing is fine by checking Standby Database details 

show database stby

DGMGRL> show database "STANDBY"

Database - STANDBY

  Role:            PHYSICAL STANDBY
  Intended State:  APPLY-ON
  Transport Lag:   0 seconds (computed 0 seconds ago)
  Apply Lag:       0 seconds (computed 0 seconds ago)
  Apply Rate:      75.00 KByte/s
  Real Time Query: OFF
  Instance(s):
    STANDBY

Database Status:
SUCCESS

Standby Creation using RMAN duplicate command completed.

Standby creation in RAC using RMAN duplicate.

I hope this article helped you

Regards,
Amit Rath

Tuesday, December 16, 2014

MRP0: Background Media Recovery terminated with error 1274

Yesterday one of our standby database recovery stopped with below error :-

Errors in file /ora_backup/TEST/duplicate_test/AMIT/diag/diag/rdbms/standby/STANDBY/trace/STANDBY_pr00_12842.trc:
ORA-01119: error in creating database file '/ora_backup/TEST1/restore_test/AMIT/DATA/AMIT_03.dbf'
Additional information: 1
File #13 added to control file as 'UNNAMED00013'.
Originally created as:
'/ora_backup/TEST1/restore_test/AMIT/DATA/AMIT_03.dbf'
Recovery was unable to create the file as:
'/ora_backup/TEST1/restore_test/AMIT/DATA/AMIT_03.dbf'
MRP0: Background Media Recovery terminated with error 1274
Errors in file /ora_backup/TEST/duplicate_test/AMIT/diag/diag/rdbms/standby/STANDBY/trace/STANDBY_pr00_12842.trc:
ORA-01274: cannot add datafile '/ora_backup/TEST1/restore_test/AMIT/DATA/AMIT_03.dbf' - file could not be created
Managed Standby Recovery not using Real Time Apply
Recovery interrupted!
Recovery stopped due to failure in applying recovery marker (opcode 17.30).
Datafiles are recovered to a consistent state at change 5662710 but controlfile could be ahead of datafiles.

Problem :-

It seems in primary a datafile has been added and it's not able to replicate the same in standby due to above errors.

Cause :-

Above error can cause due to below reasons :-

1. STANDBY_FILE_MANAGEMNET parameter is set to maual
2. If having Different file structure, db_file_name_convert is not properly set according to standby directory structure or db_create_file_dest parameter is not set in standby

Solution :-

In these kind of scenario when due to above parameters are missing in standby,
when we add a datafile in primary it failed to replicate in standby. We can see below mentioned error in alert log and recovery will stop due to this.

ORA-01274: cannot add datafile '/ora_backup/TEST1/restore_test/AMIT/DATA/AMIT_03.dbf' - file could not be created
Managed Standby Recovery not using Real Time Apply
Recovery interrupted!
Recovery stopped due to failure in applying recovery marker (opcode 17.30).

Datafile detail will be present in standby controlfile but with below name :-


/opt/oracle/product/database/11.2.0.4/dbs/UNNAMED00013

So to resume recovery in these kind of scenarios we have to maualy create this datafile and start the recovery process. PFB steps :-

1. Check standby_file_management is set to manual

to add a datafile maualy in STANDBY database above parameter has to be in manual state

SQL> alter system set standby_file_management=manual;

System altered.

from DB_BROKER also we can change this :-

DGMGRL> edit database 'STANDBY' set property standbyfilemanagement=manual;
Property "standbyfilemanagement" updated

2. Create the database file with correct name in Standby database

SQL> alter database create datafile '/opt/oracle/product/database/11.2.0.4/dbs/UNNAMED00013' as '/ora_backup/TEST/duplicate_test/AMIT/DATA/STANDBY/datafile/amit03.dbf';

Database altered.

3. Check the datafile details in controlfile :-

/ora_backup/TEST/duplicate_test/AMIT/DATA/STANDBY/datafile/amit03.dbf

now its coming appropriate

4. Start the Mrp process to resume recovery.

SQL> alter database recover managed standby database using current logfile disconnect;

Database altered.

Check the alert logfile to verify everything is fine. You can also check from Dataguard regarding sync details :-

DGMGRL> show database "STANDBY"

Database - STANDBY

  Role:            PHYSICAL STANDBY
  Intended State:  APPLY-ON
  Transport Lag:   0 seconds (computed 2 seconds ago)
  Apply Lag:       0 seconds (computed 2 seconds ago)
  Apply Rate:      0 Byte/s
  Real Time Query: OFF
  Instance(s):
    STANDBY

Database Status:
SUCCESS

To get rid from these kind of issues in future , I did following changes in this database:-

1. change STANDBY_FILE_MANAGEMENt to AUTO
2. Set the db_file_name_convert parameter accoding to standby database.

I hope this article helped you.

Regards,
Amit Rath

Saturday, December 13, 2014

How to force a SQl query to do a hard parse in Oracle

As a DBA we all know how to force all sql queries for a hard parse.

Just Flush the Shared pool and all sql's already present in shared pool will be purged and hence forth if a new sql comes it will go for a hard parse.

But what if I want to force hard parse for a single sql statement in a Production Box. I cannot flush the shared pool a sit lead to performance issues in production. All new sql's will go for a hard parse and performance will be degraded.

I just did a POC for this that how we can force hard parse for a particular sql.

I agree we cannot flush Shared pool as it leads for performance problems. But we can purge a single SQL statement from Shared pool so that when that sql comes again it goes for a hard parse. Reason for this is , as we know wheneven a sql comes to Oracle , it first checks in shared pool that whether this sql was already executed. If Oracle finds this sql it uses the same execution plan again, this is called Soft Parse else it goes for Hard parse. I will writing more on this topic in another article.

Force a SQL for Hard Parse :-

SQL> SELECT * FROM AMIT WHERE ROWNUM < 10
                /             
       199 dummy1               dummy2
       200 dummy1               dummy2
       201 dummy1               dummy2
       202 dummy1               dummy2
       203 dummy1               dummy2
       204 dummy1               dummy2
       205 dummy1               dummy2
       206 dummy1               dummy2
       207 dummy1               dummy2

SQL> SELECT a.name
        ,b.value
  FROM   v$statname a
        ,v$mystat b
  WHERE a.statistic# = b.statistic#
  AND   a.name like 'parse%';  2    3    4    5    6

parse time cpu                                                       13
parse time elapsed                                                 14
parse count (total)                                                 153
parse count (hard)                                                 74
parse count (failures)                                              2
parse count (describe)                                             0

SQL> SELECT * FROM AMIT WHERE ROWNUM < 10
                 /
       199 dummy1               dummy2
       200 dummy1               dummy2
       201 dummy1               dummy2
       202 dummy1               dummy2
       203 dummy1               dummy2
       204 dummy1               dummy2
       205 dummy1               dummy2
       206 dummy1               dummy2
       207 dummy1               dummy2

9 rows selected.

SQL> SELECT a.name
        ,b.value
  FROM   v$statname a
        ,v$mystat b
  WHERE a.statistic# = b.statistic#
  AND   a.name like 'parse%';  2    3    4    5    6

parse time cpu                                                          13
parse time elapsed                                                    14
parse count (total)                                                    155
parse count (hard)                                                    74
parse count (failures)                                                2
parse count (describe)                                               0


As we can see we ran above query twice and its not going for a hard parse. Its taking the existing execution plan from shared pool. PFB :-









From above , its clear that sql is already present in shared pool and whenever you execute this sql, it will go for a soft parse.

Now we remove this sql details from shared pool

SQL>  select ADDRESS, HASH_VALUE from V$SQLAREA where SQL_ID like '9ag79yf9mmh3p';

ADDRESS          HASH_VALUE
---------------- ----------
000000015EF29F38 2470035573

SQL> exec DBMS_SHARED_POOL.PURGE ('000000015EF29F38,2470035573','C');

PL/SQL procedure successfully completed.


As we can see from above, sql details deleted from Shared pool.

Now we will again check for the same query

SQL> SELECT a.name
        ,b.value
  FROM   v$statname a
        ,v$mystat b
  WHERE a.statistic# = b.statistic#
  AND   a.name like 'parse%';  2    3    4    5    6

parse time cpu                                                     14
parse time elapsed                                               19
parse count (total)                                               163
parse count (hard)                                               80
parse count (failures)                                          2
parse count (describe)                                         0

SQL> SELECT * FROM AMIT WHERE ROWNUM < 10
                /
       199 dummy1               dummy2
       200 dummy1               dummy2
       201 dummy1               dummy2
       202 dummy1               dummy2
       203 dummy1               dummy2
       204 dummy1               dummy2
       205 dummy1               dummy2
       206 dummy1               dummy2
       207 dummy1               dummy2

9 rows selected.

SQL> SELECT a.name
        ,b.value
  FROM   v$statname a
        ,v$mystat b
  WHERE a.statistic# = b.statistic#
  AND   a.name like 'parse%';  2    3    4    5    6

parse time cpu                                                           14
parse time elapsed                                                     19
parse count (total)                                                     164
parse count (hard)                                                     81
parse count (failures)                                                 2
parse count (describe)                                                0

6 rows selected.-

So we can see now it goes for a hard parse . 

I hope this article helped.

Regards,
Amit Rath

Tuesday, December 9, 2014

How to Duplicate an Oracle Database using Backup Based Duplication by RMAN

Sometimes we have to create a replica of production database to perform some test in it. we can create that replica using RMAN Duplicate command.

We can create this replica using Backups of production database as well as from Active production Database. RMAN Duplicate command gives us facility to create a replica of Production Database without backup.

We can do below mentioned things using RMAN Duplicate command :-

1. Duplicate a Production database on same host with different directory structure.
2. Duplicate a Production database on another host with same directory structure.
3. Duplicate a Production database on another host with different directory structure.

Duplicate of production database can be doe using below mention methods :-

1. Backup Based Duplication
2. Active Database Duplication

In this article I will show you how to do a Duplicate using Backup based duplication.

PFB steps to Duplicate a Production database on another host with different directory structure using Backup Based Duplication :-

We have Target database as 'TEST' . We are duplication it to 'AMIT'

1. Check that primary database is up and running in Archivelog mode :-

SQL> select name,open_mode,LOG_MODE  from v$database;

NAME      OPEN_MODE            LOG_MODE
--------- -------------------- ------------
TEST     READ WRITE           ARCHIVELOG

2. Add the tns details of target and auxiliary in both server(Target, Auxiliary)

AMIT =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.20.12)(PORT = 1523))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test.db.com)
    )
  )

AMIT_DUP =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.20.14)(PORT = 1523))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = amit.db.com)
    )
  )

3. Add the static entry of Auxiliary instance in listener.ora file 

(SID_DESC =
      (GLOBAL_DBNAME = amit.db.com)
      (SID_NAME = TEST)
      (ORACLE_HOME = /opt/oracle/product/database/11.2.0.4)
     )

4. On Target host create pfile for Auxiliary Database :-

*.audit_file_dest='/ora_backup/TEST/duplicate_test/AMIT/adump'
*.audit_trail='DB'
*.compatible='11.2.0.4.0'
*.control_files='/ora_backup/TEST/duplicate_test/AMIT/control01.ctl','/ora_backup/TEST/duplicate_test/AMIT/control02.ctl'
*.db_block_size=16384
*.db_file_name_convert='/ora_backup/TEST1/restore_test/TEST/DATA','/ora_backup/TEST/duplicate_test/AMIT/DATA/'
*.log_file_name_convert='/ora_backup/TEST1/restore_test/TEST/','/ora_backup/TEST/duplicate_test/AMIT/'
*.db_create_online_log_dest_1='/ora_backup/TEST/duplicate_test/AMIT/LOG/'
*.db_create_file_dest='/ora_backup/TEST/duplicate_test/AMIT/DATA/'
*.db_domain='mydb.domain'
*.db_name='AMIT'
*.db_recovery_file_dest='/ora_backup/TEST/duplicate_test/AMIT/FRA'
*.db_recovery_file_dest_size=65G
*.log_archive_dest_1='location=/ora_backup/TEST/duplicate_test/AMIT/FRA/'
*.diagnostic_dest='/ora_backup/TEST/duplicate_test/AMIT/diag'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1061607680
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'

Above parameters in Green has to be modified according to the auxiliary server.

5. Start the auxiliay Instance in nomount mode :-

==>sqlplus

SQL*Plus: Release 11.2.0.4.0 Production on Tue Dec 2 01:14:47 2014

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

Enter user-name: /as sysdba

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

SQL> startup force nomount pfile='/ora_backup/TEST/duplicate_test/initAMIT.ora'
ORACLE instance started.

Total System Global Area 1060585472 bytes
Fixed Size                  2260000 bytes
Variable Size             633340896 bytes
Database Buffers          402653184 bytes
Redo Buffers               22331392 bytes

6. Create spfile from pfile and start it again using spfile :-

SQL> create spfile from pfile='/ora_backup/TEST/duplicate_test/initAMIT.ora';

File created.

SQL> startup force nomount
ORACLE instance started.

Total System Global Area 1060585472 bytes
Fixed Size                  2260000 bytes
Variable Size             633340896 bytes
Database Buffers          402653184 bytes

Redo Buffers               22331392 bytes

7. Check the below parameters in auxiliary instance :-

SQL> show parameter control_files


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /ora_backup/TEST/duplicate_test/AMIT/control01.ctl, /ora_ba
                                                 ckup/TEST/duplicate_test/AMIT/control02.ctl

SQL> show parameter db_file_name_convert

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string      /ora_backup/TEST1/restore_test/TEST/DATA, /ora_backup/TEST/duplicate_test/AMIT/DATA/

SQL> show parameter log_file

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_file_name_convert                string      /ora_backup/TEST1/restore_test/TEST/, /ora_backup/TEST/duplicate_test/AMIT/

We have to set above parameter when we do a duplicate database on another host with different file structure.

8. Take a backup of Target database :-

RMAN> backup as backupset database plus archivelog;


Starting backup at 2014-12-05 07:00:17

current log archived
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
.
.
.
Starting Control File and SPFILE Autobackup at 2014-12-05 07:03:36
piece handle=/ora_backup/TEST1/restore_test/TEST/FRA/TEST/autobackup/2014_12_05
Finished Control File and SPFILE Autobackup at 2014-12-05 07:05:08

RMAN>

9. Move these backups to Auxiliary server

10. Start the RMAN duplicate command. If you are using a SPFILE for auxiliary instance then copy the SPFILE at the default location ($ORACLE_HOME/dbs) as while doing a duplicate RMAN will shut down the Auxiliary instance and start it again using SPFILE.

If you want to use a pfile then mention Pfile parameter in Duplicate command(optional) :-
         pfile=/ora_backup/TEST/duplicate_test/initAMIT.ora;


RMAN> run
2> {
3> allocate auxiliary channel ch1 type disk;   ######## optional if target database backups configured in Tape, then mention this#######
4> duplicate database to 'AMIT'
5> backup location '/ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05';
6> }

allocated channel: ch1
channel ch1: SID=145 device type=DISK

Starting Duplicate Db at 2014-12-09 05:40:06

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    1060585472 bytes

Fixed Size                     2260000 bytes
Variable Size                637535200 bytes
Database Buffers             398458880 bytes
Redo Buffers                  22331392 bytes
allocated channel: ch1
channel ch1: SID=139 device type=DISK

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''TEST'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''AMIT'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile from  '/ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_s_865494230_b837sqmr_.bkp';
   alter clone database mount;
}
executing Memory Script

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

sql statement: alter system set  db_unique_name =  ''AMIT'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area    1060585472 bytes

Fixed Size                     2260000 bytes
Variable Size                637535200 bytes
Database Buffers             398458880 bytes
Redo Buffers                  22331392 bytes
allocated channel: ch1
channel ch1: SID=145 device type=DISK

Starting restore at 2014-12-09 05:43:21

channel ch1: restoring control file
channel ch1: restore complete, elapsed time: 00:00:08
output file name=/ora_backup/TEST/duplicate_test/AMIT/control01.ctl
output file name=/ora_backup/TEST/duplicate_test/AMIT/control02.ctl
Finished restore at 2014-12-09 05:43:29

database mounted

contents of Memory Script:
{
   set until scn  5071278;
   set newname for datafile  1 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//system01.dbf";
   set newname for datafile  2 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//sysaux01.dbf";
   set newname for datafile  3 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//undotbs1.dbf";
   set newname for datafile  4 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//undotbs2.dbf";
   set newname for datafile  5 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//users_1.dbf";
   set newname for datafile  6 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//ts_aud01.dbf";
   set newname for datafile  7 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//DATA_data01.dbf";
   set newname for datafile  8 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//DATA_idx01.dbf";
   set newname for datafile  9 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//DATA_arch01.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

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2014-12-09 05:44:20

channel ch1: starting datafile backup set restore
channel ch1: specifying datafile(s) to restore from backup set
channel ch1: restoring datafile 00005 to /ora_backup/TEST/duplicate_test/AMIT/DATA//users_1.dbf
channel ch1: restoring datafile 00006 to /ora_backup/TEST/duplicate_test/AMIT/DATA//ts_aud01.dbf
channel ch1: restoring datafile 00009 to /ora_backup/TEST/duplicate_test/AMIT/DATA//DATA_arch01.dbf
channel ch1: reading from backup piece /ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_nnndf_TAG20141205T070140_b837o5wj_.bkp
channel ch1: piece handle=/ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_nnndf_TAG20141205T070140_b837o5wj_.bkp tag=TAG20141205T070140
channel ch1: restored backup piece 1
channel ch1: restore complete, elapsed time: 00:02:45
channel ch1: starting datafile backup set restore
channel ch1: specifying datafile(s) to restore from backup set
channel ch1: restoring datafile 00001 to /ora_backup/TEST/duplicate_test/AMIT/DATA//system01.dbf
channel ch1: restoring datafile 00003 to /ora_backup/TEST/duplicate_test/AMIT/DATA//undotbs1.dbf
channel ch1: restoring datafile 00008 to /ora_backup/TEST/duplicate_test/AMIT/DATA//DATA_idx01.dbf
channel ch1: reading from backup piece /ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_nnndf_TAG20141205T070140_b837o7sj_.bkp
channel ch1: piece handle=/ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_nnndf_TAG20141205T070140_b837o7sj_.bkp tag=TAG20141205T070140
channel ch1: restored backup piece 1
channel ch1: restore complete, elapsed time: 00:01:36
channel ch1: starting datafile backup set restore
channel ch1: specifying datafile(s) to restore from backup set
channel ch1: restoring datafile 00002 to /ora_backup/TEST/duplicate_test/AMIT/DATA//sysaux01.dbf
channel ch1: restoring datafile 00004 to /ora_backup/TEST/duplicate_test/AMIT/DATA//undotbs2.dbf
channel ch1: restoring datafile 00007 to /ora_backup/TEST/duplicate_test/AMIT/DATA//DATA_data01.dbf
channel ch1: reading from backup piece /ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_nnndf_TAG20141205T070140_b837oc9d_.bkp
channel ch1: piece handle=/ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_nnndf_TAG20141205T070140_b837oc9d_.bkp tag=TAG20141205T070140
channel ch1: restored backup piece 1
channel ch1: restore complete, elapsed time: 00:01:25
Finished restore at 2014-12-09 05:50:11

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

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=865835412 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=11 STAMP=865835413 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=12 STAMP=865835414 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs1.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=13 STAMP=865835415 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs2.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=14 STAMP=865835415 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/users_1.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=15 STAMP=865835417 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/ts_aud01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=16 STAMP=865835418 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_data01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=17 STAMP=865835419 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_idx01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=18 STAMP=865835420 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_arch01.dbf

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

executing command: SET until clause

Starting recover at 2014-12-09 05:50:31

starting media recovery

channel ch1: starting archived log restore to default destination
channel ch1: restoring archived log
archived log thread=1 sequence=10
channel ch1: reading from backup piece /ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_annnn_TAG20141205T070313_b837r28m_.bkp
channel ch1: piece handle=/ora_backup/TEST/duplicate_test/AMIT/FRA/2014_12_05/o1_mf_annnn_TAG20141205T070313_b837r28m_.bkp tag=TAG20141205T070313
channel ch1: restored backup piece 1
channel ch1: restore complete, elapsed time: 00:00:02
archived log file name=/ora_backup/TEST/duplicate_test/AMIT/FRA/1_10_864800713.dbf thread=1 sequence=10
channel clone_default: deleting archived log(s)
archived log file name=/ora_backup/TEST/duplicate_test/AMIT/FRA/1_10_864800713.dbf RECID=1 STAMP=865835516
media recovery complete, elapsed time: 00:00:08
Finished recover at 2014-12-09 05:52:04
Oracle instance started

Total System Global Area    1060585472 bytes

Fixed Size                     2260000 bytes
Variable Size                637535200 bytes
Database Buffers             398458880 bytes
Redo Buffers                  22331392 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''AMIT'' 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 =  ''AMIT'' 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    1060585472 bytes

Fixed Size                     2260000 bytes
Variable Size                637535200 bytes
Database Buffers             398458880 bytes
Redo Buffers                  22331392 bytes
allocated channel: ch1
channel ch1: SID=145 device type=DISK
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AMIT" RESETLOGS ARCHIVELOG
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY     4672
 LOGFILE
  GROUP   1 ( '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_1.283.859503479', '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_1.1335.859503481' ) SIZE 256 M  REUSE,
  GROUP   2 ( '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_2.1429.859503481', '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_2.284.859503481' ) SIZE 256 M  REUSE,
  GROUP  10 ( '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_10.1258.859929365', '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_10.298.859929363' ) SIZE 256 M  REUSE
 DATAFILE
  '/ora_backup/TEST/duplicate_test/AMIT/DATA/system01.dbf'
 CHARACTER SET AL32UTF8

sql statement: ALTER DATABASE ADD LOGFILE


  INSTANCE 'i2'
  GROUP   3 ( '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_3.291.859504009', '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_3.1303.859504009' ) SIZE 256 M  REUSE,
  GROUP   4 ( '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_4.1246.859504011', '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_4.292.859504011' ) SIZE 256 M  REUSE,
  GROUP  20 ( '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_20.858.859929393', '/ora_backup/TEST/duplicate_test/AMIT/DATA/group_20.299.859929393' ) SIZE 256 M  REUSE

contents of Memory Script:
{
   set newname for tempfile  1 to
 "/ora_backup/TEST/duplicate_test/AMIT/DATA//AMIT/datafile/o1_mf_temp_b446vnwf_.tmp";
   switch clone tempfile all;
   catalog clone datafilecopy  "/ora_backup/TEST/duplicate_test/AMIT/DATA/sysaux01.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs1.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs2.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/users_1.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/ts_aud01.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_data01.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_idx01.dbf",
 "/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_arch01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /ora_backup/TEST/duplicate_test/AMIT/DATA//AMIT/datafile/o1_mf_temp_b446vnwf_.tmp in control file

cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/sysaux01.dbf RECID=1 STAMP=865836027
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs1.dbf RECID=2 STAMP=865836028
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs2.dbf RECID=3 STAMP=865836028
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/users_1.dbf RECID=4 STAMP=865836029
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/ts_aud01.dbf RECID=5 STAMP=865836029
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_data01.dbf RECID=6 STAMP=865836030
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_idx01.dbf RECID=7 STAMP=865836030
cataloged datafile copy
datafile copy file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_arch01.dbf RECID=8 STAMP=865836031

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=865836027 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=865836028 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs1.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=865836028 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/undotbs2.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=865836029 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/users_1.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=865836029 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/ts_aud01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=865836030 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_data01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=865836030 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_idx01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=8 STAMP=865836031 file name=/ora_backup/TEST/duplicate_test/AMIT/DATA/DATA_arch01.dbf
Reenabling controlfile options for auxiliary database
Executing: alter database force logging

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

database opened
Finished Duplicate Db at 2014-12-09 06:03:30
released channel: ch1

Database Duplicated using Backup Based Duplication on another host with different file structure .

If we have to duplicate database on same host then we have to follow the same above process. One thing we have to keep in mind while duplicating on same host , DB name of Auxiliary instance has to be different from target.

PFB link to Duplicate database with same file structure on another host.
Please click on link for Duplicating database using Active Database Duplication.

I hope this article helped you.

Regards,
Amit Rath