Monday, June 23, 2014

How to rename a database in Oracle

Steps to change DBID and DBNAME:

Source database name is DCPROC and we will convert it to DRPROC.

Step 1. Mount the database after a clean shutdown:

[oracle@netmindtwcint ~]$ export ORACLE_SID=DCPROC

[oracle@netmindtwcint ~]$ sqlplus sys as sysdba

SQL> shutdown immediate;

SQL> startup mount;

Step 2. Invoke the DBNEWID utility (nid) specifying the new DBNAME from the command line using a user with SYSDBA privilege:

1. TO CHANGE ONLY DB NAME

% nid TARGET=SYS DBNAME=LSAUDI SETNAME=YES

2.  TO CHANGE ONLY DBID

% nid TARGET=SYS

[oracle@mumvfspocsmdb log]$ nid TARGET=SYS DBNAME=DRPROC 

DBNEWID: Release 11.2.0.3.0 - Production on Fri Oct 4 14:41:21 2013

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

Password:
Connected to database DCPROC (DBID=2392917474)

Connected to server version 11.2.0

Control Files in database:
    /oracle_backup/oracle/ora_control1.ctl
    /oracle_backup/oracle/flash_recovery_area/control02.ctl

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

Proceeding with operation
Changing database ID from 2392917474 to 1776249945
Changing database name from DCPROC to DRPROC
    Control File /oracle_backup/oracle/ora_control1.ctl - modified
    Control File /oracle_backup/oracle/flash_recovery_area/control02.ctl - modified
    Datafile /oracle_backup/oracle/system01.db - dbid changed, wrote new name
    Datafile /oracle_backup/oracle/sysaux01.db - dbid changed, wrote new name
    Datafile /oracle_backup/oracle/undotbs01.db - dbid changed, wrote new name
    Datafile /oracle_backup/oracle/saudidata1.db - dbid changed, wrote new name
    Datafile /oracle_backup/oracle/temp01.db - dbid changed, wrote new name
    Control File /oracle_backup/oracle/ora_control1.ctl - dbid changed, wrote new name
    Control File /oracle_backup/oracle/flash_recovery_area/control02.ctl - dbid changed, wrote new name
    Instance shut down

Database name changed to DRPROC.
Modify parameter file and generate a new password file before restarting.
Database ID for database DRPROC changed to 1776249945.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

Step 3  Create a new password file:

[oracle@netmindtwcint dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwDRPROC password=Oracle entries=10

Step 4 Rename the initFILE to match the new DBNAME.

Make new init.ora file from existing init.ora file and change db_name parameter from DCPROC to DRPROC manually

change *.db_name='DCPROC' to *.db_name='DRPROC' in initDRPROC.ora file.

[oracle@netmindtwcint dbs]$ cp initDCPROC.ora initDRPROC.ora

SQL> alter system set db_name='DRPROC' scope=memory;

OR

Rename the SPFILE to match the new DBNAME. 
    
Make new spfileDRPROC.ora file and from existing spfileDCPROC.ora file and change db_name parameter from DCPROC to DRPROC commandly  

[oracle@netmindtwcint dbs]$ cp spfileDCPROC.ora spfileDRPROC.ora;

SQL> alter system set db_name='DRPROC' scope=spfile

Step 5 Configure listener & tnsnames files

Change the $ORACLE_HOME/network/admin/tnsnames.ora file wherever it has the old db name.

If there is a static registration of the database in the listener.ora file then change the database name in the following file $ORACLE_HOME/network/admin/listener.ora.

Step 6. Open the database with Resetlogs option:

[oracle@netmindtwcint dbs]$ sqlplus sys as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Fri Apr 27 15:00:03 2012

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

Enter password:
Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1345376 bytes
Variable Size             167774368 bytes
Database Buffers          360710144 bytes
Redo Buffers                5832704 bytes
Database mounted.

SQL> alter database open resetlogs;

Database altered.



No comments:

Post a Comment