Saturday, 27 April 2019

Using NID utility of Oracle to change the Database Name



DBNEWID is a database utility, in $ORACLE_HOME/bin directory, that can change the internal database identifier (DBID) and the database name (DBNAME) for an operational database. Prior to the introduction of the DBNEWID utility, we used to manually create a copy of a database and give it a new database name (DBNAME) by re-creating the control file. However, alteration of the internal database identifier (DBID) of an instance was impossible.
     The DBID is an internal, unique identifier for a database. Because Recovery Manager (RMAN) distinguishes databases by DBID, you could not register a seed database and a manually copied database together in the same RMAN repository. The DBNEWID utility solves this problem.

NID utility allows us to change:

* Only DBID of a database
* Only DBNAME of a database
* Both DBNAME and DBID of a database

Check the Database name and database ID:

SQL> select dbid, name from v$database;







Steps to change the database name:

1) Backup the database.
* Use RMAN or take a hot/cold backup of database.
2) shutdown the database.
SQL> shutdown immediate.
3) startup the database in mount stage.
SQL> startup mount.

Now invoke the DBNEWID (NID) utility specifying the DBNAME from the command line using a user with SYSDBA privilege.

$ nid target=sys/<password> dbname=<new_database_name> setname=yes

NOTE: The SETNAME parameter tells the DBNEWID utility to only alter the database name. If you don't specify SETNAME parameter DBNEWID utility will change both DBNAME and DBID. 

For example to change the database name ZEE to ORCL issue the following command.
$ nid target=sys/root123 dbname=ORCL setname=yes


























The DBNEWID utility performs validations in the headers of the datafiles and control files before attempting I/O to the files. If validation is successful, then DBNEWID prompts you to confirm the operation (unless you specify a log file, in which case it does not prompt), changes the DBID in all datafiles and then exits. The database is left mounted but is not yet usable.

4) Shutdown the database:
SQL> shutdown immediate

After changing the database name we have to change the database name in PFILE or SPFILE

PFILE= If using pfile edit the pfile and startup the database.
* Go to $ORACLE_HOME/dbs
* Open PFILE init<SID>.ora
* change the parameter DB_NAME and set the new database name ORCL.
* startup the database.

SPFILE= If using spfile issue following commands.
SQL> startup mount
SQL> alter system set db_name=ORCL scope=spfile;
SQL> shutdown immediate
SQL> startup

Check the database name and DBID:

SQL> select name, dbid from v$database;







You can see the database name has been changed to ORCL but DBID is the same.

Oratab needs to have the SID renamed:
Go to /etc/oratab file and rename the database name with the new name.
In my case, I changed it to ORCL.

Change the database name in listener.ora file:
Go to
$ cd $ORACLE_HOME/network/admin 
and change the SID in listener.ora file.

DBID Only

Follow the below steps to change the DBID of the database.

* Backup the database.
* Mount the database after a clean shutdown.

SQL> shutdown immediate
SQL> startup mount

Invoke the DBNEWID utility (nid) from the command line using a user with SYSDBA privilege. Do not specify a new DBNAME.

$ nid TARGET=sys/password































It will prompt you with

Change database ID of database ORCL? (Y/[N]) =>

Type Y if you want to continue.

After completion open the database with RESETLOGS.

SQL> STARTUP MOUNT
SQL> ALTER DATABASE OPEN RESETLOGS;

Issue the following command to check the new DBID.

SQL> select name, dbid from v$database;






You can see the DBID has been changed Successfully.

No comments:

Post a Comment

Ask your Questions....