Monday, October 6, 2008

How to clone database on the same host with different name

In this post I will show how we can clone database on windows system without using RMAN duplicate. You can clone database by using RMAN duplicate which is discussed on Creating a Duplicate Database on a Remote Host -Part1. You can also clone database by taking backup of source database and restore it which is discussed in Restore and Recover database to a new host
Note that cloning in this way which is shown next part in this post will not change DBID as it was in source database. In order to change DBID after clone operation you have to use nid tool which is discussed on How to Change Database Name and DBID?
Step by steps cloning operation is described below. The scenario is,
-Source database arju will be cloned as arjucl

-Datafile named E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\*.dbf will be cloned as F:\ORACLE\ARJUCL\*.dbf

-Controlfile named E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\*.ctl will be cloned as
F:\ORACLE\*.CTL

-In cloned database adump,bdump,cdump,udump will be located in F:\ORACLE\*dump

Step 01:
In source database identify the datafile location and redo logfile location.
On windows machine,
C:\Documents and Settings\Queen>set ORACLE_SID=arju

On linux based machine,
$export ORACLE_SID=arju

C:\Documents and Settings\Queen>sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Oct 6 23:19:45 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> col file_name format a70
SQL> set linesize 160
SQL> select file_name, file_id from dba_data_files;

FILE_NAME FILE_ID
---------------------------------------------------------------------- ----------
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\USERS01.DBF 4
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\SYSAUX01.DBF 3
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\UNDOTBS01.DBF 2
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\SYSTEM01.DBF 1
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\EXAMPLE01.DBF 5
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\TEST_TBS01.DBF 6

6 rows selected.

SQL> select member from v$logfile;

MEMBER
----------------------------------------------------------------
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\REDO02.LOG
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\REDO01.LOG

Step 02:
Create a pfile from source spfile and controfile trace from source controlfile.
SQL> create pfile='f:\pfile.ora' from spfile;

File created.

SQL> alter database backup controlfile to trace as 'f:\controlfile.ctl';


Database altered.

On linux based system as linux file structure to save controlfile. Like instead of f:\controlfile.ctl use /oracle/controlfile.ctl

Step 03:
Shutdown the source database.
SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

Step 04:
Create the required directory for the cloned database. You should do this step in previous.
SQL> host
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Queen>mkdir f:\oracle

C:\Documents and Settings\Queen>mkdir f:\oracle\arjucl


On unix based machine adjust the location as you wish to create clone database.
Step 05:
Copy datafiles and redo log files to the location of f:\oracle\arjucl
C:\Documents and Settings\Queen>copy E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\*.dbf f:\oracle\arjucl
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\EXAMPLE01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\SYSAUX01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\SYSTEM01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\TEMP01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\TEST_TBS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\UNDOTBS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\USERS01.DBF
7 file(s) copied.

C:\Documents and Settings\Queen>copy E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\*.log f:\oracle\arjucl
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\REDO01.LOG
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\REDO02.LOG
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ARJU\REDO03.LOG
3 file(s) copied.

Step 06:
At this stage task with the source database is finished. Edit the pfile f:\pfile.ora and change parameter control_files, db_name, different dump directory in order to reflect cloned database name and location.
On windows,
C:\Documents and Settings\Queen>notepad f:\pfile.ora
arjucl.__db_cache_size=25165824
arjucl.__java_pool_size=4194304
arjucl.__large_pool_size=4194304
arjucl.__shared_pool_size=62914560
arjucl.__streams_pool_size=0

*.audit_file_dest='F:\oracle\adump'
*.audit_trail='DB','EXTENDED'
*.background_dump_dest='F:\oracle\bdump'
*.compatible='10.2.0.1.0'
*.control_files='F:\oracle\control01.ctl',
'F:\oracle\control02.ctl','F:\oracle\control03.ctl'

*.core_dump_dest='F:\oracle\cdump'
*.db_block_size=8192
*.db_create_file_dest='C:\'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='arjucl'
*.db_recovery_file_dest_size=2147483648
*.db_recovery_file_dest='c:\test'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=arjuclXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=c:\test'
*.log_archive_dest_2='LOCATION=g:\'
*.log_archive_dest_3='LOCATION=USE_DB_RECOVERY_FILE_DEST'
*.open_cursors=300
*.pga_aggregate_target=202375168
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=104857600
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='F:\oracle\udump'

On linux based system use as, $vi pfile.ora
Step 07:
Edit the created text controlfile and change the database name along with logfile and datafile location and use SET DATABASE database_name in the controlfile creation script.

On windows,

C:\Documents and Settings\Queen>notepad f:\CONTROLFILE.CTL

STARTUP NOMOUNT PFILE='F:\PFILE.ORA'
CREATE CONTROLFILE REUSE SET DATABASE "arjucl" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 'F:\ORACLE\ARJUCL\REDO01.LOG' SIZE 50M,
GROUP 2 'F:\ORACLE\ARJUCL\REDO02.LOG' SIZE 50M,
GROUP 3 'F:\ORACLE\ARJUCL\REDO03.LOG' SIZE 50M

