Monday, August 19, 2013

Change database name using nid



SQL> startup mount

ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              92276304 bytes
Database Buffers          188743680 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> !
[oracle@pk ~]$ nid TARGET=system DBNAME=prod1 SETNAME=Y

DBNEWID: Release 10.2.0.1.0 - Production on Sat Aug 17 18:43:12 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Password:
Connected to database DEV1 (DBID=3432497468)

Connected to server version 10.2.0

Control Files in database:
    /home/oracle/oracle/product/10.2.0/oradata/dev1/control01.ctl
    /home/oracle/oracle/product/10.2.0/oradata/dev1/control02.ctl
    /home/oracle/oracle/product/10.2.0/oradata/dev1/control03.ctl

Change database name of database DEV1 to PROD1? (Y/[N]) => Y

Proceeding with operation
Changing database name from DEV1 to PROD1
    Control File /home/oracle/oracle/product/10.2.0/oradata/dev1/control01.ctl - modified
    Control File /home/oracle/oracle/product/10.2.0/oradata/dev1/control02.ctl - modified
    Control File /home/oracle/oracle/product/10.2.0/oradata/dev1/control03.ctl - modified
    Datafile /home/oracle/oracle/product/10.2.0/oradata/dev1/system01.dbf - wrote new name
    Datafile /home/oracle/oracle/product/10.2.0/oradata/dev1/undotbs01.dbf - wrote new name
    Datafile /home/oracle/oracle/product/10.2.0/oradata/dev1/sysaux01.dbf - wrote new name
    Datafile /home/oracle/oracle/product/10.2.0/oradata/dev1/users01.dbf - wrote new name
    Datafile /home/oracle/oracle/product/10.2.0/oradata/dev1/example01.dbf - wrote new name
    Datafile /home/oracle/oracle/product/10.2.0/oradata/dev1/temp01.dbf - wrote new name
    Control File /home/oracle/oracle/product/10.2.0/oradata/dev1/control01.ctl - wrote new name
    Control File /home/oracle/oracle/product/10.2.0/oradata/dev1/control02.ctl - wrote new name
    Control File /home/oracle/oracle/product/10.2.0/oradata/dev1/control03.ctl - wrote new name
    Instance shut down

Database name changed to PROD1.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.



This utility won’t change the database name in pfile, so change the database name (DB_NAME) in pfile manually and create password file (if necessary).


Mount the database
SQL> STARTUP MOUNT
Open the database in RESETLOGS mode and resume normal use
SQL> ALTER DATABASE OPEN RESETLOGS;
SQL> select dbid, name from v$database;


Make a new database backup. Because you had reset the online redo logs, the old backups and archived logs are no longer usable in the current incarnation of the database.