对于Oracle数据库来说,db_name和instance_name可以不同。
我们来看一下Oracle文档中对于db_name的定义:
DB_NAME必须是一个不超过8个字符的文本串.在数据库创建过程中,db_name被记录在数据文件,日志文件和控制文件中。如果数据库实例启动过程中参数文件中的db_name和控制文件中的数据库名称不一致,则数据库不能启动。
我们看一下我的数据库:
[oracle
@jumper dbs]$ grep name initeygle.ora
*.db_name='eygle'
*.instance_name='eygle'
当前参数设置下的数据库:
sql> select name from v$datafile;
NAME
-----------------------------------------------------
/opt/oracle/oradata/eygle/system01.dbf
/opt/oracle/oradata/eygle/undotbs01.dbf
/opt/oracle/oradata/eygle/users01.dbf
/opt/oracle/oradata/eygle/eygle01.dbf
sql> show parameter db_name
NAME
TYPE VALUE
------------------------------------ ----------- -----------
db_name
string eygle
sql> show parameter instance_name
NAME
TYPE VALUE
------------------------------------ ----------- -----------
instance_name
string eygle
sql> create pfile from spfile;
File created.
sql> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
我们创建一个新的pfile为julia这个新的实例使用:
[oracle
@jumper oracle]$ cd $ORACLE_HOME/dbs
[oracle
@jumper dbs]$ cp initeygle.ora initjulia.ora
[oracle
@jumper dbs]$ ll init*
-rw-r--r--
1 oracle dba 982 Jul 25 14:03 initeygle.ora
-rw-r--r--
1 oracle dba 982 Jul 25 14:04 initjulia.ora
-rw-r--r--
1 oracle dba 8385 Mar92002 init.ora
instance_name = julia
修改后的参数设置:
[oracle
@jumper dbs]$ grep name initjulia.ora
*.db_name='eygle'
*.instance_name='julia'
然后我们启动实例名称为julia的instance:
[oracle@jumper dbs]$ export ORACLE_SID=julia
[oracle@jumper dbs]$ sqlplus "/ as sysdba"
sql*Plus: Release 9.2.0.4.0 - Production on Tue Jul 25 14:04:15 2006
Copyright (c) 1982,2002,Oracle Corporation.All rights reserved.
Connected to an idle instance.
sql> startup mount;
ORACLE instance started.
Total System Global Area139531744 bytes
Fixed Size
452064 bytes
Variable Size
121634816 bytes
Database Buffers
16777216 bytes
Redo Buffers
667648 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
sql> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[oracle@jumper dbs]$ ps -ef|grep ora
oracle
27321 10 Jul14 ? 00:00:00 ora_pmon_eygle
oracle
27323 10 Jul14 ? 00:00:00 ora_dbw0_eygle
oracle
27325 10 Jul14 ? 00:00:00 ora_lgwr_eygle
oracle
27327 10 Jul14 ? 00:00:00 ora_ckpt_eygle
oracle
27329 10 Jul14 ? 00:00:32 ora_smon_eygle
oracle
27331 10 Jul14 ? 00:00:00 ora_reco_eygle
oracle
27333 10 Jul14 ? 00:00:00 ora_cjq0_eygle
root
15388 6560 14:02 ? 00:00:00 sshd: oracle [priv]
oracle
15390 153880 14:02 ? 00:00:00 sshd: oracle@pts/2
oracle
15391 153900 14:02 pts/2 00:00:00 -bash
oracle
15445 10 14:04 ? 00:00:00 ora_pmon_julia
oracle
15447 10 14:04 ? 00:00:00 ora_dbw0_julia
oracle
15449 10 14:04 ? 00:00:00 ora_lgwr_julia
oracle
15451 10 14:04 ? 00:00:00 ora_ckpt_julia
oracle15453
10 14:04 ? 00:00:00 ora_smon_julia
oracle
15455 10 14:04 ? 00:00:00 ora_reco_julia
oracle
15457 10 14:04 ? 00:00:00 ora_cjq0_julia
oracle
15459 153910 14:04 pts/2 00:00:00 ps -ef
oracle
15460 153910 14:04 pts/2 00:00:00 grep ora
[oracle@jumper dbs]$ export ORACLE_SID=eygle
[oracle@jumper dbs]$ sqlplus "/ as sysdba"
sql*Plus: Release 9.2.0.4.0 - Production on Tue Jul 25 14:04:39 2006
Copyright (c) 1982,Oracle Corporation.All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
sql> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sql> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
此时就可以通过实例julia加载并打开db_name=eygle的数据库了:
[oracle@jumper dbs]$ export ORACLE_SID=julia
[oracle@jumper dbs]$ sqlplus "/ as sysdba"
sql*Plus: Release 9.2.0.4.0 - Production on Tue Jul 25 14:05:06 2006
Copyright (c) 1982,Oracle Corporation.All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
sql> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
sql> alter database open;
Database altered.
sql> select name from v$datafile;
NAME
----------------------------------------------------------------------------
/opt/oracle/oradata/eygle/system01.dbf
/opt/oracle/oradata/eygle/undotbs01.dbf
/opt/oracle/oradata/eygle/users01.dbf
/opt/oracle/oradata/eygle/eygle01.dbf
sql> ! ps -ef|grep ora
root
15388 6560 14:02 ? 00:00:00 sshd: oracle [priv]
oracle
15390 153880 14:02 ? 00:00:00 sshd: oracle@pts/2
oracle
15391 153900 14:02 pts/2 00:00:00 -bash
oracle
15445 10 14:04 ? 00:00:00 ora_pmon_julia
oracle
15447 10 14:04 ? 00:00:00 ora_dbw0_julia
oracle
15449 10 14:04 ? 00:00:00 ora_lgwr_julia
oracle
15451 10 14:04 ? 00:00:00 ora_ckpt_julia
oracle
15453 10 14:04 ? 00:00:00 ora_smon_julia
oracle
15455 10 14:04 ? 00:00:00 ora_reco_julia
oracle
15457 10 14:04 ? 00:00:00 ora_cjq0_julia
oracle
15513 153910 14:05 pts/2 00:00:00 sqlplus
oracle
15514 155133 14:05 ? 00:00:01 oraclejulia (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle
15515 155130 14:05 pts/2 00:00:00 /bin/bash -cps -ef|grep ora
oracle
15516 155150 14:05 pts/2 00:00:00 ps -ef
sql> show parameter instance_name
NAME
TYPEVALUE
------------------------------------ ----------- ------------------------------
instance_name
string julia
sql> show parameter db_name
NAME
TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name
string eygle
修改参数db_name:
[oracle@jumper dbs]$ grep name initjulia.ora
*.db_name='julia'
*.instance_name='julia'
sql> startup nomount;
ORACLE instance started.
Total System Global Area139531744 bytes
Fixed Size
452064 bytes
Variable Size
121634816 bytes
Database Buffers
16777216 bytes
Redo Buffers
667648 bytes
sql> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-01103: database name 'EYGLE' in controlfile is not 'JULIA'
另外的一个区别是,db_name通常限制在8个字符之内;instance_name最多应该支持21个字符。通常我们都是设置db_name和instance_name一致。需要注意的是如果db_name设置过长,则会被Oracle截断为8个字符,而instance_name仍然会保留在21个字符之内,如果你的环境变量设置的instance_name=db_name,则启动时就会出现问题,你需要重建pfile/spfile并且修改环境变量才能启动实例,加载数据库。
这个问题可以参考Itpub曾经出现的案例:
http://www.itpub.net/showthread.PHP?threadid=604507
本文通过实例来介绍instance_name和db_name的区别,希望大家能对这两个参数以及instance和database有进一步的认识。
个人补充:
1.
拷贝eygle数据库的参数文件 INITeygle.ORA 为 INITjulia.ORA,并设置 instancename = julia,也可以动态生成 spfile 文件,启动的时候使用该spfile。
2.
为实例 julia 生成新的 password file,可以拷贝 PWDEYGLE.ora 然后改名为 PWDJULIA.ora,或者使用 orapwd命令:
orapwd file=%ORACLE_HOME%datebase¥PWDJULIA.ora password={password} entries=10
3.
为实例 julia 生成Windows Service
oradim -new -sid JULIA -intpwd password -startmode a -pfile %ORACLE_HOME%database¥INITjulia.ORA
5.
reload TNS listener
lsnrctl reload
原文链接:https://www.f2er.com/oracle/213353.html