2
Articles from Rants & Raves - The Blog! Rename an Oracle 10g or 11g Database 2012- 03- 07 16:03:28 No rma n Due to a document not being supplied to me recently, I built a few 11g databases with the wrong SID. I needed to change them all. I found a few web pages, Oracle and others, on using the nid utility to do just that, however, they were incomplete. The full process is described here. The following has been tested fully on an 11.2.0.2 Oracle database. The nid utility used also exists in Oracle 10.2.0.5 and possibly other versions that I do not have access to at the moment. Backup the database or ensure a backup exists in RMAN. This shouldn’t be necessary but you are a DBA right? And chances we do not take! create pfile='/home/oracle/initnew_sid.ora' from spfile; this ensures that the pfile you are about to edit contains all the current settings. It is saved in a non-standard location for safety. Shutdown the database cleanly. Use shutdown or shutdown immediate. Startup mount the database. Check the open_cursors parameter. If you have a lot of data files you might need to increase this setting temporarily: 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 The logfile created will show details of what just happened and should be checked for errors. As far as I am aware, but don’t trust me on this, errors will not change the database at all. The instance will also have been shut down at the end of the nid command. Edit /etc/oratab to change the old sid to the new one. Edit tnsnames.ora to do likewise. Also applies to OID, LDAP, whatever you use for alias resolution. Stop the appropriate listener, edit listener.ora and restart the listener. If the listener in question serves other databases, just edit the listener.ora f ile and run lsnrctl reload listener_name. Copy the newly created /home/oracle/initnew_sid.ora to $ORACLE_HOME/dbs/initnew_sid.ora then edit the new file and change the db_name parameter.

Rename the Database

Embed Size (px)

DESCRIPTION

Rename the database

Citation preview

Page 1: Rename the Database

Articles from Rants & Raves - The Blog!Rename an Oracle 10g or 11g Database2012-03-07 16:03:28 Norman

Due to a document not being supplied to me recent ly, I built a few 11gdatabases with the wrong SID. I needed to change them all. I found a few webpages, Oracle and others, on using the nid ut ilit y to do just that , however,they were incomplete. The full process is described here.

The following has been tested fully on an 11.2.0.2 Oracle database. The nidut ilit y used also exists in Oracle 10.2.0.5 and possibly other versions that I donot have access to at the moment .

Backup the database or ensure a backup exists in RMAN. This shouldn’tbe necessary but you are a DBA right? And chances we do not take!create pfile='/home/oracle/initnew_sid.ora' from spfile;this ensures that the pf ile you are about to edit contains all the currentset t ings. It is saved in a non-standard locat ion for safety.Shutdown the database cleanly. Use shutdown or shutdownimmediate.Startup mount the database.Check the open_cursors parameter. If you have a lot of data f iles youmight need to increase this set t ing temporarily:

alter system set open_cursors=1500 scope=memory;

In a shell session run the following nid command:

nid target=/ dbname=new_sid setname=y logfile=new_name.log

The logf ile created will show details of what just happened and shouldbe checked for errors. As far as I am aware, but don’t t rust me on this,errors will not change the database at all.

The instance will also have been shut down at the end of the nidcommand.

Edit /etc/oratab to change the old sid to the new one.Edit tnsnames.ora to do likewise. Also applies to OID, LDAP, whateveryou use for alias resolut ion.Stop the appropriate listener, edit listener.ora and restart thelistener. If the listener in quest ion serves other databases, just edit thelistener.ora f ile and run lsnrctl reload listener_name.Copy the newly created /home/oracle/initnew_sid.ora to$ORACLE_HOME/dbs/initnew_sid.ora then edit the new f ile andchange the db_name parameter.

Page 2: Rename the Database

You may, if desired, delete the old f iles$ORACLE_HOME/dbs/initold_sid.ora and$ORACLE_HOME/dbs/spfileold_sid.ora as they are no longerneeded. (Unless you plan on renaming the database back again ofcourse!)Export ORACLE_SID as the new sid. ORACLE_HOME will remain the sameas before.Run the orapwd command to create a new password f ile if required.Startup the database.create spfile='oracle_home/dbs/spfilenew_sid.ora' frompfile; Obviously subst itut ing the correct values for new_sid andoracle_home.Shutdown and restart the database to use the new spf ile.Check it all just worked:

select name from v$database;show parameter db_name

That ’s the simple bit and in theory is all you need to do. However, be awarethat any data f iles, cont rol f iles, recovery f ile dest inat ions etc st ill have theirold format names. You may end up with a database called fred located in/srv/barney/oradata for example. If you wish to go down the route ofrenaming everything to suit the database name, see part 2 of this discussion,here.

As the cont rol f iles are not overwrit ten by this process, and because the DBIDdoesn’t change, all your RMAN backup informat ion is safe and even af ter thedatabase has been renamed, you can use an old backup to restore andrecover the database. I’ve tested this on a tablespace recovery to be sure.

Ok, when I say your backups are safe, they are, but if you t ry torestore the cont rolf ile f rom an old pre-rename dump, it will restorewith no errors. However, when you at tempt to mount the databaseyou will be informed that the name in the cont rolf ile doesn’t matchthe database. Edit the restored cont rolf ile(s) to change the nameand cont inue.

I’m pret t y sure that because the DBID doesn’t change, an RMAN catalogue willnot lose any backup details either. On my test system, I don’t yet have acatalogue to play with, so best you test on an expendable database f irst . Justsaying!

Online and backed up archived logs as well as the online redo logs are usedquite happily to apply any required REDO.

It just works!