Oracle 使用Nid 修改数据库的DBID 和 Database Name

How to Change the DBID, DBNAME Using NID Utility (Doc ID 863800.1)

 

Changing the DBID and Database Name (DB_NAME) :

1. Ensure you have valid cold/hot backup of database. If it's a hot backup (RMAN or OS), ensure you also have all the archived logs and backup of all Online Redo logs (after database is consistently shutdown).

2. export ORACLE_HOME=<Path of the Oracle Home> -- Unix and Linux

set ORACLE_HOME=<Path of the Oracle Home> -- Windows 

3. cd <Oracle Home>/bin

4. Drop the dbconsole :

Refer to the following note for more information:

Note.278100.1 How To Drop, Create And Recreate DB Control In A 10g Database.

5. Bring the database to the Mount stage:
    SQL> STARTUP MOUNT


6. If you need to use TNS to connect to database, make sure that you have DB_OLD specified in the tnsnames.ora and listener is started.
    You can also check if you able to connect to the database using sqlplus :   
  $ sqlplus sys/<password>@DB_OLD

7. Issue following command to invoke NID utility:   

$ nid TARGET=SYS/password@DB_OLD DBNAME=DB_NEW

or

$ nid TARGET=SYS/password DBNAME=DB_NEW

 

The DBNEWID utility performs validations in the headers of the datafiles and control files before attempting I/O to the files. If validation is successful, then DBNEWID prompts you to confirm the operation (unless you specify a log file, in which case it does not prompt), changes the DBID (and the DBNAME, if specified, as in this example) for each datafile, including offline normal and read-only datafiles, shuts down the database, and then exits.


The following is an example of what the output for this would look like:

DBNEWID: Release 10.2.0.4.0 - Production on Mon Jul 27 18:29:06 2009

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

Connected to database TSTNID2 (DBID=729333573)

Connected to server version 10.2.0

Control Files in database:
    D:\ORACLE\ORADATA\DB102NEW\CONTROL01.CTL
    D:\ORACLE\ORADATA\DB102NEW\CONTROL02.CTL
    D:\ORACLE\ORADATA\DB102NEW\CONTROL03.CTL

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

Proceeding with operation
Changing database ID from 729333573 to 2473929266
Changing database name from DB_OLD to DB_NEW
Control File D:\ORACLE\ORADATA\DB102NEW\CONTROL01.CTL - modified
Control File D:\ORACLE\ORADATA\DB102NEW\CONTROL02.CTL - modified
Control File D:\ORACLE\ORADATA\DB102NEW\CONTROL03.CTL - modified

Datafile D:\ORACLE\ORADATA\DB102NEW\SYSTEM01.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\UNDOTBS01.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\SYSAUX01.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\USERS01.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\EXAMPLE01.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\TEST.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\TEMP01.DBF - dbid changed, wrote new name
Datafile D:\ORACLE\ORADATA\DB102NEW\TEMP011.DBF - dbid changed, wrote new name
Control File D:\ORACLE\ORADATA\DB102NEW\CONTROL01.CTL - dbid changed, wrote new name
Control File D:\ORACLE\ORADATA\DB102NEW\CONTROL02.CTL - dbid changed, wrote new name
Control File D:\ORACLE\ORADATA\DB102NEW\CONTROL03.CTL - dbid changed, wrote new name

Instance shut down

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

 

If validation is not successful, then DBNEWID terminates and leaves the target database intact, as shown in the following sample output. You can open the database, fix the error, and then either resume the DBNEWID operation or continue using the database without changing its DBID.


8. Change the DB_NAME in the pfile/spfile:
    Set the DB_NAME initialization parameter in the initialization parameter file (PFILE) to  the new   
    database name.

The NID utility does not change the server parameter file (SPFILE). Therefore, if you use SPFILE to start your Oracle database, you must re-create the initialization parameter file from the server parameter file, remove the server parameter file, change the DB_NAME in the initialization parameter file, and then re-create the server parameter file.


