修改DBID和DBNAME

NID修改DBID和DBNAME

先查看,這個和我們之前的一樣

SQL> select name,dbid from v$database;

NAME                                                     DBID

-------------------------------------------------- ----------

ORCL                                               1275959622

NOTE

(1)在修改DBID期間仍然可能會遇到不可恢復的錯誤所以修改之前備份數據庫,特是控制文件因爲nid會修改控制文件中的信息。

(2)需要將DB啓動到mount狀態才能修改。

SQL> shutdown immediate

SQL> startup mount;


在執行NID命令之前:一定要關閉所有的session連接。


nid命令到執行的最後會關閉數據庫,如果有session連接,就會阻止這個操作,修改dbid就會被掛死。如果中斷這個操作,修改就會失敗,數據庫就不能mount,需要恢復。



(1)只改DBID,不改db_name


$ nid target=sys/Oracle



DBNEWID: Release 11.2.0.1.0 - Production on Mon Apr 11 22:27:49 2011



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



Connected to database ORCL (DBID=1275959622)



Connected to server version 11.2.0



Control Files in database:


   /u01/oradata/orcl/control01.ctl


   /u01/app/oracle/flash_recovery_area/orcl/control02.ctl



Change database ID of database ORCL? (Y/[N]) => Y



Proceeding with operation


Changing database ID from 1275959622 to 1276002278


   Control File /u01/oradata/orcl/control01.ctl - modified


   Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - modified


   Datafile /u01/oradata/orcl/system01.db - dbid changed


   Datafile /u01/oradata/orcl/sysaux01.db - dbid changed


   Datafile /u01/oradata/orcl/undotbs01.db - dbid changed


   Datafile /u01/oradata/orcl/users01.db - dbid changed


   Datafile /u01/oradata/orcl/example01.db - dbid changed


   Datafile /u01/oradata/orcl/temp01.db - dbid changed


   Control File /u01/oradata/orcl/control01.ctl - dbid changed


   Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - dbid changed


   Instance shut down



Database ID for database ORCL changed to 1276002278.


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 ID.


DBNEWID - Completed succesfully.



重啓打開數據庫:


$ sqlplus /nolog



SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 22:29:54 2011



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



SQL> conn /as sysdba


Connected to an idle instance.


SQL> startup


ORACLE instance started.



Total System Global Area 6847938560 bytes


Fixed Size                  2219808 bytes


Variable Size            353×××800 bytes


Database Buffers         3288334336 bytes


Redo Buffers               17391616 bytes


Database mounted.


ORA-01589: must use RESETLOGS or NORESETLOGS option for database open




SQL> alter database open resetlogs;



Database altered.



SQL> select name,dbid from v$database;



NAME            DBID


--------- ----------


ORCL      1276002278




(2)修改DBID和DB_NAME




注意一點,修改DB_NAME之前,要將spfile創建成pfile,因爲修改dbname之後,原來的參數文件就沒用了。所以要保證最新的參數。 還需要修改DB_NAME的值爲最新值。修改完之後,然後用這個新參數啓動DB.


SQL> create spfile from pfile='?/dbs/initorcl.ora';



File created.


SQL> create pfile='/u01/inittmp.ora' from spfile;



File created.


$ nid target=sys/oracle dbname=mahee



DBNEWID: Release 11.2.0.1.0 - Production on Mon Apr 11 22:38:15 2011



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



Connected to database ORCL (DBID=1276002278)



Connected to server version 11.2.0



Control Files in database:


   /u01/oradata/orcl/control01.ctl


   /u01/app/oracle/flash_recovery_area/orcl/control02.ctl



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



Proceeding with operation


Changing database ID from 1276002278 to 3475057431


Changing database name from ORCL to MAHEE


   Control File /u01/oradata/orcl/control01.ctl - modified


   Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - modified


   Datafile /u01/oradata/orcl/system01.db - dbid changed, wrote new name


   Datafile /u01/oradata/orcl/sysaux01.db - dbid changed, wrote new name


   Datafile /u01/oradata/orcl/undotbs01.db - dbid changed, wrote new name


   Datafile /u01/oradata/orcl/users01.db - dbid changed, wrote new name


   Datafile /u01/oradata/orcl/example01.db - dbid changed, wrote new name


   Datafile /u01/oradata/orcl/temp01.db - dbid changed, wrote new name


   Control File /u01/oradata/orcl/control01.ctl - dbid changed, wrote new name


   Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - dbid changed, wrote new name


   Instance shut down



Database name changed to MAHEE.


Modify parameter file and generate a new password file before restarting.


Database ID for database MAHEE changed to 3475057431.


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.




驗證:


首先,更改剛纔創建的那個inittmp.ora文件db_name爲mahee


$ export ORACLE_SID=mahee


$ sqlplus /nolog



SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 22:46:05 2011



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



SQL> conn /as sysdba


Connected to an idle instance.


SQL> startup mount pfile='/u01/inittmp.ora';


ORACLE instance started.



Total System Global Area 6847938560 bytes


Fixed Size                  2219808 bytes


Variable Size            353×××800 bytes


Database Buffers         3288334336 bytes


Redo Buffers               17391616 bytes


Database mounted.


SQL> alter database open resetlogs;



Database altered.



SQL> select name,dbid from v$database;



NAME            DBID


--------- ----------


MAHEE     3475057431



到此,實驗完成。


原文鏈接:http://www.linuxidc.com/Linux/2011-04/34524p6.htm


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章