Create Controlfile Noresetlogs: Reuse Database "Oldlsq"

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

A database cloning procedure is especially useful for the DBA who wants to give his

developers a full-sized TEST and DEV instance by cloning the PROD instance into the
development server areas.

This Oracle clone procedure can be use to quickly migrate a system from one UNIX server to
another. It clones the Oracle database and this Oracle cloning procedures is often the fastest
way to copy a Oracle database.

STEP 1: On the old system, go into SQL*Plus, sign on as SYSDBA and issue: “alter
database backup controlfile to trace”. This will put the create database syntax in the trace file
directory. The trace keyword tells oracle to generate a script containing a create controlfile
command and store it in the trace directory identified in the user_dump_dest parameter of the
init.ora file. It will look something like this:
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "OLDLSQ" NORESETLOGS
NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 240
MAXINSTANCES 1
MAXLOGHISTORY 113
LOGFILE
GROUP 1 ('/u03/oradata/oldlsq/log1a.dbf',
'/u03/oradata/olslsq/log1b.dbf') SIZE 30M,
GROUP 2 ('/u04/oradata/oldlsq/log2a.dbf',
'/u04/oradata/oldlsq/log2b.dbf') SIZE 30M
DATAFILE
'/u01/oradata/oldlsq/system01.dbf',
'/u01/oradata/oldlsq/mydatabase.dbf'
;
# Recovery is required if any of the datafiles are restored
# backups, or if the last shutdown was not normal or immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;

STEP 2: Shutdown the old database

