Thursday, April 26, 2012

Duplicate Database to new database

Duplicate Database to New Database

As example we will  create database ASM453D1 from
source database ASM451D1. 
 
The new database will run on the ota5045
the source database runs on the ota5026
 
First we create the audit directory on the ota5045 
$ mkdir /oracle/home/admin/ASM453D/adump
put new database in /etc/oratab
$vi /etc/oratab
ASM453D1:/oracle/home/11.2.0.3.0:N

Then make a pfile with only 1 entry in it.
$ vi $ORACLE_HOME/DBS/initASM453D1.ora
db_name=ASM453D

In our enviroment the listenerer runs under grid user
login as grid user and go to $ORACLE_HOME/network/admin
$ vi listener.ora

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = ota5045.business.finl.fortis)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
  ( SID_DESC =
     (GLOBAL_DBNAME = ASM453D)
     (ORACLE_HOME = /oracle/home/11.2.0.3.0)
     (SID_NAME = ASM453D1)
  )
 ) 


Log on  as oracle user op de ota5045 an put the following entry's in the tnsnames.ora

ASM451D1 =
(DESCRIPTION =
    (ADDRESS_LIST =
      (LOAD_BALANCE=ON)
      (ADDRESS = (Protocol = TCP)(Host = ota5026)(Port = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME =  ASM451D)
    )
  )

ASM453D1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (LOAD_BALANCE=ON)
      (ADDRESS = (Protocol = TCP)(Host = ota5045)(Port = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME =  ASM453D)
    )
  )

 
Do the same for the tnsnames.ora on the ota5025 where the source database is running. 
 
copy  password file from source database to target database and change name of the file on the ota5026 as user oracle

$ scp $ORCLE_HOME/dbs/orapwASM451D1 ota5045:$ORACLE_HOME/dbs  
$ mv orapwASM451D1 orapwASM453D1
$ chmod 650 orapwASM453D1

 start the new database ASM453D1 in nomount fase
 SQL> startup nomount

On the ota5026 where the target database ASM451D1 runs start rman and login

connect target sys/password@asm451d
connect auxiliary sys/password@asm453d
Note *
Passwords MUST be the same otherwise the active duplicate fails  
Start the duplicate from active database.
 
duplicate target database
TO ASM453D
from active database
spfile
SET db_file_name_convert 'ASM451D','ASM453D'
SET log_file_name_convert 'ASM451D','ASM453D'
SET control_files '+DATA/asm453d/controlfile/control1.ctl','+FRA/asm453d/controlfile/control2.ctl' SET audit_file_dest '/oracle/home/admin/SVM453D/adump';
 
 
This are the last lines of the active duplicate. 
 
datafile 10 switched to datafile copy
input datafile copy RECID=9 STAMP=780764632 file name=+DATA/asm453d/datafile/svm4_dwa_i.303.780764577
datafile 11 switched to datafile copy
input datafile copy RECID=10 STAMP=780764632 file name=+DATA/asm453d/datafile/svm4_dwa_l.304.780764581
datafile 12 switched to datafile copy
input datafile copy RECID=11 STAMP=780764632 file name=+DATA/asm453d/datafile/svm4_dwh_d.305.780764583
datafile 13 switched to datafile copy
input datafile copy RECID=12 STAMP=780764632 file name=+DATA/asm453d/datafile/svm4_dwh_i.306.780764587
datafile 14 switched to datafile copy
input datafile copy RECID=13 STAMP=780764632 file name=+DATA/asm453d/datafile/svm4_dwh_l.307.780764589
contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script
database opened

Finished Duplicate Db at 16-APR-12

You have an exact clone of the source database ASM451D1