oracle工具之nid命令的使用

本文涉及的产品
云原生数据仓库AnalyticDB MySQL版,基础版 8ACU 100GB 1个月
简介:

   当我们手动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,如需转载请自行联系原作者
相关实践学习
AnalyticDB MySQL海量数据秒级分析体验
快速上手AnalyticDB MySQL,玩转SQL开发等功能!本教程介绍如何在AnalyticDB MySQL中,一键加载内置数据集,并基于自动生成的查询脚本,运行复杂查询语句,秒级生成查询结果。
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
目录
相关文章
|
5月前
|
运维 Oracle 前端开发
Oracle 11g RAC集群日常运维命令总结
Oracle 11g RAC集群日常运维命令总结
117 2
|
5月前
|
SQL 运维 Oracle
入门级Oracle 11g日常运维命令总结
入门级Oracle 11g日常运维命令总结
191 1
|
6月前
|
SQL Oracle 关系型数据库
关系型数据库Oracle备份工具
【7月更文挑战第19天】
93 4
|
6月前
|
Oracle 关系型数据库 Java
Oracle数据库导入工具IMP详解与用法
Oracle数据库导入工具IMP详解与用法
|
7月前
|
SQL Oracle 关系型数据库
探索 Linux 命令 `db_archive`:Oracle 数据库归档日志的工具
探索 Linux 中的 `db_archive`,实际与 Oracle 数据库归档日志管理相关。在 Oracle 中,归档日志用于恢复,当在线重做日志满时自动归档。管理员可使用 SQL*Plus 查看归档模式,通过 `RMAN` 进行备份和恢复操作。管理归档日志需谨慎,避免数据丢失。了解归档管理对 Oracle 管理员至关重要,确保故障时能快速恢复数据库。
|
7月前
|
Oracle 关系型数据库 Java
Oracle数据库导入工具IMP详解与用法
Oracle数据库导入工具IMP详解与用法
|
8月前
|
SQL Oracle 关系型数据库
Oracle spool格式化数据命令
在这个示例中,通过设置不同的 `SET`命令参数,你可以控制输出的格式,包括每页行数、每行字符数、列分隔符等。你也可以使用其他的 `SET`命令参数来进一步定制输出格式。
82 0
|
8月前
|
SQL Oracle 关系型数据库
Oracle SQL*Plus的TTITLE和BTITLE命令:为你的数据报告加上精美的“画框”
【4月更文挑战第19天】`SQL*Plus`的`TTITLE`和`BTITLE`命令用于为数据报告添加吸引人的标题和边框。
|
8月前
|
SQL Oracle 关系型数据库
Oracle SQL*Plus的COLUMN命令:数据展示的“化妆师”
【4月更文挑战第19天】Oracle SQL*Plus的COLUMN命令是数据展示的利器,能美化和格式化输出。它可定制列标题、调整显示格式(如数字的小数位数和日期格式),添加前缀和后缀(如货币符号),以及控制列宽和是否折行,使得数据呈现更直观、专业。利用COLUMN命令,能将原始数据转化为易于理解和视觉吸引力强的展示形式。
|
8月前
|
SQL Oracle 关系型数据库
Oracle SQL*Plus的SPOOL命令:数据库世界的“录像机”
【4月更文挑战第19天】`SQL*Plus`的`SPOOL`命令是Oracle数据库中的“录像机”,能记录所有操作和输出。它在用户开始“SPOOL ON”时启动,记录SQL查询、输出、错误信息等。完成后,“SPOOL OFF”停止记录并生成日志文件,便于回顾和检查。日志文件可自定义保存位置和命名,支持多文件录制,方便分类管理。无论数据分析、SQL脚本编写还是日常维护,`SPOOL`都是强大的工具,值得一试!

相关实验场景

更多

推荐镜像

更多