STEP 3: Copy all data files into the new directories on the new server. You may change the
file names if you want, but you must edit the controlfile to reflect the new data files names on
the new server.
rcp /u01/oradata/oldlsq/* newhost:/u01/oradata/newlsq
rcp /u01/oradata/oldlsq/* newhost:/u01/oradata/newlsq
rcp /u03/oradata/oldlsq/* newhost:/u03/oradata/newlsq
rcp /u04/oradata/oldlsq/* newhost:/u04/oradata/newlsq

STEP 4: Copy and Edit the Control file – Using the output syntax from STEP 1, modify the
controlfile creation script by changing the following:

Old:

CREATE CONTROLFILE REUSE DATABASE "OLDLSQ" NORESETLOGS

New:

CREATE CONTROLFILE SET DATABASE "NEWLSQ" RESETLOGS

STEP 5: Remove the “recover database” and “alter database open” syntax
# Recovery is required if any of the datafiles are restored
# backups, or if the last shutdown was not normal or immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;

STEP 6: Re-names of the data files names that have changed.

Save as db_create_controlfile.sql.

Old:

DATAFILE
'/u01/oradata/oldlsq/system01.dbf',
'/u01/oradata/oldlsq/mydatabase.dbf'

New:

DATAFILE
'/u01/oradata/newlsq/system01.dbf',
'/u01/oradata/newlsq/mydatabase.dbf'

STEP 7: Create the bdump, udump and cdump directories

cd $DBA/admin
mkdir newlsq
cd newlsq
mkdir bdump
mkdir udump
mkdir cdump
mkdir pfile

STEP 8: Copy-over the old init.ora file

rcp $DBA/admin/olslsq/pfile/*.ora newhost:/u01/oracle/admin/newlsq/pfile

STEP 9: Start the new database

@db_create_controlfile.sql

STEP 10: Place the new database in archivelog mode


Cloning An Oracle Database.
First let's consider the steps that would be required to do this operation manually. The following is
a list of the steps you might follow, if you were making a clone of an existing database on a
Windows 2000 or Windows NT Server:

1. Create A Backup Control File Script.

First you need to obtain a script that will create a copy of the existing control file. This is
usually carried out with the SVRMGRL utility using the following commands:
2. CONNECT INTERNAL
3. ALTER DATABASE BACKUP CONTROLFILE TO TRACE RESETLOGS;

This creates a file in the trace file directory. The file usually has the extension '.trc' and
will be located either in the directory defined by the parameter 'user_dump_dest', or if this
parameter is undefined it will be in $ORACLE_HOME/rdbms/log. Edit this file with your
favourite editor and remove the crud. Then rename it as "ctrl<NEW_SID>.sql," where
<NEW_SID> will be the ORACLE_SID of the copied database.

4. Modify The Script Created In The Previous Step.

The CREATE CONTROLFILE command in the script ctrl<NEW_SID>.sql contains SQL,


which might look something like this:
5. CREATE CONTROLFILE REUSE DATABASE "OLD_SID" RESETLOGS ARCHIVELOG
6. MAXLOGFILES 32
7. MAXLOGMEMBERS 2
8. MAXDATAFILES 32
9. MAXINSTANCES 16
10. MAXLOGHISTORY 1815
11. LOGFILE
12. GROUP 1 'E:\ORACLE\ORADATA\OLD_SID\REDO03.LOG' SIZE 1M,
13. GROUP 2 'E:\ORACLE\ORADATA\OLD_SID\REDO02.LOG' SIZE 1M,
14. GROUP 3 'E:\ORACLE\ORADATA\OLD_SID\REDO01.LOG' SIZE 1M
15. DATAFILE
16. 'E:\ORACLE\ORADATA\OLD_SID\SYSTEM01.DBF',
17. 'E:\ORACLE\ORADATA\OLD_SID\RBS01.DBF',
18. 'E:\ORACLE\ORADATA\OLD_SID\TEMP01.DBF',
19. 'E:\ORACLE\ORADATA\OLD_SID\TOOLS01.DBF',
20. 'E:\ORACLE\ORADATA\OLD_SID\INDX01.DBF',
21. 'E:\ORACLE\ORADATA\OLD_SID\DR01.DBF',
22. 'E:\ORACLE\ORADATA\OLD_SID\WORK01.DBF',
23. 'E:\ORACLE\ORADATA\OLD_SID\TEMP02.DBF'
24. CHARACTER SET WE8ISO8859P1
25. ;

Where the string <OLD_SID> is the Oracle SID of the original database. This should be
changed to <NEW_SID>. Normallly this will be contained somewhere in the full filespec
(path + filename) of all redo logs, data logs and control files. If it isn't then it should have
been. This entire document assumes that you have the SID somewhere in the full
filespec of these crucial files and furthermore that there are no embedded spaces or other
weird characters in these filespecs. If you failed to observe these universal conventions
when you setup your database, you should not try to use any of the procedures outlined
in this document.

26. Copy The Existing Database To The New Location.

This will be a "cold" copy. So obviously you should make sure that the database is
shutdown and all services are stopped before attempting to "cold" copy the database.

If the copy is on the same host, you can use the DOS copy command (once the instance
is shutdown). If you are lack the manual dexterity required for a keyboard you can copy
the files with a mouse. If the target is a remote host then you will have to copy to a mass
storage device or copy across the network.

On the target host you need to copy all parameter files and all files mentioned above to
their new location. Make sure you preserve ownership and permissions. The copied
init<OLD_SID>.ora should be renamed to init<NEW_SID>.ora, and any parameter files
pointed to by an ifile parameter (e.g. parameter files such as config<OLD_SID>.ora)
should be renamed to contain <NEW_SID> (e.g. config<NEW_SID>.ora).

The datafiles and redo log files from the pervious step also need to be renamed to
contain the <NEW_SID> in the full filespec.

27. Set Up Parameter Files For The New Database

There may be several parameters that need to be edited in init<NEW_SID>.ora. In


particular you will need to edit the control_files parameter so that it points to the name
and location that you want to use for the new control files. You will also have to change
the DB_NAME parameter in init<NEW_SID>.ora. Change it to the newname for your
database. Usually this corresponds the <NEW_SID>. Any 'ifile' parameters will need to
be edited to point to the new name of the include file in the new location.

28. Create The Control File For The New Database.

Now edit the file ctrl<NEW_SID>.sql and strip out everything up to and including the
STARTUP NOMOUNT command. Remove the ALTER DATABASE OPEN command and
everything after it. This leaves a command which just creates the controlfile.

Now change all the appropriate instances of <OLD_SID> to <NEW_SID>. Unless you
have a very good reason for doing so, you should make the database name the same as
<NEW_SID>. Save this script in an area where you will find it again.

Make sure that your ORACLE_SID is set to <NEW_SID>. Then use the SVRMGRL utility
to run the following commands:
29. STARTUP NOMOUNT
30. @ctrl<NEW_SID>
31. Create The Services For NEW_SID

Create the services "OracleService<Sid>" and the "OracleStart<Sid>" for "NEW_SID"


with the following command:
32. oradim -new -sid <NEW_SID> -intpwd <password> -startmode auto
-pfile <path_name>
33. Run 'CREATE CONTROLFILE' For <NEW_SID>

Make sure that your current directory is the one that contains ctrl<NEW_SID>.sql

Set your ORACLE_SID to <NEW_SID>

Startup SVRMGRL and enter the following:


34. CONNECT INTERNAL
35. STARTUP NOMOUNT PFILE=<full path>\init<NEW_SID>.ora
36. @ctrl<NEW_SID>
37. ALTER DATABASE OPEN RESETLOGS;

You might also like