Thursday, August 03, 2006

Copy and Rename a database (clone)

Practise: Copy and Rename a Database
The original DB: mydb1
The new DB: oradb1

1) Copy mydb1 data files and init.ora
select file_name from dba_data_files
FILE_NAME
--------------------------------------------
/opt/app/oracle/oradata/mydb1/system01.dbf
/opt/app/oracle/oradata/mydb1/undotbs01.dbf
/opt/app/oracle/oradata/mydb1/user01.dbf

cp above files to the location(after shutdown the db):
/opt/app/oracle/oradata/oradb1/

cp the online redo file to the new location too
( do we really need to copy redo log file?)

Copy the initmydb1.ora to initoradb1.ora;
edit initoradb1.ora; change any neccessary parameters (db_name etc)
create bdump cdump udump etc directories

2) Create the script that will re-create the controlfile
sql> startup mount
sql> alter database backup controlfile to trace;

in USER_DUMP_DEST find the current trace file,
create a script (cr_ctl.sql) from it;
change 'reuse' to 'set'; specify resetlogs

3) create a password file under $ORACLE_HOME/dbs
% orapwd file=orapworadb1 password=oracle entries=5

4) Set ORACLE_SID = oradb1
run the cr_ctl.sql script

% sqlplus /nolog
% connect / as sydba
% @cr_ctl.sql
% create spfile from pfile;
% alter database open resetlogs;

5) add a temp file
alter tablespace temp add tempfile
'/opt/app/oracle/oradata/oradb1/temp01.dbf' size 30M;

No comments: