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.1How 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:Release10.2.0.4.0-ProductiononMonJul2718:29:062009
Copyright(c)1982,2007,Oracle.Allrightsreserved.
ConnectedtodatabaseTSTNID2(DBID=729333573)
Connectedtoserverversion10.2.0
ControlFilesindatabase:
D:ORACLEORADATADB102NEWCONTROL01.CTL
D:ORACLEORADATADB102NEWCONTROL02.CTL
D:ORACLEORADATADB102NEWCONTROL03.CTL
ChangedatabaseIDanddatabasenameTSTNID2toTSTNID3?(Y/[N])=>Y
Proceedingwithoperation
ChangingdatabaseIDfrom729333573to2473929266
Changingdatabasenamefrom DB_OLD to DB_NEW
ControlFileD:ORACLEORADATADB102NEWCONTROL01.CTL-modified
ControlFileD:ORACLEORADATADB102NEWCONTROL02.CTL-modified
ControlFileD:ORACLEORADATADB102NEWCONTROL03.CTL-modified
DatafileD:ORACLEORADATADB102NEWSYSTEM01.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWUNDOTBS01.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWSYSAUX01.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWUSERS01.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWEXAMPLE01.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWTEST.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWTEMP01.DBF-dbidchanged,wrotenewname
DatafileD:ORACLEORADATADB102NEWTEMP011.DBF-dbidchanged,wrotenewname
ControlFileD:ORACLEORADATADB102NEWCONTROL01.CTL-dbidchanged,wrotenewname
ControlFileD:ORACLEORADATADB102NEWCONTROL02.CTL-dbidchanged,wrotenewname
ControlFileD:ORACLEORADATADB102NEWCONTROL03.CTL-dbidchanged,wrotenewname
Instanceshutdown
Databasenamechangedto DB_NEW.
Modifyparameterfileandgenerateanewpasswordfilebeforerestarting.
DatabaseIDfordatabase DB_NEW changedto2473929266.
Allpreviousbackupsandarchivedredologsforthisdatabaseareunusable.
DatabaseisnotawareofpreviousbackupsandarchivedlogsinRecoveryArea.
Databasehasbeenshutdown,opendatabasewithRESETLOGSoption.
SuccesfullychangeddatabasenameandID.
DBNEWID-Completedsuccesfully.
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.1How 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%databasePWD%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.1How 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.1How 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 ***
總結
以上是生活随笔為你收集整理的Oracle 使用Nid 修改数据库的DBID 和 Database Name的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MCMC:Markov Chain&am
- 下一篇: 央行无意放宽松,7月贷款仍有可能吃紧