Oracle 修改DB_NAME 和 DBID
一. 相關概念
關於DB_NAME,INSTANCE_NAME 的定義,參考我的Blog:
DBID,SID,DB_NAME,DB_DOMAIN,INSTANCE_NAME,DB_UNIQUE_NAME,SERVICE_NAMES 及監聽引數的說明
關於NID命令的使用,參考Blog:
How to Change the DBID and the DBNAME by using NID [ID 224266.1]
在這篇blog裡提到了一下資訊:
The NID (New Database ID)is a new utility introduced with Oracle 9.2.The NID utility allows you to change only the DBNAME, or only the DBID or both DBNAME and DBID in the same command.
-- 我們可以使用NID 命令只修改DBNAME,或者只修改DBID,或者2個都修改。
他們的區別如下:
1. If you change the DBID you must open the database with the RESETLOGSoption, which re-creates the online redo logs and resets their sequence to 1.
--
修改DBID,必須要用resetlogs
開啟資料庫。
這個在之前的DBID 的介紹裡說過,因為DBID
存在與資料檔案,redo log
和控制檔案。 所以如果修改了DBID,
2. If you change the DBNAME without changing the DBID then this does not require you to open with the RESETLOGS option, so database backups and
archived logs are not invalidated.
You must change the DB_NAME initialization parameter after a database name change to reflect the new name
關於NID 修改DBID 和DBNAME的具體3種用法,參考之前的那片文章。
在這裡還有一點要注意,就是orapwSID 和 initSID.ora 是和INSTANCE_NAME 對應的,如果這個引數修改了,那麼這2個檔案也需要修改並與INSTANCE_NAME 對應。修改這個引數也很簡單,就是在init 檔案裡指定一個名稱即可,如:*.INSTANCE_NAME=orcl
二. 修改DBID,DBNAME步驟
在這裡,只演示一下修改DBID 和 DBNAME的操作。 並不修改INSTANE_NAME.
步驟如下:
1. Backup of the database.
2. Shutdown IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/[email protected]_db DBNAME=test_db2
- the value of DBNAME is the new dbname of the database
5. After DBNEWID successfully changes the DBID,Shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter file to the new database name.
7. Create a new password file.
8. Startup of the database with open resetlogs
在修改之前,先看一下資料庫的引數:
SQL> select name,dbid,db_unique_name from v$database;
NAMEDBID DB_UNIQUE_NAME
--------- ---------- ------------------------------
ORCL1264931370 orcl
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
orcl
2.1 shutdown database
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
2.2Startup mount
SQL> startup mount;
ORACLE instance started.
Total System Global Area360710144 bytes
Fixed Size1219424 bytes
Variable Size109053088 bytes
Database Buffers247463936 bytes
Redo Buffers2973696 bytes
Database mounted.
2.3 Run NID command
[[email protected] bdump]$ nid
DBNEWID: Release 10.2.0.1.0 - Production on Mon Dec 20 14:26:13 2010
Copyright (c) 1982, 2005, Oracle.All rights reserved.
KeywordDescription(Default)
----------------------------------------------------
TARGETUsername/Password(NONE)
DBNAMENew database name(NONE)
LOGFILEOutput Log(NONE)
REVERTRevert failed changeNO
SETNAMESet a new database name onlyNO
APPENDAppend to output logNO
HELPDisplays these messagesNO
[[email protected] bdump]$ nid target=/ dbname=dave
DBNEWID: Release 10.2.0.1.0 - Production on Mon Dec 20 14:27:13 2010
Copyright (c) 1982, 2005, Oracle.All rights reserved.
Connected to database ORCL (DBID=1264931370)
Connected to server version 10.2.0
Control Files in database:
/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/oradata/orcl/control02.ctl
/u01/app/oracle/oradata/orcl/control03.ctl
Change database ID and database name ORCL to DAVE? (Y/[N]) => Y--手工輸入
Proceeding with operation
Changing database ID from 1264931370 to 801102850
Changing database name from ORCL to DAVE
Control File /u01/app/oracle/oradata/orcl/control01.ctl - modified
Control File /u01/app/oracle/oradata/orcl/control02.ctl - modified
Control File /u01/app/oracle/oradata/orcl/control03.ctl - modified
Datafile /u01/app/oracle/oradata/orcl/system.256.736598559 - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/orcl/undotbs1.258.736598599 - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/orcl/sysaux.257.736598563 - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/orcl/users.259.736598641 - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/orcl/temp.263.736599505 - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/orcl/temp01.dbf - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/orcl/control01.ctl - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/orcl/control02.ctl - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/orcl/control03.ctl - dbid changed, wrote new name
Instance shut down
Database name changed to DAVE.
Modify parameter file and generate a new password file before restarting.
Database ID for database DAVE changed to 801102850.
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.
[[email protected] bdump]$
2.4 修改PFILE 裡的DB_NAME引數
[[email protected] dbs]$ cat initorcl.ora
...
*.db_name='dave'
...
2.5 用pfile啟動資料庫,並用resetlogs 開啟
SQL> startup mount pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora';
ORACLE instance started.
Total System Global Area360710144 bytes
Fixed Size1219424 bytes
Variable Size109053088 bytes
Database Buffers247463936 bytes
Redo Buffers2973696 bytes
Database mounted.
SQL> alter database open resetlogs;
Database altered.
2.7 檢視修改之後的資訊
SQL>select name,dbid,db_unique_name from v$database;
NAMEDBID DB_UNIQUE_NAME
--------- ---------- ------------------------------
DAVE801102850 dave
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
orcl
SQL>
在這裡看到, db_name 和DBID 都修改了,但是instance_name 沒有修改。 在官網的文件裡提到了重建密碼檔案,因為我的instance_name沒有修改,所以我沒有進行重建。
------------------------------------------------------------------------------
QQ:492913789
Email:[email protected]
網上資源: http://tianlesoftware.download.csdn.net
相關視訊:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
DBA1 群:62697716(滿); DBA2 群:62697977(滿)
DBA3 群:62697850DBA 超級群:63306533;
聊天 群:40132017
--加群需要在備註說明Oracle表空間和資料檔案的關係,否則拒絕申請