当我们手动copy了整个数据库,并通过重建控制文件给数据库指定了新的dbname,但是却不能给数据库分配新的dbid.对于以上问题我们可以通过nid命令来对数据库分配一个全新的dbid。同时需要注意rman也是通过dbid来区分数据库。


一 命令解释

[oracle@source ~]$ nid  help=yes

DBNEWID: Release 11.2.0.2.0 - Production on Thu Dec 5 00:09:50 2013

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

Keyword     Description                    (Default)

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

TARGET      Username/Password              (NONE)    指定连接数据库的用户名和密码

DBNAME      New database name              (NONE)  DBNAME=new_db_name 改变数据库的名字

LOGFILE     Output Log                     (NONE) LOGFILE=logfile指定输出消息到指定的日志文件,默认nid覆盖之前的日子文件

REVERT      Revert failed change           NO  指定yes表明更改dbid失败时能够恢复之前的状态

SETNAME     Set a new database name only   NO  指定yes表明仅仅更改数据库db_name

APPEND      Append to output log           NO  指定yes标识输出追加到已经存在的日志文件

HELP        Displays these messages        NO  指定yes显示帮助信息

注意:可以同时更改数据库的dbid和db_name,也可以仅改变数据库的db_name、抑或仅更改数据库的dbid。语法分别如下:

改变dbid和db_name : nid target=sys/dhhzdhhz  dbname=crm_test (也可以target=/)

仅改变db_name:  nid target=sys/dhhzdhhz dbname=crm_test  setname=yes (也可以target=/)

仅更改dbid: nid target=sys/dhhzdhhz (也可以target=/)

二 使用nid的注意事项


1 确保有能够对数据库进行完全恢复的备份。

2 确保执行更改dbid操作时数据库处于mounted状态且mounted之前数据库是经过shutdown immediate关闭的。

3 使用nid更改数据库的dbid后,数据库需要alter database open resetlogs启动,启动之后须对数据库进行一次全备份,因为之前的备份和归档已经不能再使用了。

4 使用nid更改数据库dbname后,需更改初始化参数文件中的DB_NAME参数并重建密码文件。

5 使用nid不能更改全局数据库名。

6 确保所有数据文件处于online状态且不需要恢复。

7 尽量确保oracle没有离线的数据文件和只读表空间,如果有使其正常化。

三 举两个例子

eg1:仅更改数据库dbid

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 1252663296 bytes

Fixed Size                  2226072 bytes

Variable Size             922749032 bytes

Database Buffers          318767104 bytes

Redo Buffers                8921088 bytes

Database mounted.

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@source ~]$ nid target=sys

DBNEWID: Release 11.2.0.2.0 - Production on Wed Dec 4 23:39:11 2013

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

Password:

Connected to database CRM (DBID=3599153036)

Connected to server version 11.2.0

Control Files in database:

/oracle/CRM/control03.ctl

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

Proceeding with operation

Changing database ID from 3599153036 to 3641774948

Control File /oracle/CRM/control03.ctl - modified

Datafile /oracle/CRM/system01.db - dbid changed

Datafile /oracle/CRM/sysaux01.db - dbid changed

Datafile /oracle/CRM/zx.db - dbid changed

Datafile /oracle/CRM/users01.db - dbid changed

Datafile /oracle/CRM/pos.db - dbid changed

Datafile /oracle/CRM/erp.db - dbid changed

Datafile /oracle/CRM/user01.db - dbid changed

Datafile /oracle/CRM/undotbs03.db - dbid changed

Datafile /oracle/CRM/crm.db - dbid changed

Datafile /oracle/CRM/jxc.db - dbid changed

Datafile /oracle/CRM/temp01.db - dbid changed

Control File /oracle/CRM/control03.ctl - dbid changed

Instance shut down

Database ID for database CRM changed to 3641774948.

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open database with RESETLOGS option.

Succesfully changed database ID.

DBNEWID - Completed succesfully.

[oracle@source ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Wed Dec 4 23:47:21 2013

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

Connected to an idle instance.

SQL> startup  mount;

ORACLE instance started.

Total System Global Area 1252663296 bytes

Fixed Size                  2226072 bytes

Variable Size             922749032 bytes

Database Buffers          318767104 bytes

Redo Buffers                8921088 bytes

Database mounted.

SQL> alter database open resetlogs;

Database altered.

SQL> select dbid,name from v$database;

DBID NAME

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

3641774948 CRM

eg2 :仅更改数据库db_name

oracle@source ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Thu Dec 5 00:11:03 2013

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select open_mode from v$database;

OPEN_MODE

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

READ WRITE

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 1252663296 bytes

Fixed Size                  2226072 bytes

Variable Size             905971816 bytes

Database Buffers          335544320 bytes

Redo Buffers                8921088 bytes

Database mounted.

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

oracle@source ~]$ nid target=sys dbname=CRM_TEST setname=YES

DBNEWID: Release 11.2.0.2.0 - Production on Thu Dec 5 00:24:58 2013

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

Password:

Connected to database CRM (DBID=3641774948)

Connected to server version 11.2.0

Control Files in database:

/oracle/CRM/control03.ctl

Change database name of database CRM to CRM_TEST? (Y/[N]) => y

Proceeding with operation

Changing database name from CRM to CRM_TEST

Control File /oracle/CRM/control03.ctl - modified

Datafile /oracle/CRM/system01.db - wrote new name

Datafile /oracle/CRM/sysaux01.db - wrote new name

Datafile /oracle/CRM/zx.db - wrote new name

Datafile /oracle/CRM/users01.db - wrote new name

Datafile /oracle/CRM/pos.db - wrote new name

Datafile /oracle/CRM/erp.db - wrote new name

Datafile /oracle/CRM/user01.db - wrote new name

Datafile /oracle/CRM/undotbs03.db - wrote new name

Datafile /oracle/CRM/crm.db - wrote new name

Datafile /oracle/CRM/jxc.db - wrote new name

Datafile /oracle/CRM/temp01.db - wrote new name

Control File /oracle/CRM/control03.ctl - wrote new name

Instance shut down

Database name changed to CRM_TEST.

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

Succesfully changed database name.

DBNEWID - Completed succesfully.

