用NID修改資料庫名稱

space6212發表於2019-07-21

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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章