9. If you are using ASM and want to change the file name, follow this Article at this point

Note 564993.1 How to rename/move a datafile in the same ASM diskgroup



10. NID Utility will shutdown the database after the execution. So mount the database once again. 
    SQL> STARTUP MOUNT

11. Open the database in RESETLOGS mode: 
    SQL> ALTER DATABASE OPEN RESETLOGS;

Make a new database backup. Because you reset the online redo logs, the old backups and archived logs are no longer usable in the current incarnation of the database.


12. Recreate the password file since the DB NAME has been changed:

$ orapwd file=<fname> password=<password> entries=<users> force=<y/n> nosysdba=<y/n>

where
file - name of password file (mand),
password - password for SYS (mand),
entries - maximum number of distinct DBA,
force - whether to overwrite existing file (opt),
nosysdba - whether to shut out the SYSDBA logon (opt for Database Vault only).
Note: There are no spaces around the equal-to (=) character.

On Unix/Linux the passwordfile convention is : $ORACLE_HOME/dbs/orapw$ORACLE_SID
On MS Windows the passwordfile convention is : %ORACLE_HOME%\database\PWD%ORACLE_SID%.ORA


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

14. 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.
 
15. Change of Global Database Names:

If you are dealing with a database in a distributed database system, then each database should have a unique global database name. The DBNEWID utility does not change global database names. This can only be done with the SQL ALTER DATABASE statement, for which the syntax is as follows:

ALTER DATABASE RENAME GLOBAL_NAME TO <newname>.<domain>;


The global database name is made up of a database name and a domain, which are determined by the DB_NAME and DB_DOMAIN initialization parameters when the database is first created.

Windows specific steps:

16. Recreate the Database Service :

$ oradim -NEW -SID prod -STARTMODE auto -PFILE <....\initDB_NEW.ora>


17. Recreate the DB Console service : 

$ emca -config dbcontrol db -repos recreate

This command will ask you the new SID and will delete and recreate the service.


Refer to the following note for more information:
Note.278100.1 How To Drop, Create And Recreate DB Control In A 10g Database

Changing Only the Database ID

1-6 except 4. Follow the steps 1 to 6 (except step 4) given in above section.

7. Issue following command to invoke the NID utility:   

$ nid TARGET=SYS/password@DB_OLD

or

$ nid TARGET=SYS/password


8. NID Utility will shutdown the database after the execution. So mount the database once again. 
    SQL> STARTUP MOUNT

9. Open the database in RESETLOGS mode: 
    SQL> ALTER DATABASE OPEN RESETLOGS;

Make a new database backup. Because you reset the online redo logs, the old backups and archived logs are no longer usable in the current incarnation of the database.

 

Changing Only the Database Name

1-6. Follow the steps 1 to 6 given in first section.

7. Invoke the NID utility using following command
   You must specify both the DBNAME and SETNAME parameters.   

$ nid TARGET=SYS/password@test_db DBNAME=test_db SETNAME=YES

or

$ nid TARGET=SYS/password DBNAME=test_db SETNAME=YES


8. Change the DB_NAME in the pfile/spfile: Follow step 8 from the first section.

9. If you are using ASM and want to change the file name, follow this Article at this point

Note 564993.1 How to rename/move a datafile in the same ASM diskgroup



10. Start up the database in normal mode.
    SQL> STARTUP mount


11 - 16 Follow steps 11 to 16 given in the first section as applicable.

Logs for NID :

The operation performed by NID is recorded in the alert file:
For example:

*** DBNEWID utility started ***
DBNAME will be changed from PROD to new DBNAME of TEST_DB
Starting datafile conversion
Datafile conversion complete
Database name changed to TEST_DB.
Modify parameter file and generate a new password file before restarting.
Successfully changed database name.
*** DBNEWID utility finished successfully ***
posted @ 2018-12-21 10:22  魏暴富  阅读(897)  评论(0编辑  收藏  举报