Welcome back everyone. Lets do something very interesting today. In my last post I have shown you a practical example on how the Oracle TAF configuration works. Well today its completely different. Lets take some time to understand how an active RMAN duplicate works. I am pretty sure most of us just trigger the “duplicate” clause and do some other stuff ( may be a cup of coffee or round table conference with our friends – of course not on official matters 🙂 ). While I understand that Oracle has made the database refresh activities very easy with just the single “duplicate” clause, it is also important for us as a DBA to understand how it works internally. This greatly helps in troubleshooting any issue that arises out of duplicate and for a good reason allows us to continue a failed duplicate sometimes when 70% of the task is done by RMAN. I am sure most of us simply scrap everything and start a fresh duplicate if at all it fails at a certain stage due to unforeseen circumstances. So lets get started.
So all in all do you know how many stages are involved in a RMAN duplicate ? Well to segregate below are the important stages:
- Start up an auxiliary instance (Manual)
- Configure static entry for the auxiliary instance  in the listener and copy password file (Manual)
- Connect to target and auxiliary via RMAN (Manual)
- Copy controlfile from target (RMAN duplicate)
- Mount the auxiliary instance (RMAN duplicate)
- Set newname for the datafiles to be copied from target to auxiliary (RMAN duplicate)
- Copy datafiles from target (RMAN duplicate)
- Copy archive logs from target to auxiliary that will be required for recovery of auxiliary datafiles (RMAN duplicate)
- Rename datafiles in the auxiliary controlfile to the location of copied datafiles (RMAN duplicate)
- Recover the auxiliary instance (RMAN duplicate)
- Recreate auxiliary controlfile with the auxiliary database name (RMAN duplicate)
- Open the auxiliary instance with RESETLOGS option. (RMAN duplicate)
Well thats it for the duplicate. From step number 4 till step number 11, all have been automated in the “duplicate” clause and we find it magical..hahahaha…!! However, very true..! Tremendous automation for a person who just triggers the “duplicate” and leaves it, waiting for the action to complete (Meanwhile he can do chit-chat with his friends 🙂 ). Job made easy!! So after reading this post you will be able  to perform all these steps manually.
Now for each of the above steps lets have a closer look :
- Starting up auxiliary instance
In my example the auxiliary database name will be “exadev”. Below is the content of the pfile that I created with minimum parameters –
cat /tmp/pfile.ora

Its time to create the spfile first in dbs location and make the auxiliary instance to start via spfile. Remember once the duplication is over we will create the spfile in ASM location with instance in at least mount state. If we create the spfile now in ASM it will create it under “unknown” directory as the database name is not known using a controlfile.

- Configure static entry in listener for auxiliary instance and copy password file
This step is mainly required because duplicate automatically shuts down and starts up the instance during the entire process and RMAN needs a service in the listener to be connected. If it would have been a dynamic service, during shutdown the service would have been removed by PMON from the listener and RMAN will exit out throwing error since it no longer knows to what it is connected.
cat /u01/app/grid/network/admin/listener.ora


After starting the LISTENER_DG below is the status –

Password file from target is copied to auxiliary instance $ORACLE_HOME/dbs location.
- Connect to TARGET and AUXILIARY via RMAN

Cool..! now that we are able to connect to both target and auxiliary via RMAN lets get straightaway into duplicate action but of course our intention is to learn it manually 🙂 . Note here that in the above connect method I am using full description in place of alias because that gives me the freedom where I do not need to add the aliases in tnsnames.ora file of both target and auxiliary. Remember if you are using RMAN connect method with full description it should not contain any white spaces as you can see above I have trimmed down the description.
Action begins from here on. In conventional method straight after this connection we simply trigger “duplicate target database to exadev from active database” and this will trigger all the steps from step number 4 to step number 11 automatically. But hold on..! My post is not that simple. You are in this post to learn how you can do it manually the same set of steps. So here it goes.
- Copy controlfile from target (RMAN duplicate)
After the above target and auxiliary connection do as below –


Controlfile copied to +DATA/exadev/controlfile/backup.444.947185867. You can verify it by navigating to the location
- Mount the auxiliary instance (RMAN duplicate)
Controlfile is now copied and we can go ahead to mount the database. But hold on, to mount the database the db_name should be same as the name present in controlfile. Since the controlfile came from target whose name is “testcon”, lets make the changes in auxiliary spfile and mount the database.
***Remember at this point you need to set the db_unique_name in spfile to exadev since the datafiles are copied to the db_unique_name location in ASM.


