系统 rh5.8
oracle 10.2.0.5
使用nid实验之前要明白dbname和dbid以及sid的关系
在使用dbca建库的时候,有一步要填dbname和sid,一般情况下填完dbname后下面那个自动填上。实际上,sid和dbname是可以不一样的
另外,dbname能够指定一个数据库,dbid也能对应一个库,它们在数据库里是一一对应的。
但是二者又都是可以修改的,不过dbid的修改是系统自动改的(应该是往大的方向改)
下面是我的实验内容,后面附上英文原文(我只做修改 dbname和dbid,分别修改也都差不多,如果你需要,请参考我的步骤但实施前请按照英文文档核实需要的操作)
1.实验前准备(如果有可能最好生成下pfile)
查看原数据库dbid,dbname
SQL> select dbid,name from v$database;
DBID NAME
---------- ---------
1439048815 ORCL
[oracle@ttee ~]$ sqlplus sys/oracle as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 05:52:38 2016
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
2.关闭数据库,启动到mount
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
3.使用nid工具修改
[oracle@ttee ~]$ nid target=sys/oracle dbname=test
DBNEWID: Release 10.2.0.5.0 - Production on Tue May 24 05:56:14 2016
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to database ORCL (DBID=1439048815)
Connected to server version 10.2.0
Control Files in database:
/oradata/orcl/control01.ctl
/oradata/orcl/control02.ctl
/oradata/orcl/control03.ctl
Change database ID and database name ORCL to TEST? (Y/[N]) => y
Proceeding with operation
Changing database ID from 1439048815 to 2210806654
Changing database name from ORCL to TEST
Control File /oradata/orcl/control01.ctl - modified
Control File /oradata/orcl/control02.ctl - modified
Control File /oradata/orcl/control03.ctl - modified
Datafile /oradata/orcl/system01.dbf - dbid changed, wrote new name
Datafile /oradata/orcl/undotbs01.dbf - dbid changed, wrote new name
Datafile /oradata/orcl/sysaux01.dbf - dbid changed, wrote new name
Datafile /oradata/orcl/users01.dbf - dbid changed, wrote new name
Datafile /oradata/orcl/temp01.dbf - dbid changed, wrote new name
Control File /oradata/orcl/control01.ctl - dbid changed, wrote new name
Control File /oradata/orcl/control02.ctl - dbid changed, wrote new name
Control File /oradata/orcl/control03.ctl - dbid changed, wrote new name
Instance shut down
Database name changed to TEST.
Modify parameter file and generate a new password file before restarting.
Database ID for database TEST changed to 2210806654.
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.
4.提示成功,使用参数文件启动成功,如果有保存的pfile修改其中的dbname,我这里没有保存但是$ORACLE_HOME/dbs下有原来的spfile
将它拷贝到tmp下命名为init.ora,然后保留里面带*号的选项,其他一概删掉(尤其是乱码)更改dbname哪一行
SQL> startup mount pfile='/tmp/init.ora'
ORACLE instance started.
Total System Global Area 171966464 bytes
Fixed Size 2094832 bytes
Variable Size 113248528 bytes
Database Buffers 50331648 bytes
Redo Buffers 6291456 bytes
Database mounted.
SQL> alter database open resetlogs
2 ;
5.resetlogs后创建打开数据库创建spfile
SQL> create spfile from pfile='/tmp/init.ora';
File created.
6.创建新的密码文件。我这里使用的是操作系统认证,所以这一步在第5步之后,否则要先建密码文件
oracle@ttee dbs]$ orapwd file=orapwtest password=oracle
[oracle@ttee dbs]$
[oracle@ttee dbs]$ sqlplus sys/oracle as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 06:16:05 2016
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Database altered.
7.查看此时的dbid和dbname,发现已经是新的了
SQL> select dbid,name from v$database;
DBID NAME
---------- ---------
2210806654 TEST
Connected.
8.查看参数除了sid都变为test
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string test
db_unique_name string test
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
service_names string test
SQL>
9.查看监听,停止,开启,注册
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "test" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "test_XPT" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@ttee admin]$
10.修改tnsnames.ora,这里的服务名要修改
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ttee)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
修改完后
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ttee)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test)
)
)
然后使用一个普通用户sqlplus scott/tiiger@orcl
SQL> conn scott/tiger@orcl
Connected.
下面是英文原文