今天有需求要改DBID,试了下NEWDBID,还是很方便的。
平时我们用RMAN或者物理备份恢复一个数据库到新的机器上时,数据库的DBID还是与原来相同的。而RMAN是根据DBID来维护备份集信息的,特别是当使用catalog时,就更需要更改新库的DBID了。这个时候 NEWDBID就派上用场了。
NEWDBID除了可以更改DBID,还可以更改DBNAME。
注意:更改dbid后,需要以resetlogs模式打开数据库,原来的备份,归档日志都不能在新的dbid库上使用了。
更改DBID的主要步骤:
1. 切换数据库到mount模式
2. 调用NEWDBID(命令为nid)去更改DBID, nid会提示你是否要继续。在你确认后,nid更改数据文件dbid, 并关闭数据库。
3. 启动数据库到mount,再以resetlogs方式打开数据库。
4. 记录新的DBID.
具体参数:
$> nid help=y
DBNEWID: Release 10.2.0.1.0 - Production on Tue Aug 10 04:36:59 2010
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
APPEND Append to output log NO
HELP Displays these messages NO样例:[@more@]
oracer> select dbid from v$database;
DBID
----------
2717013816 ===》 旧的dbid
重启数据库到mount状态
$>nid target=sys/syspass
DBNEWID: Release 10.2.0.1.0 - Production on Tue Aug 10 04:07:00 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to database BAKDB (DBID=2717013816)
Connected to server version 10.2.0
Control Files in database:
/oracle/BAKDB/data01/cntrlBAKDB.ctl
Change database ID of database BAKDB? (Y/[N]) => y
Proceeding with operation
Changing database ID from 2717013816 to 3269519972
Control File /oracle/BAKDB/data01/cntrlBAKDB.ctl - modified
Datafile /oracle/BAKDB/data01/system_01.BAKDB - dbid changed
Datafile /oracle/BAKDB/data01/undotbs_01.BAKDB - dbid changed
Datafile /oracle/BAKDB/data01/sysaux01.BAKDB - dbid changed
Datafile /oracle/BAKDB/data01/users_01.BAKDB - dbid changed
Datafile /oracle/BAKDB/data01/fred_d_01.BAKDB - dbid changed
Control File /oracle/BAKDB/data01/cntrlBAKDB.ctl - dbid changed
Instance shut down
Database ID for database BAKDB changed to 3269519972.
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.
oracer> startup mount;
ORACLE instance started.
Total System Global Area 524288000 bytes
Fixed Size 2022080 bytes
Variable Size 146801984 bytes
Database Buffers 373293056 bytes
Redo Buffers 2170880 bytes
Database mounted.oracer> alter database open resetlogs;
Database altered.
oracer> select dbid from v$database;
DBID
----------
3269519972 ==> 新的DBID