Sei sulla pagina 1di 4

Change the database name only [changing TZDB to TZDR]

STEP 1: Backup the database.


RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
STEP 2: Mount the database after a clean shutdown:
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE, V$INSTANCE;

We have to change dbname in the parameter file, in case you are using spfile, create pfile so
that you will be able to change dbname after invoking nid
SQL> SHOW PARAMETER PFILE;
SQL> CREATE PFILE = '/tmp/pfile' FROM SPFILE;
STEP 3:

Invoke the DBNEWID utility (nid) specifying the new DBNAME from the command line using
a user with SYSDBA privilege:
$ which nid
$ nid target=SYS/PASSWORD dbname=new_name setname=YES logfile=new_name.log
$ nid target=SYS/PASSWORD dbname=TZDR setname=YES logfile=TZDR.log
Assuming the validation is successful the utility prompts for confirmation before performing the
actions.
Change database ID and database name TZDB to TZDR? (Y/[N]) => Y
If operation is failed, to revert changes, run the DBNEWID utility again, specifying the REVERT
keyword.
$ nid TARGET=SYS/PASSWORD REVERT=YES LOGFILE=revert.log
STEP 4:

Modify Paramater Files


Wherever the keyword TZDB name being used will be replaced by TZDR, change *.db_name='TZDB'
to *.db_name='TZDR' and append the entry *.instance_name=TZDR in init file
$ cd $ORACLE_HOME/dbs
$ ls -altr
$ cp initTZDB.ora initTZDR.ora
$ vi initTZDR.ora
Change instance name in /var/opt/oracle/oratab file for Solaris and /etc/oratab file for HP and
Linux
$ vi /var/opt/oracle/oratab
$ . oraenv
SQL> STARTUP;
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE, V$INSTANCE;

Change the dbid of the database alone


All previous RMAN backups will become invalid because the DBID has changed,

NOTE:

STEP 1: Backup the database.


RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
STEP 2: Mount the database after a clean shutdown:
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE;
SQL> SHOW PARAMETER PFILE;
SQL> CREATE PFILE = '/tmp/pfile' FROM SPFILE;
STEP 3:

Invoke the DBNEWID utility (nid) from the command line using a user with SYSDBA privilege,
do not specify DBNAME:
$ which nid
$ nid TARGET=SYS/password
$ nid TARGET=dbname
Assuming the validation is successful the utility prompts for confirmation before performing the
actions. Typical output may look something like:
Change database ID and database name TZDB to TZUAT? (Y/[N]) => Y
If operation is failed, to revert changes, run the DBNEWID utility again, specifying the REVERT
keyword.
$ nid TARGET=SYS/PASSWORD REVERT=YES LOGFILE=backout.log
If operation is successful, mount the database and open with resetlogs.
STEP 6: Open the database with RESETLOGS:
SQL> STARTUP MOUNT
SQL> ALTER DATABASE OPEN RESETLOGS;
STEP 7:

Backup the database.

Change the DBID and the DBNAME using NID


Changing DBNAME and/or DBID is one of the steps for cloning Oracle Databases. You can change
the database name by using controlfile creation scripts or using DBNEWID utility.
STEP 1: Backup the database.
STEP 2: Mount the database after a clean shutdown:
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE;
SQL> SHOW PARAMETER PFILE;
SQL> CREATE PFILE = '/tmp/pfile' FROM SPFILE;
STEP 3:

Invoke the DBNEWID utility (nid) specifying the new DBNAME from the command line using
a user with SYSDBA privilege:
$ nid TARGET=SYS/PASSWORD DBNAME=new_name LOGFILE=change_dbname.log

This utility wont change the database name in pfile, so change the database name (DB_NAME) in
pfile manually and create password file (if necessary).
STEP 4:

Modify Paramater Files


Wherever the keyword TZDB name being used will be replaced by TZDR, change *.db_name='TZDB'
to *.db_name='TZDR' and append the entry *.instance_name=TZDR in init file
$ cd $ORACLE_HOME/dbs
$ ls -altr
$ cp initTZDB.ora initTZDR.ora
$ vi initTZDR.ora
Change instance name in /var/opt/oracle/oratab file for Solaris and /etc/oratab file for HP and
Linux
$ vi /var/opt/oracle/oratab
$ . oraenv
SQL> STARTUP;
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE, V$INSTANCE;
SQL> STARTUP MOUNT
SQL> ALTER DATABASE OPEN RESETLOGS;
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE;

Change the DBID Using controlfile creation script:


You can create controlfile creation script using this command with sqlplus when database is on
mount or open status:
$ SQLPLUS / AS SYSDBA
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS /tmp/ctrl.sql' REUSE;
SQL> SHUT IMMEDIATE

$ vi /tmp/ctrl.sql'
After a quick modify on the first line of controlfile script into the /tmp/ctrl.sql file,
We can create new controlfiles with new database name on the TZDR database.
In addition, we need to add SET command before DATABASE when changing DB_NAME.
For examle;
This is the first line of script:
CREATE CONTROLFILE REUSE DATABASE TZDB NORESETLOGS FORCE LOGGING ARCHIVELOG

Lets change first line as:


CREATE CONTROLFILE REUSE SET DATABASE TZDR RESETLOGS ARCHIVELOG

After, running this new ctrl.sql file with nomount state, new controlfiles are created for TZDR
database and TZDR database is automatically changed to mount state. Then, you have to open
TZDR database with resetlogs option in order to recreate redolog files for new database.
SQL> STARTUP MOUNT

SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE;


SQL> EXECUTE dbms_backup_restore.zeroDbid(0);
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE;
DBID still

exist because it is in Dynamic Performance View which is always persistence as long as


the instance is up.
SQL> SHUT IMMEDIATE;

---Delete all control files


SQL> SHOW PARAMETER CONTROL;

$ cd /u01/app/oracle/oradata/TZDB/
$ rm *.clt
$ cd /u01/app/oracle/fast_recovery_area/TZDB
$ rm *.clt
---Execute created control file
SQL> @/tmp/ctl.sql
SQL> ALTER DATABASE OPEN RESETLOGS;
SQL> SELECT NAME, DBID, INSTANCE_NAME FROM V$DATABASE;

Potrebbero piacerti anche