Changing Oracle Database ID and Name (nid)

 Getting back into Oracle as a DBA I've been reading up and watching tutorials to try to get the old skills back and update to the new tools, last time I DBAed in anger we were still on Oracle 7 and 8i, 9i had been out a while and 10g was in early versions, but because much of our software was so old we weren't using it much.  I came across a tutorial on how to update the name and ID of a database.  This is useful if you have copied a database and want to rename the copy to stop it being confused with the old, or if you want to have it on the same machine as the old.  The database ID is an internal number used by Oracle to identify the database, it looks like the main reason you'd want to change the ID is if you use RMAN and want to have both in the same repository.

PLEASE NOTE: The below is based on a tutorial I watched and has not been tested, errors and omissions are expected.  Before using in production do a few practice runs on sandbox databases.  Proceed at your own risk.

Change Just Database ID

Shutdown the database in a consistent state:

sqlplus / as sysdba

shutdown immediate

startup restrict

shutdown

 Then startup in MOUNT mode:

startup mount

 At the Linux prompt enter:

nid TARGET=SYS/<password>@[Oracle SID]

You will then be prompted to confirm that you want to change the database ID.  Respond Y.  The process will then update the database files and notify you of the new database ID, then shut the database down.

Recreate the password file with orapwd.

Startup the database in MOUNT mode then open with the RESETLOGS option:

sqlplus / as sysdba

startup mount

alter database open resetlogs

Change Just Database Name

If you use an SPFILE (Oracle's binary parameters file) then create an editable text versions using:

sqlplus / as sysdba

create pfile from spfile

(It's a good idea to do this periodically anyway as a backup)

Shutdown the database in a consistent state:

sqlplus / as sysdba

shutdown immediate

startup restrict

shutdown

 Then startup in MOUNT mode:

startup mount

 At the Linux prompt enter:

nid TARGET=SYS/<password>@[Oracle SID] DBNAME=[New Database Name] SETNAME=YES

You will be prompted to confirm that you want to rename the database.  Respond Y.

The process will then update the database files.  Note that only the actual database files will be updated, most of the ancillary settings and parameter files will not be updated.

Recreate the password file using orapwd.

Edit the listener settings file with the new database name and the tnsnames.ora files on the server and each client with the new database name.

Edit the PFILE you created with the new database and save with the new filename.

Edit /etc/oratab to point to the new database name.

start the database explicitly pointing  to the PFILE you just edited

sqlplus / as sysdba

startup pfile="[path and filename of changed PFILE]"

If you usually use an SPFILE recreate it using:

create spfile from pfile


Change Database ID and name in one action

 If you use an SPFILE (Oracle's binary parameters file) then create an editable text versions using:

sqlplus / as sysdba

create pfile from spfile

(It's a good idea to do this periodically anyway as a backup)

Shutdown the database in a consistent state:

sqlplus / as sysdba

shutdown immediate

startup restrict

shutdown

 Then startup in MOUNT mode:

startup mount

 At the Linux prompt enter:

nid TARGET=SYS/<password>@[Oracle SID] DBNAME=[New Database Name]

 You will then be prompted to confirm that you want to change the database ID and name.  Respond Y.  The process will then update the database files and notify you of the new database ID, then shut the database down.  Note that, again, only the actual database files will be updated, most of the ancillary settings and parameter files will not be updated.

Recreate the password file with orapwd.

Edit the listener settings file with the new database name and the tnsnames.ora files on the server and each client with the new database name.

Edit the PFILE you created with the new database and save with the new filename.

Edit /etc/oratab to point to the new database name.

Startup the database in MOUNT mode explicitly pointing  to the PFILE you just edited then open with the RESETLOGS option:

sqlplus / as sysdba pfile="[path and filename of changed PFILE]"

startup mount

alter database open resetlogs

If you usually use an SPFILE recreate it using:

create spfile from pfile

 

Comments

Popular posts from this blog

SQL*Server Import Export Wizard 2017 vs Office 64 bit

Preventing record deletion

Oracle aims to secure future of Sparc, Solaris and Sun hardware