Ok cool..!! so we have got the auxiliary instance mounted with the target controlfile that was copied. Next step..
- Set newname for the datafiles to be copied from target to auxiliary (RMAN duplicate)
Well the “set newname” clause is required because the auxiliary instance controlfile has reference to the datafile path of the target database. By using this clause we are telling RMAN to copy the datafiles of the target database to auxiliary instance over its ASM location with the db_unique_name directory (***Remember ? Just a while ago I told to set the db_unique_name parameter to original database name after setting the db_name to target database in auxiliary instance). RMAN duplicate writes a new statement for each datafile with “set newname for datafile…..” clause. However, here I will simply use the “set newname for database” clause that considers all the datafiles of the auxiliary instance to +DATA diskgroup.

- Copy datafiles from target (RMAN duplicate)


……………………………..
…………………………….

- Copy archive logs from target to auxiliary that will be required for recovery of auxiliary datafiles (RMAN duplicate)
Now lets copy the archive logs from target that will be required to recover the auxiliary instance. Note here that since RMAN uses online copies during duplicate so its logic is to copy all the archives from the minimum checkpoint that was recorded in the controlfile when it was being copied from target to auxiliary in the first step of duplication. So that makes sense. Lets find out the minimum checkpoint from the auxiliary controlfile (Remember – the minimum checkpoint has to be taken from the auxiliary controlfile)

Cool..!! Lets go ahead and copy the archivelogs from target to auxiliary with starting scn 1741639.

*************************
***********************

- Rename datafiles in the auxiliary controlfile to the location of copied datafiles (RMAN duplicate)
Remember the “set newname” clause during copy of datafiles ? Now is the time to let the auxiliary controlfile know the correct location of its copied datafiles. To do this we will simply connect as “/” to auxiliary instance and catalog the datafiles. Once it is cataloged just use the “switch” command in RMAN to rename the datafiles in controflile.


After cataloging the files just trigger switch command in the same RMAN session.
RMAN > switch database to copy;
Lets verify now –

Perfect the controlfile now knows the copied location of the datafiles and is reflecting right there. But hold on, before recovery the controlfile should also know the location of the archivelogs that we copied in step number 8. For that just catalog the location where it copied and you are good to go.

- Recover the auxiliary instance (RMAN duplicate)
So all set..!! We have the datafiles and archivelogs in place. Lets recover it in rman duplicate style ;). Since RMAN duplicate from active recovers upto latest archive available in target hence we need to know the latest checkpoint of the target database which we can refer as “set until SCN” during the recovery of auxiliary.


****************
***************

Note here that you will need to use recover “clone” keyword to tell rman that he needs to recover the auxiliary instance 🙂
Bingoo..!! done till here. Now its the time to recreate the controlfile with original database name “exadev”.
- Recreate auxiliary controlfile with the auxiliary database name (RMAN duplicate)
Remember we changed the db_name in auxiliary to target database name and kept the db_unique_name to original ? Since all our files are now copied under db_unique_name directory in ASM and ready for controlfile re-creation with original database name “exadev”, so will revert those changes and yes in RMAN duplicate style 😉 –



Perfect..! Now is the time to recreate the controlfile and lets do it in the duplicate style again

Instance is in no mount state and cluster_database should be false. Lets do it in RMAN duplicate style

Remember since the controlfile is being recreated using RMAN method you will need to put one white space before each of the keywords from MAXLOGFILES until CHARACTER SET otherwise you will get some weird error messages (Now you know why in RMAN duplicate you will see a lot of white spaces in the create controlfile command 🙂 ). Also note the single quotes that are to be used two times. When you are triggering sql statement inside RMAN command line it has to be done to preserve the original single quote.

Ohh..!! Now you might be thinking why did I only add the system datafile and not all the datafiles during re-creation. Thats for your convenience. When you will have hundreds of datafiles its not very manageable to put them in the command line or in the script and is time consuming. Instead lets do it in the RMAN duplicate style where while recreating controlfile you generally need only the system datafile and the rest you can just catalog. Optionally, you can just put all the rest of the datafile names in the create controlfile statement in which case the below step is not required. Lets see below how to proceed with RMAN duplicate style –


Remember the “set newname” clause is required for us again. In duplicate process it does in the beginning and is within the run block so for the subsequent operation it refers that.
Lets now verify in the controlfile –

Cant expect more. Perfect..!! Now lets use the RMAN duplicate style for one last time. Yes you guessed it right. The irreversible “RESETLOGS” 🙂

Thats it. You have just nailed the RMAN duplicate and now you know what it exactly does. So next time if a duplicate fails do not scrap the entire process and redo it specially if it has completed over 50 % of its process. Its a pain to restart the process for huge restores having Terabytes of data. You will know exactly from which stage to continue manually after reading this post. Well this post was done referring active duplicate but the other options such as duplicate from backup and without target are 99% similar. Instead of “backup as copy” it does “restore”. Happy learning !!
*** Either win or guide ***
