Rename The Database

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Articles from Rants & Raves - The Blog!

Rename an Oracle 10g or 11g Database


2012- 03- 07 16:03:28 Norman

Due t o a document not being supplied t o me recent ly, I built a f ew 11g


dat abases wit h t he wrong SID. I needed t o change t hem all. I f ound a f ew web
pages, Oracle and ot hers, on using t he nid ut ilit y t o do just t hat , however,
t hey were incomplet e. T he f ull process is described here.
T he f ollowing has been t est ed f ully on an 11.2.0.2 Oracle dat abase. T he nid
ut ilit y used also exist s in Oracle 10.2.0.5 and possibly ot her versions t hat I do
not have access t o at t he moment .
Backup t he dat abase or ensure a backup exist s in RMAN. T his shouldnt
be necessary but you are a DBA right ? And chances we do not t ake!
create pfile='/home/oracle/initnew_sid.ora' from spfile;
t his ensures t hat t he pf ile you are about t o edit cont ains all t he current
set t ings. It is saved in a non-st andard locat ion f or saf et y.
Shut down t he dat abase cleanly. Use shutdown or shutdown
immediate.
Startup mount t he dat abase.
Check t he open_cursors paramet er. If you have a lot of dat a f iles you
might need t o increase t his set t ing t emporarily:
alter system set open_cursors=1500 scope=memory;
In a shell session run t he f ollowing nid command:
nid target=/ dbname=new_sid setname=y logfile=new_name.log
T he logf ile creat ed will show det ails of what just happened and should
be checked f or errors. As f ar as I am aware, but dont t rust me on t his,
errors will not change t he dat abase at all.
T he inst ance will also have been shut down at t he end of t he nid
command.
Edit /etc/oratab t o change t he old sid t o t he new one.
Edit tnsnames.ora t o do likewise. Also applies t o OID, LDAP, what ever
you use f or alias resolut ion.
St op t he appropriat e list ener, edit listener.ora and rest art t he
list ener. If t he list ener in quest ion serves ot her dat abases, just edit t he
listener.ora f ile and run lsnrctl reload listener_name.
Copy t he newly creat ed /home/oracle/initnew_sid.ora t o
$ORACLE_HOME/dbs/initnew_sid.ora t hen edit t he new f ile and
change t he db_name paramet er.

You may, if desired, delet e t he old f iles


$ORACLE_HOME/dbs/initold_sid.ora and
$ORACLE_HOME/dbs/spfileold_sid.ora as t hey are no longer
needed. (Unless you plan on renaming t he dat abase back again of
course!)
Export ORACLE_SID as t he new sid. ORACLE_HOME will remain t he same
as bef ore.
Run t he orapwd command t o creat e a new password f ile if required.
St art up t he dat abase.
create spfile='oracle_home/dbs/spfilenew_sid.ora' from
pfile; Obviously subst it ut ing t he correct values f or new_sid and
oracle_home.
Shut down and rest art t he dat abase t o use t he new spf ile.
Check it all just worked:
select name from v$database;
show parameter db_name
T hat s t he simple bit and in t heory is all you need t o do. However, be aware
t hat any dat a f iles, cont rol f iles, recovery f ile dest inat ions et c st ill have t heir
old f ormat names. You may end up wit h a dat abase called fred locat ed in
/srv/barney/oradata f or example. If you wish t o go down t he rout e of
renaming everyt hing t o suit t he dat abase name, see part 2 of t his discussion,
here.
As t he cont rol f iles are not overwrit t en by t his process, and because t he DBID
doesnt change, all your RMAN backup inf ormat ion is saf e and even af t er t he
dat abase has been renamed, you can use an old backup t o rest ore and
recover t he dat abase. Ive t est ed t his on a t ablespace recovery t o be sure.
Ok, when I say your backups are saf e, t hey are, but if you t ry t o
rest ore t he cont rolf ile f rom an old pre-rename dump, it will rest ore
wit h no errors. However, when you at t empt t o mount t he dat abase
you will be inf ormed t hat t he name in t he cont rolf ile doesnt mat ch
t he dat abase. Edit t he rest ored cont rolf ile(s) t o change t he name
and cont inue.
Im pret t y sure t hat because t he DBID doesnt change, an RMAN cat alogue will
not lose any backup det ails eit her. On my t est syst em, I dont yet have a
cat alogue t o play wit h, so best you t est on an expendable dat abase f irst . Just
saying!
Online and backed up archived logs as well as t he online redo logs are used
quit e happily t o apply any required REDO.
It just works!

You might also like