[oracle@source ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Thu Dec 5 00:25:33 2013

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

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 1252663296 bytes

Fixed Size                  2226072 bytes

Variable Size             905971816 bytes

Database Buffers          335544320 bytes

Redo Buffers                8921088 bytes

SQL> alter system set db_name=CRM_TEST scope=spfile;

System altered.

[oracle@source ~]$orapwd file="$ORACLE_HOME/dbs/orapw$ORACLE_SID" password=dhhzdhhz force=y

[oracle@source dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Thu Dec 5 00:34:40 2013

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> startup force open;

ORACLE instance started.

Total System Global Area 1252663296 bytes

Fixed Size                  2226072 bytes

Variable Size             905971816 bytes

Database Buffers          335544320 bytes

Redo Buffers                8921088 bytes

Database mounted.

Database opened.

SQL> select dbid,name from v$database;

DBID NAME

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

3641774948 CRM_TEST

本文转自 zhangxuwl 51CTO博客,原文链接:http://blog.51cto.com/jiujian/1336559,如需转载请自行联系原作者

oracle工具之nid命令的使用相关推荐

  1. oracle11g nid,Oracle工具之nid命令的使用

    当我们手动copy了整个数据库,并通过重建控制文件给数据库指定了新的dbname,但是却不能给数据库分配新的dbid.对于以上问题我们可以通过nid命令来对数据库分配一个全新的dbid.同时需要注意r ...

  2. Oracle 数据库相关主题:用户、权限、常用管理工具、常用命令

    1. Oracle数据库中SYS.SYSTEM.DBSNMP.SYSMAN 四种用户有什么区别? SYS用户(超级管理员):sys用户具有"SYSDBA"或者"SYSOP ...

  3. Oracle rac使用nid和dbms_backup_restore包修改dbid和dbname

    Oracle rac使用nid和dbms_backup_restore包修改dbid和dbname 之前的连接: http://blog.itpub.net/26736162/viewspace-21 ...

  4. Oracle 常用运维命令整理

    一.oracle建库与删库命令 (1)oracle11g建库(一般习惯配置gdbname与sid名一样,sys密码与system密码一样,以方便记忆) [oracledb@ ~]$ dbca -sil ...

  5. Navicat for Oracle工具连接oracle

    为什么80%的码农都做不了架构师?>>>    这个工具可以用于任何版本 8i 或以上的 Oracle 数据库服务器,并支持大部份 Oracle 最新版本的功能,包括目录.表空间.同 ...

  6. 【分享】Oracle 常用运维命令大全

    教材下载 ORACLE OCP 19C 官方电子教材 ORACLE OCP 12C官方电子教材 课程介绍 DBA数据库管理必备认证:ORACLE OCP 19C Oracle 常用运维命令大全 一.o ...

  7. access转换成oracle,Access转Oracle工具

    iefans下载为用户提供的AccessToOracle是一款特色鲜明的Access转Oracle工具,这款软件不仅可以帮助用户将Access数据转换成Oracle数据,还能快速的导入出Oracle数 ...

  8. oracle+挂载dbf,dbf导入oracle工具下载|OracleToDbf(dbf导入oracle工具) v1.2官方版 附教程_星星软件园...

    OracleToDbf是一款好用的dbf导入oracle工具,该工具操作简单,只需要几个简单的步骤,就可以完成导入导出操作,它还拥有提供重复操作.查询导出.自动导出等实用功能,为您节约大量的时间,具有 ...

  9. Oracle 工具权限二

    SQL Plus工具: 在命令行中输入sqlplusw,启动该工具 连接数据库:conn sys/system as sysdba; PL/SQL Developer工具: 在Oracle开发中,经常 ...

最新文章

  1. 设计一个简单的空间配置器
  2. 笔记本8G+256G固态免费送,吃鸡不吃力,包邮!
  3. sqlserver中GUID的默认值设置
  4. 为什么你设计的网页不够惊艳?
  5. 【金融】【python】CAPM实证分析
  6. 详解:知乎如何使用机器学习,未来还有哪些想象空间
  7. 超级账本 --- ReadWriteSet的逻辑结构
  8. 基于CSS+dIV的网页层,点击后隐藏或显示
  9. JSP面试题都在这里 1
  10. B站视频下载:如何下载B站视频到电脑上
  11. Java针对不同文件加水印
  12. 谷物割捆一体农用车系统整体设计
  13. echart中饼图如何显示数据 实现鼠标移动切换显示(vue中)
  14. dell服务器驱动安装安装系统安装,dellR720服务器安装系统win server2012X64方法
  15. R: 每年发表基因简单分析
  16. 游戏开发经验之开源游戏盈利的十个有效途径
  17. 如何使用Foobar2000将音乐文件按照专辑或者歌手名分出文件夹
  18. PTC Mathcad Prime7.0,简单易用的用户界面
  19. 34岁的我,重拾编程
  20. ThoughtWorks给你不一样的入职之旅

热门文章

  1. mysql创建表时加入时间格式
  2. T8服务器怎么重装系统,美图 T8手机如何重装系统、手机系统怎样重装?
  3. AD软件制手工板导出元器件流水号
  4. 微信小程序与webview关于iphone X的兼容设置
  5. 微信小程序自定义组件-城市选择
  6. 微信小程序中的省市区选择器
  7. 苹果发布iOS 14.2正式版
  8. 搭建 Hexo 个人博客和 Matery 主题的配置优化
  9. oracle 年月相减求月数,oracle 时间相减,月度相加减
  10. 金融知识国民读本学习