设为首页 收藏本站
查看: 917|回复: 0

[经验分享] oracle工具之nid命令的使用

[复制链接]
YunVN网友  发表于 2018-9-13 10:38:59 |阅读模式
  当我们手动copy了整个数据库,并通过重建控制文件给数据库指定了新的dbname,但是却不能给数据库分配新的dbid.对于以上问题我们可以通过nid命令来对数据库分配一个全新的dbid。同时需要注意rman也是通过dbid来区分数据库。
  
  一 命令解释
  [oracle@source ~]$ nid  help=yes

  DBNEWID:>  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>
  Variable>  Database Buffers          318767104 bytes
  Redo Buffers                8921088 bytes
  Database mounted.
  SQL> exit

  Disconnected from Oracle Database 11g Enterprise Edition>  With the Partitioning, OLAP, Data Mining and Real Application Testing options
  [oracle@source ~]$ nid target=sys

  DBNEWID:>  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>  Proceeding with operation

  Changing database>  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>  All previous backups and archived redo logs for this database are unusable.
  Database has been shutdown, open database with RESETLOGS option.

  Succesfully changed database>  DBNEWID - Completed succesfully.
  [oracle@source ~]$ sqlplus / as sysdba

  SQL*Plus:>  Copyright (c) 1982, 2010, Oracle.  All rights reserved.

  Connected to an>  SQL> startup  mount;
  ORACLE instance started.
  Total System Global Area 1252663296 bytes

  Fixed>
  Variable>  Database Buffers          318767104 bytes
  Redo Buffers                8921088 bytes
  Database mounted.

  SQL>>
  Database>  SQL> select dbid,name from v$database;
  DBID NAME
  ---------- ---------
  3641774948 CRM
  eg2 :仅更改数据库db_name
  oracle@source ~]$ sqlplus / as sysdba

  SQL*Plus:>  Copyright (c) 1982, 2010, Oracle.  All rights reserved.
  Connected to:

  Oracle Database 11g Enterprise Edition>  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>
  Variable>  Database Buffers          335544320 bytes
  Redo Buffers                8921088 bytes
  Database mounted.
  SQL> exit

  Disconnected from Oracle Database 11g Enterprise Edition>  With the Partitioning, OLAP, Data Mining and Real Application Testing options
  oracle@source ~]$ nid target=sys dbname=CRM_TEST setname=YES

  DBNEWID:>  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:>  Copyright (c) 1982, 2010, Oracle.  All rights reserved.

  Connected to an>  SQL> startup nomount;
  ORACLE instance started.
  Total System Global Area 1252663296 bytes

  Fixed>
  Variable>  Database Buffers          335544320 bytes
  Redo Buffers                8921088 bytes

  SQL>>
  System>  [oracle@source ~]$orapwd file="$ORACLE_HOME/dbs/orapw$ORACLE_SID" password=dhhzdhhz force=y
  [oracle@source dbs]$ sqlplus / as sysdba

  SQL*Plus:>  Copyright (c) 1982, 2010, Oracle.  All rights reserved.
  Connected to:

  Oracle Database 11g Enterprise Edition>  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>
  Variable>  Database Buffers          335544320 bytes
  Redo Buffers                8921088 bytes
  Database mounted.
  Database opened.
  SQL> select dbid,name from v$database;
  DBID NAME
  ---------- ---------
  3641774948 CRM_TEST


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-577588-1-1.html 上篇帖子: oracle物理结构 -- 收获,不止oracle 下篇帖子: oracle 游标cursor-pl
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表