No great genius has ever existed without some touch of madness.

Monday 31 October 2011

Cloning using RMAN


Clone of a database on the same Host i.e. same Server


Source database=TEST
New database to be created=PROD


 First make sure your database is in archivelog mode.
 Make a fresh backup of your database using Rman.
 The SID of the database which I have is “TEST”.
 The cloned database name will be “PROD”.


-Produce a pfile for the new database
   
C:\Documents and Settings\sagar.verma>set oracle sid=test
   
C:\Documents and Settings\sagar.verma>sqlplus

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 19 10:57:27 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
   
Enter user-name: sys as sysdba
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
    
SQL> create pfile='D:\oracle\product\10.2.0\db_1\database\initprod.ora' from spfile;
File created.


IN PARAMETER FILE, CHANGE THE PARAMETERS AND AT THE END,ADD


db_file_name_convert=('D:\oracle\product\10.2.0\oradata\test\','D:\oracle\product\10.2.0\oradata\prod\')
log_file_name_convert=('D:\oracle\product\10.2.0\oradata\test\','D:\oracle\product\10.2.0\oradata\prod\')

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


SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP and Data Mining options




--Specifying Instance Sid
   
C:\Documents and Settings\sagar.verma>oradim -new -sid prod -intpwd sagar -start
   mode auto
Instance created.
  
C:\Documents and Settings\sagar.verma>set oracle_sid=prod
   
C:\Documents and Settings\sagar.verma>sqlplus  /nolog
   
SQL> startup nomount
ORACLE instance started.
Total System Global Area  289406976 bytes
Fixed Size                  1248576 bytes
Variable Size             104858304 bytes
Database Buffers          176160768 bytes
Redo Buffers                7139328 bytes
   

On another cmd window , set
   
C:\Documents and Settings\sagar.verma>set oracle_sid=test


C:\Documents and Settings\sagar.verma>sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 19 12:18:19 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Enter user-name: sys as sysdba
Enter password:
Connected to an idle instance.
  
SQL> startup
ORACLE instance started.
Total System Global Area  289406976 bytes
Fixed Size                  1248576 bytes
Variable Size             104858304 bytes
Database Buffers          176160768 bytes
Redo Buffers                7139328 bytes
Database mounted.
Database opened.
   

Now, on another cmd window----
  
C:\Documents and Settings\sagar.verma>set oracle_sid=test


C:\Documents and Settings\sagar.verma>rman target / auxiliary sys/sys@prod
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Sep 19 12:19:39 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: TEST (DBID=2060060426)
connected to auxiliary database: PROD (not mounted)
  
RMAN> connect catalog rman3/rman3@catdb
   
RMAN> duplicate target database to 'prod';

(MAKE SURE THAT YOUR AUXILIARY DATABASE i.e clone db, IS STARTED AS NOMOUNT AND YOU MUST NOT HAVE ANOTHER OPEN SESSION WITH SYS USER )



- Create an spfile(for prod db)


From sqlplus:
create spfile from pfile;
  
Checks to be performed after the clone process is finished


Execute the below steps in Test (Clone) instance, and cross check the result with the Production (Target) instance.

SQL> SELECT OPEN_MODE,NAME FROM V$DATABASE;
SQL> ARCHIVE LOG LIST;
SQL> SELECT NAME FROM V$TABLESPACE;
SQL> SELECT USERNAME FROM DBA_USERS;
SQL> SELECT COUNT(*) FROM DBA_OBJECTS WHERE STATUS='INVALID';


If you find invalid objects then you can compile them using  C:\oracle\product\10.2.0\rdbms/admin/utlrp.sql

1 comment: