Decode360's Blog

业精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

  BlogJava :: 首页 :: 新随笔 :: 联系 ::  :: 管理 ::
  397 随笔 :: 33 文章 :: 29 评论 :: 0 Trackbacks
修改DBNAME
 
 
    最近通过VMware硬盘的直接复制来创建结点,需要修改DBID和DBNAME(保证数据库环境可用),找了找可以用来直接修改DBNAME的方法,还真有,原来Oracle本身就自带了这个功能的工具(NID),用了一下发现使用还是比较方便的,但是更改之后问题多多,使用的最终结论还是:不到万不得已不推荐使用,因为DBID涉及到的关联很多,修改SID后会引发很多不可预知的错误,很多参数都任然沿用之间的%SID%,如果没有非常特殊的要求,还是保留datafile后,删除重建。讲一下 具体的操作过程:

一、NID的用法:
 
    这是Oracle自带的工具,数据库安装完成后就自动安装了。
C:\>nid
DBNEWID: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation.  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

用法举例:

1) 只修改DBID的用法 :
wangxiaoqi> nid TARGET=sys/sys

2) 修改DBID和DBNAME的用法:
wangxiaoqi> nid TARGET=sys/sys DBNAME=kaka02

3) 只修改DBNAME不改DBID的用法:
wangxiaoqi> nid TARGET=sys/sys DBNAME=kaka02 SETNAME=YES
 
4) 添加日志的用法
wangxiaoqi> nid TARGET=sys/sys DBNAME=kaka02 SETNAME=YES LOGFILE='D:\test\nid.log'
--理论上应该是这样的,但是这个测试没通过,根本不产生LOG
 
 
二、修改步骤:
 
1) 连接并修改DBNAME
 
SQL> conn sys/sys as sysdba
Connected.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
 
Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.
SQL> host nid target=sys/sys dbname=kaka02
DBNEWID: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
 
Connected to database KAKA (DBID=524574739)
 
Control Files in database:
    D:\ORACLE\ORADATA\KAKA\CONTROL01.CTL
    D:\ORACLE\ORADATA\KAKA\CONTROL02.CTL
    D:\ORACLE\ORADATA\KAKA\CONTROL03.CTL
 
Change database ID and database name KAKA to KAKA02? (Y/[N]) => y
 
Proceeding with operation
Changing database ID from 524574739 to 2420728802
Changing database name from KAKA to KAKA02
    Control File D:\ORACLE\ORADATA\KAKA\CONTROL01.CTL - modified
    Control File D:\ORACLE\ORADATA\KAKA\CONTROL02.CTL - modified
    Control File D:\ORACLE\ORADATA\KAKA\CONTROL03.CTL - modified
    Datafile D:\ORACLE\ORADATA\KAKA\SYSTEM01.DBF - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\KAKA\UNDOTBS01.DBF - dbid changed, wrote new name
    Control File D:\ORACLE\ORADATA\KAKA\CONTROL01.CTL - dbid changed, wrote new name
    Control File D:\ORACLE\ORADATA\KAKA\CONTROL02.CTL - dbid changed, wrote new name
    Control File D:\ORACLE\ORADATA\KAKA\CONTROL03.CTL - dbid changed, wrote new name
 
Database name changed to KAKA02.
Modify parameter file and generate a new password file before restarting.
Database ID for database KAKA02 changed to 2420728802.
All previous backups and archived redo logs for this database are unusable.
Shut down database and open with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

2) 修改db_name参数,重启数据库

SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.

  --在spfile文件里作相应修改,数据库db_name
SQL>startup mount;
SQL>alter system set db_name=kaka02 scope=spfile;
System altered.
  --如果是pfile文件,需手工修改db_name参数值

3) 重新创建密码文件

SQL>host orapwd file=c:\oracle\ora92\database\pwdkaka02.ora password=sys entries=8
SQL> conn
sys/sys as sysdba
Connected to an idle instance.

4) 以Resetlogs选项打开数据库

SQL> startup mount
ORACLE instance started.
 
Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.

SQL> alter database open resetlogs;

Database altered.

5) 查看修改是构成功

SQL> select dbid,name from v$database;

      DBID NAME
---------- ---------
2420728802 KAKA02

SQL>

注意:2、3不能颠倒,否则,重建口令文件是不可用的
 
 
三、注意修改监听
 
    发现在..\network\admin\listener.ora下直接添加SID修改不管用,监听起来的时候还是没有对新的DB进行监听。
 
    最后在图形界面下增加了新的SID后,重启lsnrctl,连接成功。
 
 
 
 
 
 
 
附:Tom对修改SID的建议和过程:
***************************************************
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:318216852435
***************************************************
 
 
 
 
posted on 2009-06-20 23:19 decode360 阅读(776) 评论(0)  编辑  收藏 所属分类: 10.DB_Tools

只有注册用户登录后才能发表评论。


网站导航: