IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

使用nid更改数据库名

ilonng 2009-10-12 10:10:41 累计浏览 2,421 次
本机暂存

如果想更改数据库名,即修改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

同分类推荐文章

  1. 使用deepseek进行Oracle恢复,引起重大故障 (2026-06-22 10:56:00)
  2. 接手一个只差临门一脚的数据库恢复 (2026-06-18 00:13:09)
  3. 我做了一个 AI 版的 StarRocks 升级风险扫描工具,直接帮我定位到一个风险 (2026-06-15 01:00:00)

查看更多 数据库 文章 →

建议继续学习

  1. Oracle MTS模式下 进程地址与会话信息 (累计阅读 14,406)
  2. 那些在11gR2中可能惹祸的新特性,一张列表帮助你摆脱升级11gR2带来的烦恼 (累计阅读 6,878)
  3. 性能测试工具sysbench简介 (累计阅读 6,026)
  4. 大于2GB的Listener.log和运行超过198天的主机上的Oracle实例 (累计阅读 5,861)
  5. 仅仅只备份是不够的 (累计阅读 5,823)
  6. Oracle Database 12c 新特性 - Native Top N 查询 (累计阅读 5,750)
  7. ORACLE最大可以存储多少数据量 (累计阅读 5,726)
  8. Oracle DBA的学习进阶成长树-从初出茅庐到高瞻远瞩 (累计阅读 5,600)
  9. 老托的Oracle 数据库Patch概念性小常识 (累计阅读 5,547)
  10. 查看oracle数据库用户下的所有空表 (累计阅读 5,502)