Friday, March 27, 2020

How Change the DBID and Database Name using DBNEWID utility (nid)


How to Change the DBID and Database Name


Step 1
-----------

SQL> select name,open_mode,dbid,db_unique_name from v$database;

NAME      OPEN_MODE                  DBID DB_UNIQUE_NAME
--------- -------------------- ---------- ------------------------------
ORCL      READ WRITE           1553847750 orcl

SQL>


Step 2
----------

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

Step 3
---------

SQL> startup mount
ORACLE instance started.

Total System Global Area 1519898624 bytes
Fixed Size                  2253464 bytes
Variable Size             436211048 bytes
Database Buffers         1073741824 bytes
Redo Buffers                7692288 bytes
Database mounted.
SQL>



Step 4
----------

nid TARGET=/ DBNAME=RDX


[oracle@localhost ~]$ which nid
/u01/app/oracle/product/11.2.0/dbhome_1/bin/nid
[oracle@localhost ~]$
[oracle@localhost ~]$
[oracle@localhost ~]$
[oracle@localhost ~]$ nid TARGET=/ DBNAME=RDX

DBNEWID: Release 11.2.0.4.0 - Production on Fri Mar 27 23:41:13 2020

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

Connected to database ORCL (DBID=1553847750)

Connected to server version 11.2.0

Control Files in database:
    /u01/app/oracle/oradata/orcl/control01.ctl
    /u01/app/oracle/fast_recovery_area/orcl/control02.ctl

Change database ID and database name ORCL to RDX? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 1553847750 to 1347507995
Changing database name from ORCL to RDX
    Control File /u01/app/oracle/oradata/orcl/control01.ctl - modified
    Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - modified
    Datafile /u01/app/oracle/oradata/orcl/system01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/sysaux01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/undotbs01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/users01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/example01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/temp01.db - dbid changed, wrote new name
    Control File /u01/app/oracle/oradata/orcl/control01.ctl - dbid changed, wrote new name
    Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - dbid changed, wrote new name
    Instance shut down

Database name changed to RDX.
Modify parameter file and generate a new password file before restarting.
Database ID for database RDX changed to 1347507995.
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.

[oracle@localhost ~]$


Need to change DB_NAME in parameter before start otherwise you will get below error

[oracle@localhost ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 27 23:41:46 2020

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

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1519898624 bytes
Fixed Size                  2253464 bytes
Variable Size             436211048 bytes
Database Buffers         1073741824 bytes
Redo Buffers                7692288 bytes
ORA-01103: database name 'RDX' in control file is not 'ORCL'


SQL>

SQL>
SQL> create pfile from spfile;

File created.

SQL> shut immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL>

[oracle@localhost ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/


[oracle@localhost dbs]$ mv spfileorcl.ora spfileorcl.ora_bkp

Chnage DB_NAME in parameter file

Step 6
------------

SQL> startup mount
ORACLE instance started.

Total System Global Area 1519898624 bytes
Fixed Size                  2253464 bytes
Variable Size             436211048 bytes
Database Buffers         1073741824 bytes
Redo Buffers                7692288 bytes
Database mounted.
SQL>
SQL> alter database open resetlogs;

Database altered.

SQL> select name,open_mode,dbid,db_unique_name from v$database;

NAME      OPEN_MODE                  DBID DB_UNIQUE_NAME
--------- -------------------- ---------- ------------------------------
RDX       READ WRITE           1347507995 RDX

SQL>


To Revert
============

nid TARGET=/ REVERT=YES






No comments:

Post a Comment