Google it ....

Showing posts with label change dbname in oracle. Show all posts
Showing posts with label change dbname in oracle. Show all posts

Friday, November 15, 2013

How To change database name (DB_NAME) and DB_ID in Oracle Database?

The DBID is an internal, unique identifier for a database. RMAN distinguishes databases by DBID, so you could not register a seed database and a manually copied database together in the same RMAN repository.
changing DBID is a serious procedure. When you change DBID previous backups and archived redo logs become invalid.

1) shutdown immediate;
2) startup mount;
I) To change only DBID just invoke nid target=username/pass
II) To change both DBID and DBNAME invoke nid target=username/pass DBNAME=new_database_name
III)To change only DBNAME invoke nid target=username/pass DBNAME=new_database_name SETNAME=y

I show you how to change database name and dbid in oracle database:

SQL> select dbid, name from v$database;

      DBID NAME
---------- ---------
2570398171 TESTDB
SQL> shutdown immediate;
.....
SQL> startup mount;
.....
nid target=sys/oracle dbname=test

DBNEWID: Release 11.2.0.1.0 - Production on Thu Nov 14 21:11:16 2013

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

Connected to database TESTDB (DBID=2570398171)

Connected to server version 11.2.0

Control Files in database:
    +DG1/testdb/controlfile/current.296.787767029
    +DG1/testdb/controlfile/current.323.787767031

Changing database ID from 2570398171 to 2129633269
Changing database name from TESTDB to TEST
    Control File +DG1/testdb/controlfile/current.296.787767029 - modified
    Control File +DG1/testdb/controlfile/current.323.787767031 - modified
    Datafile +DG1/testdb/datafile/system.277.78776789 - dbid changed, wrote new name
    Datafile +DG1/testdb/datafile/sysaux.334.78776794 - dbid changed, wrote new name
    Datafile +DG1/testdb/datafile/undotbs1.336.78776799 - dbid changed, wrote new name
    Datafile +DG1/testdb/datafile/users.338.78776802 - dbid changed, wrote new name
    Datafile +DG1/testdb/datafile/example.340.78776802 - dbid changed, wrote new name
    Datafile +DG1/testdb/tempfile/temp1.262.83150196 - dbid changed, wrote new name
    Control File +DG1/testdb/controlfile/current.296.787767029 - dbid changed, wrote new name
    Control File +DG1/testdb/controlfile/current.323.787767031 - dbid changed, wrote new name
Instance shut down

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


after that startup database in nomount mode an change db_name parameter after that you can start database with resetlogs option;
SQL> startup nomount;
.....
SQL> alter system set db_name=test scope=spfile;
.....
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database open resetlogs;
.....
orapwd file=$ORACLE_HOME/dbs/orapwtest.ora password=anypass entries=5;

now let me check dbid and db_name for ensure that they have new values
SQL> select dbid, name from v$database;
      DBID NAME
---------- ---------
2129633269 TEST

everything is ok, after that it's vital to make new full backup.