昨天,由于现实原因,需要更改名,在此做下记录,以便日后参考!
在 9iR2提供了一个工具,可以通过它来更改db_name和dbid,这样就避免重建控制文件了。nid工具可以只用来更改数据库名(db_name),或者只更改数据库的id(dbid),或者两个同时更改。
当涉及到更改db_name的时候,由于数据库名还存在与参数文件中,因此,更改数据库名时也要更改相应的参数。如果你使用了spfile,那么要重建它。另外,还需要重建密码文件。
有关nid工具的详细使用情况,在metalink 文章 Note:224266.1有详细的记载。
首先,我们来看看nid的使用帮助:
[oracle@testdbc oracle]$ nid
DBNEWID: Release 9.2.0.6.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. 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
这里来解释一下几个问题:
(I):如果你只想更改数据库的id(dbid),那么你只需要指定target参数就可以了,具体的操作过程,请参考如下:
1. Backup the database
2. SHUTDOWN IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/password@test_db
5. Shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter
file to the new database name
7. Create a new password file
8. Startup of the database with open resetlogs
(II):如果你想只更改数据库名(db_name),那么你需要设置SETNAME参数为Y,同时指定DBNAME参数,具体的操作过程,请参考如下:
1. Backup the database
2. SHUTDOWN IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/password@test_db DBNAME=test_db2 SETNAME=Y
- the value of DBNAME is the new dbname of the database
- SETNAME must be set to Y. The default is N and causes the
DBID to be changed also.
5. shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter
file to the new database name
7. Create a new password file
8. Startup of the database(without resetlogs)
(III):如果你想同时更改数据库名(db_name)和数据库ID(dbid),那么你要指定DBNAME参数,同时设置SETNAME为N(其值默认也为N),具体操作过程,请参考如下:
1. Backup of the database.
2. Shutdown IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/password@test_db DBNAME=test_db2
- the value of DBNAME is the new dbname of the database
5. After DBNEWID successfully changes the DBID,Shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter file to the new database name.
7. Create a new password file.
8. Startup of the database with open resetlogs
(IV):如果你只更改了数据库名,而没有更改数据库id,那么你打开数据库就不需要open resetlogs了。
下面是我自己做的一次操作,DBNAME和DBID同时更改。
1.数据库启动到mount状态
SQL> startup mount
ORACLE instance started.
total System Global Area 923904016 bytes
Fixed Size 452624 bytes
Variable Size 385875968 bytes
Database Buffers 536870912 bytes
Redo Buffers 704512 bytes
Database mounted.
2. 使用NID更改
[oracle@testdb2 dbs]$ nid target=sys/syspassword dbname=testdb2
DBNEWID: Release 9.2.0.6.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
Connected to database TESTDB1 (DBID=287286795) -- 注意这里的数据库名和数据库id
Control Files in database:
/cx300_testdb2/data1/control01.ctl
/cx300_testdb2/data2/control02.ctl
/cx300_testdb2/data3/control03.ctl
Change database ID and database name TESTDB1 to TESTDB2? (Y/[N]) => Y – 这里有个手工确认过程
Proceeding with operation
Changing database ID from 287286795 to 975736982
Changing database name from TESTDB1 to TESTDB2
Control File /cx300_testdb2/data1/control01.ctl – modified -- 更改控制文件中相关控制信息,这里估计是致控制文件于某种状态,以便后面信息的更改。
Control File /cx300_testdb2/data2/control02.ctl - modified
Control File /cx300_testdb2/data3/control03.ctl - modified
Datafile /cx300_testdb2/data2/system01.dbf - dbid changed, wrote new name -- 这里开始更改数据文件中的信息
Datafile /cx300_testdb2/data2/tbs_taobao_3.dbf - dbid changed, wrote new name
…………………………………………
Datafile /cx300_testdb2/data3/tbs_temp2.dbf - dbid changed, wrote new name
Control File /cx300_testdb2/data1/control01.ctl - dbid changed, wrote new name --- 这里开始更改控制文件中的信息
Control File /cx300_testdb2/data2/control02.ctl - dbid changed, wrote new name
Control File /cx300_testdb2/data3/control03.ctl - dbid changed, wrote new name
Database name changed to TESTDB2. –- 数据库名更改完毕
Modify parameter file and generate a new password file before restarting. –- 这里提示要在再次启动数据库时要更改parameter file和password file
Database ID for database TESTDB2 changed to 975736982. –- 数据库id更改完毕
All previous backups and archived redo logs for this database are unusable.
Shut down database and open with RESETLOGS option. –- 由于更改了dbid,所以要以resetlogs选项打开数据库
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
3.Shutdown database
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
4.修改初始化参数文件
###########################################
db_domain=""
db_name=testdb2
# db_name=testdb1
###########################################
5.重建口令文件
orapwd file=/opt/oracle/product/9.2/dbs/orapwdev-db2 password=syspassword
6.Startup mount,resetlogs打开
alter database open resetlogs;
7.创建新的spfile
create spfile from pfile='/opt/oracle/product/9.2/dbs/initdev-db2.ora';
8.对数据库做个全
我这里其实在开始的时候还少了一步,就是在更改之前,要对全库做备份。这个很重要,备份最重要!
<!--
--EOF--
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/386081/viewspace-605926/,如需转载,请注明出处,否则将追究法律责任。