ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用NID修改数据库名称

用NID修改数据库名称

原创 Linux操作系统 作者:space6212 时间:2019-07-21 10:00:02 0 删除 编辑

NID是9iR2开始推出的一个命令行工具,它用来修改DB_NAME,DBID。你可以用此工具只修改DB_NAME或者DBID,也可以同时修改这两个东西。
NID的语法如下:


[oracle@standby admin]$ nid -help

DBNEWID: Release 10.2.0.3.0 - Production on Sat Jun 16 01:04:56 2007

Copyright (c) 1982, 2005, Oracle. 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 --Y表示同时修改DB_NAME和DBID,N表示只修改DB_NAME,默认是N
APPEND Append to output log NO
HELP Displays these messages NO


下面以一个例子来说明其用法:
1、首先把数据库启动到mount状态下
[oracle@standby oradata]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Jun 16 00:22:27 2007

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size 2072320 bytes
Variable Size 352321792 bytes
Database Buffers 838860800 bytes
Redo Buffers 14704640 bytes
Database mounted.
SQL>

2、使用nid命令修改db_name
[oracle@standby oradata]$ nid target=sys/systembak dbname=uplot logfile=~/nid.log

修改日志如下:
[oracle@standby oradata]$ more ~/nid.log

DBNEWID: Release 10.2.0.3.0 - Production on Sat Jun 16 00:28:50 2007

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

Connected to database ID5 (DBID=836265559)

Connected to server version 10.2.0

Control Files in database:
/opt/oracle/oradata/id5/control01.ctl
/opt/oracle/oradata/id5/control02.ctl
/opt/oracle/oradata/id5/control03.ctl

Changing database ID from 836265559 to 2052204354
Changing database name from ID5 to UPLOT
Control File /opt/oracle/oradata/id5/control01.ctl - modified
Control File /opt/oracle/oradata/id5/control02.ctl - modified
Control File /opt/oracle/oradata/id5/control03.ctl - modified
Datafile /opt/oracle/oradata/id5/system01.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/id5/undotbs01.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/id5/sysaux01.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/id5/users01.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/id5/temp01.dbf - dbid changed, wrote new name
Control File /opt/oracle/oradata/id5/control01.ctl - dbid changed, wrote new name
Control File /opt/oracle/oradata/id5/control02.ctl - dbid changed, wrote new name
Control File /opt/oracle/oradata/id5/control03.ctl - dbid changed, wrote new name
Instance shut down

Database name changed to UPLOT.
Modify parameter file and generate a new password file before restarting.
Database ID for database UPLOT changed to 2052204354.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.


3、重建密码文件

[oracle@standby oradata]$ orapwd file=/opt/oracle/product/10g/dbs/orapwduplot password=systembak entries=10


4、修改参数文件的db_name为新数据库名称,并用新参数文件启动
[oracle@standby oradata]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Jun 16 00:34:37 2007

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to an idle instance.

SQL> startup pfile='/opt/oracle/product/10g/dbs/inituplot.ora'
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size 2072320 bytes
Variable Size 352321792 bytes
Database Buffers 838860800 bytes
Redo Buffers 14704640 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

--修改DBID必须要resetlogs
SQL> alter database open resetlogs;

Database altered.

--检查修改成果
SQL> select dbid, name, open_mode, activation#, created from v$database;

DBID NAME OPEN_MODE ACTIVATION# CREATED
---------- ------------------ -------------------- ----------- ------------
2052204354 UPLOT READ WRITE 2052221623 14-JUN-07

--重建spfile
SQL> create spfile from pfile='/opt/oracle/product/10g/dbs/inituplot.ora';

File created.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size 2072320 bytes
Variable Size 352321792 bytes
Database Buffers 838860800 bytes
Redo Buffers 14704640 bytes
Database mounted.
Database opened.

此时,大功告成。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/231499/viewspace-63818/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2005-01-25

  • 博文量
    245
  • 访问量
    166218