技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> Oracle --> 使用nid更改数据库名

使用nid更改数据库名

浏览:1346次  出处信息

如果想更改数据库名,即修改db_name参数。在Oracle 9iR2提供了一个工具nid,可以通过它来完成这项工作,这样就避免了重建控制文件等繁琐方式来实现了。

nid工具可以只用来更改数据库名(db_name),或者只更改数据库的id(dbid),或者两个同时更改。

当涉及到更改db_name的时候,由于数据库名还存在与参数文件中,因此,更改数据库名时也要更改相应的参数。如果你使用了spfile,那么要重建它。另外,还需要重建密码文件。

有个nid工具的详细使用情况,在metalink 文章 Note:224266.1有详细的记载。

首先,我们来看看nid的使用帮助:

[oracle@testdbc oracle]$ nid

DBNEWID: Release 9.2.0.6.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

这里来解释一下几个问题:

(I):如果你只想更改数据库的id(dbid),那么你只需要指定target参数就可以了,具体的操作过程,请参考如下:

1. Backup the database

2. SHUTDOWN IMMEDIATE of the database

3. STARTUP MOUNT

4. Open one session and run NID with sysdba privileges

   % nid TARGET=SYS/password@test_db

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

(II):如果你想只更改数据库名(db_name),那么你需要设置SETNAME参数为Y,同时指定DBNAME参数,具体的操作过程,请参考如下:

1. Backup the database

2. SHUTDOWN IMMEDIATE of the database

3. STARTUP MOUNT

4. Open one session and run NID with sysdba privileges

   % nid TARGET=SYS/password@test_db DBNAME=test_db2 SETNAME=Y

   - the value of DBNAME is the new dbname of the database

   - SETNAME must be set to Y. The default is N and causes the

     DBID to be changed also.

5. 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(without resetlogs)

(III):如果你想同时更改数据库名(db_name)和数据库ID(dbid),那么你要指定DBNAME参数,同时设置SETNAME为N(其值默认也为N),具体操作过程,请参考如下:

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/password@test_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

(IV):如果你只更改了数据库名,而没有更改数据库id,那么你打开数据库就不需要open resetlogs了。

 

     下面是我自己做的一次操作,DBNAME和DBID同时更改。

1.数据库启动到mount状态

SQL> startup mount

ORACLE instance started.

total System Global Area  923904016 bytes

Fixed Size                   452624 bytes

Variable Size             385875968 bytes

Database Buffers          536870912 bytes

Redo Buffers                 704512 bytes

Database mounted.

2. 使用NID更改

[oracle@testdb2 dbs]$ nid target=sys/syspassword dbname=testdb2

DBNEWID: Release 9.2.0.6.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

Connected to database TESTDB1 (DBID=287286795)  -- 注意这里的数据库名和数据库id

Control Files in database:

    /cx300_testdb2/data1/control01.ctl

    /cx300_testdb2/data2/control02.ctl

    /cx300_testdb2/data3/control03.ctl

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

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
  • 作者:小霸王    来源: ilonng
  • 标签: nid
  • 发布时间:2009-10-12 10:10:41
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1