Wednesday, March 13, 2013

Change production database name

Today I will show you how to rename existing database name. Before it take backup of your database and also please note that this step will change only database name not dbid.

My database name is prod2 and oracle version is 11g R2. I will change it to prod name.

SQL> select name from v$database;

NAME
---------
PROD2

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

SQL>

[oracle@localhost ~]$ uname -n
localhost.localdomain

[oracle@localhost ~]$ more /etc/redhat-release 
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

Firstly shutdown database and open it on mount mode.

[oracle@localhost ~]$ sql

SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 13 19:29:16 2013

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


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

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  318046208 bytes
Fixed Size                  1336260 bytes
Variable Size             109055036 bytes
Database Buffers          201326592 bytes
Redo Buffers                6328320 bytes
Database mounted.
SQL> 

Now execute nid utility (dbnewid) and specify new database name.

[oracle@localhost ~]$ nid target =/ dbname=prod setname=YES

DBNEWID: Release 11.2.0.1.0 - Production on Wed Mar 13 19:33:07 2013

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

Connected to database PROD2 (DBID=1461820883)

Connected to server version 11.2.0

Control Files in database:
    /u01/app/oracle/oradata/prod2/control01.ctl
    /u01/app/oracle/flash_recovery_area/prod2/control02.ctl

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

Proceeding with operation
Changing database name from PROD2 to PROD
    Control File /u01/app/oracle/oradata/prod2/control01.ctl - modified
    Control File /u01/app/oracle/flash_recovery_area/prod2/control02.ctl - modified
    Datafile /u01/app/oracle/oradata/prod2/system01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/sysaux01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/undotbs01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/users01.db - wrote new name
    Datafile /u01/app/oracle/oradata/prod2/temp01.db - wrote new name
    Control File /u01/app/oracle/oradata/prod2/control01.ctl - wrote new name
    Control File /u01/app/oracle/flash_recovery_area/prod2/control02.ctl - wrote new name
    Instance shut down

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

[oracle@localhost ~]$ 


Create new name directories in admin folder

[oracle@localhost admin]$ mkdir prod
[oracle@localhost admin]$ cd prod
[oracle@localhost prod]$ mkdir adump dpdump pfile


Last action is change pfile and password file and open database with resetlogs option.

[oracle@localhost pfile]$ pwd
/u01/app/oracle/admin/prod2/pfile

[oracle@localhost pfile]$ ls
init.ora.2132013192312

[oracle@localhost pfile]$ cat init.ora.2132013192312 | grep db_name
db_name=prod2

#change db_name to new db_name
#change audit_file_dest to new path : /u01/app/oracle/admin/prod/adump
[oracle@localhost pfile]$ vi init.ora.2132013192312

[oracle@localhost pfile]$ cat init.ora.2132013192312 | grep db_name
db_name=prod


[oracle@localhost pfile]$ cat init.ora.2132013192312 | grep audit_file
audit_file_dest=/u01/app/oracle/admin/prod/adump

[oracle@localhost dbs]$ pwd
/u01/oracle/product/11.2.0/db_1/dbs

[oracle@localhost dbs]$ orapwd file=orapwprod entries=5 ignorecase=y password=oracle

[oracle@localhost dbs]$ export | grep ORACLE_SID
declare -x ORACLE_SID="prod"
[oracle@localhost dbs]$ 


mv init file from ../prod2/pfile/ to ../prod/pfile/
and recreate spfile

[oracle@localhost dbs]$ export | grep ORACLE_SID
declare -x ORACLE_SID="prod"
[oracle@localhost dbs]$ sql

SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 13 19:52:23 2013

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

Connected to an idle instance.

SQL> shut immediate
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
SQL> shut abort;
ORACLE instance shut down.

SQL> create spfile from pfile='/u01/app/oracle/admin/prod/pfile/init.ora.2132013192312';

File created.

SQL> 

SQL> startup mount
ORACLE instance started.

Total System Global Area  318046208 bytes
Fixed Size                  1336260 bytes
Variable Size             109055036 bytes
Database Buffers          201326592 bytes
Redo Buffers                6328320 bytes
Database mounted.

SQL> alter database open;

Database altered.

SQL> select name from v$database;

NAME
---------
PROD

SQL> 


No comments:

Post a Comment