How to change database name in oracle?

Step-I:- Start the database in Mount Stage

[oracle@rizwan ~]$ export ORACLE_SID=prod
[oracle@rizwan ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sun May 17 22:14:53 2015

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS>startup mount
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1344652 bytes
Variable Size             155192180 bytes
Database Buffers          150994944 bytes
Redo Buffers                6328320 bytes
Database mounted.
SYS>exit

Step-II:- Use NID tool at OS level (new id)

NOTE:- Here DB NAME=NEW DB NAME

[oracle@rizwan ~]$ nid target=sys/manager dbname=prod2

DBNEWID: Release 11.2.0.3.0 - Production on Sun May 17 22:38:29 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to database PROD (DBID=291288224)

Connected to server version 11.2.0

Control Files in database:
    /u02/db/prod/control01.ctl
    /u02/db/prod/control02.ctl

Change database ID and database name PROD to PROD2? (Y/[N]) => y

Proceeding with operation
Changing database ID from 291288224 to 1531791333
Changing database name from PROD to PROD2
    Control File /u02/db/prod/control01.ctl - modified
    Control File /u02/db/prod/control02.ctl - modified
    Datafile /u02/db/prod/system01.db - dbid changed, wrote new name
    Datafile /u02/db/prod/sysaux01.db - dbid changed, wrote new name
    Datafile /u02/db/prod/undotbs01.db - dbid changed, wrote new name
    Datafile /u02/db/prod/users01.db - dbid changed, wrote new name
    Datafile /u02/db/prod/tbs1.db - dbid changed, wrote new name
    Datafile /u01/home/tbs0.db - dbid changed, wrote new name
    Datafile /u02/db/prod/tbs21.db - dbid changed, wrote new name
    Datafile /u02/db/prod/temp01.db - dbid changed, wrote new name
    Datafile /u02/db/prod/tmp1.db - dbid changed, wrote new name
    Control File /u02/db/prod/control01.ctl - dbid changed, wrote new name
    Control File /u02/db/prod/control02.ctl - dbid changed, wrote new name
    Instance shut down

Database name changed to PROD2.
Modify parameter file and generate a new password file before restarting.
Database ID for database PROD2 changed to 1531791333.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

Step-III:- change name in parameter file and also name of Parameter file

SYS>create pfile from spfile;

File created.

SYS>host

[oracle@rizwan ~]$ cd $ORACLE_HOME/dbs
[oracle@rizwan dbs]$ ls
hc_prod.dat  initprod.ora  lkPROD  orapwprod  spfileprod.ora
hc_test.dat  inittest.ora  lkTEST  orapwtest
[oracle@rizwan dbs]$ vi initprod.ora
Note:-Change db name in parameter file
db_name=prod2

[oracle@rizwan dbs]$ mv initprod.ora initprod2.ora
Note:-Change parameter file name initprod.ora to initprod2.ora

Step-IV:-Start with new db name

[oracle@rizwan dbs]$ export ORACLE_SID=prod2
[oracle@rizwan dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sun May 17 22:50:24 2015

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

Connected to an idle instance.

SYS>startup mount
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1344652 bytes
Variable Size             104860532 bytes
Database Buffers          201326592 bytes
Redo Buffers                6328320 bytes
Database mounted.

SYS>alter database open resetlogs;



Database opened.

No comments:

Post a Comment