Thursday, June 13, 2013

RMAN create duplicate database using Oracle 11g on same host

Some times there is a need to create the duplicate database from the running database on same host. This will require following steps for the creation of the duplicate database.

1. Create spfile for the duplicate database and corresponding directories.
2. Create the password file.
3. Setup listener and tnsnames.ora for duplicate database.
4. Check the latest archive log sequence number from main database.
5. connect using RMAN and run script to duplicate database.

In this example I am duplicating from TDB (Test database) to DUPLI (Duplicate database).

1. First of all an initDUPLI.ora was created under ORACLE_HOME/dbs with below parameters:



*.audit_file_dest='/u01/app/oracle/admin/DUPLI/adump'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/DUPLI/control01.ctl','/arch/FRA2/DUPLI/control02.ctl'
*.db_file_name_convert='/u01/app/oracle/oradata/TDB/','/u01/app/oracle/oradata/DUPLI/'
*.log_file_name_convert='/u01/app/oracle/oradata/TDB/','/u01/app/oracle/oradata/DUPLI/'
*.db_block_size=8192
*.db_name='DUPLI'
*.db_recovery_file_dest='/arch/FRA2'
*.db_recovery_file_dest_size=10485760000
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_format='%t_%s_%r.arc'
*.memory_max_target=500M

I have highlighted the important parameters.

mkdir -p /u01/app/oracle/admin/DUPLI/adump
mkdir -p /arch/FRA2/DUPLI/

Now to create spfile and start up database in nomount.

startup nomount
create spfile from pfile='?/dbs/initDUPLI.ora'
shutdown immediate
startup nomount

2. Create password file so that rman can connect 

orapwd file=orapwDUPLI password=********

3. Listener setup was done and a TNS entry was created.

DUPLI_TNS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hname.example.com)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DUPLI)
    )

  )

Check the status of the listener and make sure that you are getting 

Service "DUPLI" has 2 instance(s).
  Instance "DUPLI", status UNKNOWN, has 1 handler(s) for this service...

  Instance "DUPLI", status BLOCKED, has 1 handler(s) for this service...


4. Check the archivelog sequence number from main database which is TDB in our case.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     6
Next log sequence to archive   8

Current log sequence           8


5. Log into RMAN and run following to create duplicate database.

$ rman 
RMAN> 
RMAN> connect target sys/********@tdb

RMAN> connect auxiliary sys/********@dupli_tns
RMAN> run {
2> set until sequence 8 thread 1;
3> duplicate target database to dupli;
4> }
RMAN> 


and let this finish and you are done.