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