DATAFILE
'F:\ORACLE\ARJUCL\SYSTEM01.DBF',
'F:\ORACLE\ARJUCL\UNDOTBS01.DBF',
'F:\ORACLE\ARJUCL\SYSAUX01.DBF',
'F:\ORACLE\ARJUCL\USERS01.DBF',
'F:\ORACLE\ARJUCL\EXAMPLE01.DBF',
'F:\ORACLE\ARJUCL\TEST_TBS01.DBF'

CHARACTER SET WE8MSWIN1252
;
On unix based system open the controlfile with any editor software and then edit.
Step 08:Avoid this step if you are on unix based system. On windows, with oradim create new oracle service arjucl. However if you are on unix machine then simply ignore this step.
C:\Documents and Settings\Queen>oradim -new -sid arjucl
Instance created.

Step 09:
Set environmental variable to arjucl and connect to instance as sysdba.
C:\Documents and Settings\Queen>set ORACLE_SID=arjucl
On unix based system, export ORACLE_SID=arjucl
C:\Documents and Settings\Queen>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Oct 7 00:04:32 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to an idle instance.
Step 10:
Run the controlfile creation script.
On windows,
SQL> @f:\controlfile.ctl
ORACLE instance started.

Total System Global Area 104857600 bytes
Fixed Size 1247516 bytes
Variable Size 71304932 bytes
Database Buffers 25165824 bytes
Redo Buffers 7139328 bytes

Control file created.

On unix based system run the modified controlfile script where you saved.

Step 11:
Open the database with resetlogs option.
SQL> alter database open resetlogs;
Database altered.

Check the cloned database name.
SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string arjucl

You can check the cloned database datafile location.
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
F:\ORACLE\ARJUCL\TEST_TBS01.DBF
F:\ORACLE\ARJUCL\EXAMPLE01.DBF
F:\ORACLE\ARJUCL\USERS01.DBF
F:\ORACLE\ARJUCL\SYSAUX01.DBF
F:\ORACLE\ARJUCL\UNDOTBS01.DBF
F:\ORACLE\ARJUCL\SYSTEM01.DBF

6 rows selected.

4 comments:

Smriti said...

Hi, This is a wonderful tutorial.
and easy to refer.

but when i was trying to create oracle service, i got error. hopefully you might help me out because i am struggling it for long time.
DIM-00019: create service error
O/S-Error: (OS 2) The system cannot find the file specified.
please suggest

Arju said...

You must perform a fresh install of oracle in your machine. When a windows OS gets corrupted you loose more than just the oracle home structure, you loose the Oracle Universal Installer repository and the regedit entries. Running a fresh oracle install without any database and then run oradim in order to perform restore.

Pankaj said...

Hi Arju,

I tried to follow the steps which you have mentioned but I am getting the following error message:
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file 'C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE
\INITDBCL.ORA'
SP2-0042: unknown command "DATAFILE" - rest of line ignored.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0734: unknown command beginning "CHARACTER ..." - rest of line ignored.
1 CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG' SIZE 50M,
9 GROUP 2 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO02.LOG' SIZE 50M,
10 GROUP 3 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO03.LOG' SIZE 50M
11* -- STANDBY LOGFILE
ORA-01034: ORACLE not available


ALTER DATABASE OPEN
*
ERROR at line 1:
ORA-01034: ORACLE not available


ALTER TABLESPACE TEMP ADD TEMPFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP01
.DBF'
*
ERROR at line 1:
ORA-01034: ORACLE not available


ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file 'C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE
\INITDBCL.ORA'
SP2-0042: unknown command "DATAFILE" - rest of line ignored.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "'C:\ORACLE..." - rest of line ignored.
SP2-0734: unknown command beginning "CHARACTER ..." - rest of line ignored.
1 CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS NOARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG' SIZE 50M,
9 GROUP 2 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO02.LOG' SIZE 50M,
10 GROUP 3 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO03.LOG' SIZE 50M
11* -- STANDBY LOGFILE
ORA-01034: ORACLE not available


ALTER DATABASE OPEN RESETLOGS
*
ERROR at line 1:
ORA-01034: ORACLE not available


ALTER TABLESPACE TEMP ADD TEMPFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP01
.DBF'
*
ERROR at line 1:
ORA-01034: ORACLE not available


SQL>

manasi said...

Hi arju

Very informative and helpful series
I am getting unable to open controlfile error whenever i tried to run it
sp2-0310 is the number says "archived log contains sequence %s; sequence %s required"
// *Cause: The archived log is out of sequence, probably because it
// is corrupted or the wrong redo log filename was specified
pl explain
1.can i copy all the files while the source database is up and running keeping it in a backup mode
2.pl explain as to why u gave 3 control files in the initfile at a different location while u recreating it in F: drive