【原創】使用nid命令修改資料庫名稱
nid是Oracle用來更改資料庫名稱的自帶工具.它可以直接修改資料庫名稱,而無需通過以前需要重建控制檔案的方法來改變.
nid命令的使用方法如下:
C:\WINDOWS>nid
DBNEWID: Release 10.2.0.1.0 - Production on Thu May 22 21:56:48 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Keyword Description (Default)
----------------------------------------------------
TARGET Username/Password (NONE)
DBNAME New database name (NONE)
LOGFILE Output Log (NONE)
REVERT Revert failed change NO
SETNAME Set a new database name only NO
APPEND Append to output log NO
HELP Displays these messages NO
下面是使用nid修改資料名稱的庫實驗:
實驗環境:WinXP SP2
資料庫版本:10.2.0.1
注:其中有些步驟可能是不需要的,主要是為了說明nid執行的兩個條件:
1、資料庫必須處於mount狀態
2、所有的資料檔案不能處於disabled狀態
具體實驗步驟:
1.使用nid將資料庫名稱由test改為t,但是提示錯誤:資料庫不能處於open的狀態
C:\WINDOWS>nid target=sys/test@test dbname=t
DBNEWID: Release 10.2.0.1.0 - Production on Thu May 22 21:58:33 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to database TEST (DBID=1946053558)
NID-00121: Database should not be open
Change of database name failed during validation - database is intact.
DBNEWID - Completed with validation errors.
2.關閉資料庫,並啟動到mount狀態
sys@TEST>shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TEST>startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1248504 bytes
Variable Size 134218504 bytes
Database Buffers 125829120 bytes
Redo Buffers 7139328 bytes
Database mounted.
3.再次執行nid命令,又報了錯,說有資料檔案處於disabled的狀態
C:\WINDOWS>nid target=sys/test@test dbname=t
DBNEWID: Release 10.2.0.1.0 - Production on Thu May 22 22:01:29 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to database TEST (DBID=1946053558)
Connected to server version 10.2.0
Control Files in database:
+TEST/test/control01.ctl
+TEST/test/control02.ctl
The following datafiles are disabled:
F:\ORACLE\PRODUCT\ORADATA\TEST\TEST01.DBF (8)
NID-00125: Database should have no disabled datafiles
Change of database name failed during validation - database is intact.
DBNEWID - Completed with validation errors.
4.檢視資料檔案的狀態,果然有檔案處於disabled的狀態
sys@TEST>select file#,enabled from v$datafile;
FILE# ENABLED
---------- ----------
1 READ WRITE
2 READ WRITE
3 READ WRITE
4 READ WRITE
5 READ WRITE
6 READ WRITE
7 READ WRITE
8 DISABLED
9 DISABLED
10 READ WRITE
11 READ WRITE
12 READ WRITE
12 rows selected.
5.將資料庫open
sys@TEST>alter database open;
Database altered.
6.發現原來是有兩個表空間offline了
sys@TEST>select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
UNDOTBS1 ONLINE
SYSAUX ONLINE
TEMP ONLINE
USERS ONLINE
TEST_BIG ONLINE
MGMT_TABLESPACE ONLINE
MGMT_ECM_DEPOT_TS ONLINE
TEST OFFLINE
TEST1 OFFLINE
UNDO01 ONLINE
UNDO02 ONLINE
TEST03 ONLINE
13 rows selected.
7.將這兩個表空間online
sys@TEST>alter tablespace test1 online;
Tablespace altered.
sys@TEST>alter tablespace test online;
Tablespace altered.
8.再次檢視,所有資料檔案的狀態都是READ WRITE的
sys@TEST>select file#,enabled from v$datafile;
FILE# ENABLED
---------- ----------
1 READ WRITE
2 READ WRITE
3 READ WRITE
4 READ WRITE
5 READ WRITE
6 READ WRITE
7 READ WRITE
8 READ WRITE
9 READ WRITE
10 READ WRITE
11 READ WRITE
12 READ WRITE
12 rows selected.
9.再次關閉資料庫,並啟動到mount狀態
sys@TEST>shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TEST>startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1248504 bytes
Variable Size 134218504 bytes
Database Buffers 125829120 bytes
Redo Buffers 7139328 bytes
Database mounted.
10.執行nid命令,這次執行成功了,可以看到資料庫id改變了,由1946053558變成544433466,這就意味著原來的備份和歸檔日誌都不能再使用了
C:\WINDOWS>nid target=sys/test@test dbname=t
DBNEWID: Release 10.2.0.1.0 - Production on Thu May 22 22:14:16 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to database TEST (DBID=1946053558)
Connected to server version 10.2.0
Control Files in database:
+TEST/test/control01.ctl
+TEST/test/control02.ctl
Change database ID and database name TEST to T? (Y/[N]) => y
Proceeding with operation
Changing database ID from 1946053558 to 544433466
Changing database name from TEST to T
Control File +TEST/test/control01.ctl - modified
Control File +TEST/test/control02.ctl - modified
Datafile +TEST/test/datafile/system.258.650496175 - dbid changed, wrote new name
Datafile +TEST/test/datafile/undotbs1.259.650496245 - dbid changed, wrote new name
Datafile +TEST/test/datafile/sysaux.257.650496219 - dbid changed, wrote new name
Datafile +TEST/test/datafile/users.260.650496247 - dbid changed, wrote new name
Datafile +TEST/test/datafile/test_big.262.650496255 - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\MGMT.DBF - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\MGMT_ECM_DEPOT1.DBF - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\TEST01.DBF - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\TEST02.DBF - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\UNDO01.DBF - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\UNDO02.DBF - dbid changed, wrote new name
Datafile F:\ORACLE\PRODUCT\ORADATA\TEST\TEST03.DBF - dbid changed, wrote new name
Datafile +TEST/temp01.dbf - dbid changed, wrote new name
Control File +TEST/test/control01.ctl - dbid changed, wrote new name
Control File +TEST/test/control02.ctl - dbid changed, wrote new name
Instance shut down
Database name changed to T.
Modify parameter file and generate a new password file before restarting.
Database ID for database T changed to 544433466.
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.
11.關閉資料庫
sys@TEST>shut immediate
ORA-01507: database not mounted
ORACLE instance shut down.
12.重新啟動資料庫,在從nomount狀態啟動至mount狀態時報錯,這是因為控制檔案中的資料庫名稱已經改成t了,但引數檔案中的db_name仍然是test,所以報錯了
idle>startup
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1248504 bytes
Variable Size 125829896 bytes
Database Buffers 134217728 bytes
Redo Buffers 7139328 bytes
ORA-01103: database name 'T' in control file is not 'TEST'
13.檢視引數檔案中的db_name設定
idle>show parameter name
NAME TYPE VALUE
------------------------------------ ---------------------- --------------------------
db_file_name_convert string
db_name string test
db_unique_name string test
global_names boolean FALSE
instance_name string test
lock_name_space string
log_file_name_convert string
service_names string test
14.修改引數檔案中的db_name引數,並重啟資料庫
idle>alter system set db_name='t' scope=spfile;
System altered.
idle>shut immediate
ORA-01507: database not mounted
ORACLE instance shut down.
idle>startup
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1248504 bytes
Variable Size 125829896 bytes
Database Buffers 134217728 bytes
Redo Buffers 7139328 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
15.由於資料庫的id變化了,需要以resetlogs的方式啟動資料庫
idle>alter database open resetlogs;
Database altered.
16.到此資料庫的名稱修改完畢
idle>show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string t
db_unique_name string test
global_names boolean FALSE
instance_name string test
lock_name_space string
log_file_name_convert string
service_names string t
17.重建密碼檔案,進行資料庫備份,這裡就不詳述了
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/498744/viewspace-293561/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- nid修改資料庫名稱資料庫
- 用NID修改資料庫名稱資料庫
- 在RAC中用NID修改資料庫名稱資料庫
- 使用NID修改Oracle資料庫名Oracle資料庫
- Oracle NID工具修改資料庫DBID和資料庫名稱Oracle資料庫
- NID修改資料庫名稱時候碰到NID-00137資料庫
- 修改資料庫名稱資料庫
- [轉] 使用NID 修改資料庫名(Oracle9或以上)資料庫Oracle
- 如何修改MySQL資料庫名稱MySql資料庫
- SQL Server還原資料庫,修改還原後的物理檔名稱SQLServer資料庫
- 二、修改資料庫全域性名稱資料庫
- 使用mmv命令批次修改檔名稱
- Oracle 11g修改資料庫使用者名稱Oracle資料庫
- Oracle 11g支援修改資料庫使用者名稱Oracle資料庫
- nid 改變資料庫名,DBID資料庫
- ***批次修改資料夾名稱
- 在Linux中使用mmv命令批量修改檔名稱Linux
- 關於修改資料庫名稱和ID的方法總結資料庫
- win10修改使用者名稱資料夾方法 win10怎麼改使用者資料夾名稱Win10
- C#取資料庫名稱與資料庫中表名的方法C#資料庫
- win10怎麼更改使用者名稱資料夾_win10如何修改suers使用者名稱資料夾Win10
- 查詢當前資料庫名、使用者名稱、資料庫伺服器IP、埠、資料庫版本資訊。資料庫伺服器
- 如何修改資料庫例項及資料庫名資料庫
- ORACLE資料庫修改資料庫名db_nameOracle資料庫
- github修改使用者名稱Github
- 快速修改Oracle使用者名稱Oracle
- 關於資料庫登陸名和資料庫使用者名稱的一點點心得資料庫
- 修改git遠端倉庫分支名稱Git
- Postgresql10資料庫之更改資料庫的名稱SQL資料庫
- 資料庫 校驗名稱唯一性,用於新增和修改功能資料庫
- SQL資料庫使用者只有“名稱”而無“登陸名”解決SQL資料庫
- mongodb對資料庫建立使用者名稱和密碼MongoDB資料庫密碼
- Git修改檔名稱Git
- 2.6.2 確定全域性資料庫名稱資料庫
- mongodb怎樣給本地資料庫新增使用者名稱密碼和修改賬號密碼?MongoDB資料庫密碼
- 使用“基表修改法”快速修改Oracle使用者名稱(z)Oracle
- 【USER】使用“基表修改法”快速修改Oracle使用者名稱Oracle
- 使用ALTER修改資料庫資料庫