您的位置:首页 > 数据库 > Oracle

ORACLE_SID、DB_NAME、INSTANCE_NAME、DB_DOMIAN、GLOBAL_NAME区分

2015-06-04 13:23 429 查看
ORACLE_SID、DB_NAME、INSTANCE_NAME、DB_DOMIAN、GLOBAL_NAMES是Oracle中几个重要的参数,而且也比较容易混淆,下面给出这些参数的具体描述。 一、SID、ORACLE_SID: SID的全称为site identifier,Oracle_SID则为Oracle site identifier. 下面引用Tom(Thomas Kyte)的一段话来解释Oracle_SID If you’re unfamiliar with the term SID or ORACLE_SID, a full definition is called for. The SID is a site identifier. It and ORACLE_HOME (where the Oracle software is installed) are hashed together in UNIX to create a unique key name for attaching an SGA. If your ORACLE_SID or ORACLE_HOME is not set correctly, you’ll get the ORACLE NOT AVAILABLE error, since you can’t attach to a shared memory segment that is identified by this unique key. On Windows, shared memory isn’t used in the same fashion as UNIX, but the SID is still important. You can have more than one database on the same ORACLE_HOME, so you need a way to uniquely identify each one, along with their configuration files. 即:在Unix系统中,SID和ORACLE_HOME在一起哈希后得到一个唯一的值作为SGA的key。 当oracle实例启动时,在操作系统上的fork进程则根据Oracle_SID来创建相关后台进程。 Oracle 11g 支持Oracle_SID的长度为12位,db_name的长度为8位 作用: 用于区别同一台主机上不同的Oracle实例 决定实例所启动后台进程的名称。(实例由SGA和后台进程组成) 决定了参数文件的名称。如spfile<ORACLE_SID>.ora,init<ORACLE_SID>.ora 决定后台进程产生的相关跟踪文件、日志文件等。如alert_<ORACLE_SID>.log,<ORACLE_SID>_arc1_<spid>.trc,<SID>_ora_<SPID>.trc 同一主机上不同的$ORACLE_HOME,可以创建相同的ORACLE_SID 由此可以得出 ORACLE_HOME相同时,可以使用不同的ORACLE_SID ORACLE_HOME不同时,可以使用相同的ORACLE_SID [oracle@robinson ~]$ export ORACLE_SID=orcl --设定ORACLE_SID为orcl [oracle@robinson ~]$ sqlplus / as sysdba; SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 1 09:46:36 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; ORACLE instance started. Total System Global Area 469762048 bytes Fixed Size 1220048 bytes Variable Size 117441072 bytes Database Buffers 348127232 bytes Redo Buffers 2973696 bytes SQL> ho ps -ef | grep oracle --ORACLE_SID参与了后台进程命名 oracle 3272 1 0 09:46 ? 00:00:00 ora_pmon_orcl oracle 3274 1 0 09:46 ? 00:00:00 ora_psp0_orcl oracle 3276 1 1 09:46 ? 00:00:00 ora_mman_orcl oracle 3278 1 0 09:46 ? 00:00:00 ora_dbw0_orcl oracle 3280 1 0 09:46 ? 00:00:00 ora_lgwr_orcl oracle 3282 1 0 09:46 ? 00:00:00 ora_ckpt_orcl oracle 3284 1 0 09:46 ? 00:00:00 ora_smon_orcl ---------............部分结果省略.............. -------------- 二、INSTANCE_NAME 用于标识数据库实例的名称,缺省值通常为ORACLE_SID 用于和操作系统之间联系,根据实例名产生的响应的实例来取得与数据库的交互 初始化参数中INSTANCE_NAME与ORACLE_SID可以不同 不同的实例可以拥有相同的INSTANCE_NAME,只要ORACLE_SID不同,则与ORACLE_HOME哈希可以得到不同的值 INSTANCE_NAME可以用于向监听器动态注册 [oracle@robinson ~]$ cp $ORACLE_HOME/dbs/initorcl.ora $ORACLE_HOME/dbs/initscott.ora [oracle@robinson ~]$ export ORACLE_SID=scott --设定ORACLE_SID为scott [oracle@robinson ~]$ env | grep ORA ORACLE_SID=scott ORACLE_BASE=/u01/app/oracle ORACLE_HOME=/u01/app/oracle/10g [oracle@robinson ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 1 10:04:59 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; --启动实例scott ORACLE instance started. Total System Global Area 469762048 bytes Fixed Size 1220048 bytes Variable Size 134218288 bytes Database Buffers 331350016 bytes Redo Buffers 2973696 bytes SQL> show parameter instance_name; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string scott SQL> ho ps -ef | grep scott --可以看到后台以scott命名的进程 oracle 3489 1 0 10:05 ? 00:00:00 ora_pmon_scott oracle 3491 1 0 10:05 ? 00:00:00 ora_psp0_scott oracle 3493 1 0 10:05 ? 00:00:00 ora_mman_scott oracle 3495 1 0 10:05 ? 00:00:00 ora_dbw0_scott oracle 3497 1 0 10:05 ? 00:00:00 ora_lgwr_scott oracle 3499 1 0 10:05 ? 00:00:00 ora_ckpt_scott ---------............部分结果省略.............. -------------- SQL> ho ps -ef | grep ora --此时可以看到后台启动了orcl和scott两个实例 oracle 3445 1 0 10:01 ? 00:00:00 ora_pmon_orcl oracle 3447 1 0 10:01 ? 00:00:00 ora_psp0_orcl oracle 3449 1 0 10:01 ? 00:00:00 ora_mman_orcl oracle 3451 1 0 10:01 ? 00:00:00 ora_dbw0_orcl oracle 3453 1 0 10:01 ? 00:00:00 ora_lgwr_orcl oracle 3455 1 0 10:01 ? 00:00:00 ora_ckpt_orcl oracle 3457 1 0 10:01 ? 00:00:00 ora_smon_orcl oracle 3497 1 0 10:05 ? 00:00:00 ora_lgwr_scott oracle 3499 1 0 10:05 ? 00:00:00 ora_ckpt_scott oracle 3501 1 0 10:05 ? 00:00:00 ora_smon_scott oracle 3503 1 0 10:05 ? 00:00:00 ora_reco_scott oracle 3505 1 0 10:05 ? 00:00:00 ora_cjq0_scott oracle 3507 1 0 10:05 ? 00:00:00 ora_mmon_scott ---------............部分结果省略.............. -------------- SQL>select*from dual; ADDR INDX INST_ID D -------- ---------- ---------- - 0C4B2FD4 0 1 X --用于向监听器动态注册 SQL> ho lsnrctl status LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 01-SEP-2010 12:30:13 --------------------------部分省略--------------------------------------- Listener Parameter File /u01/app/oracle/10g/network/admin/listener.ora Listener Log File /u01/app/oracle/10g/network/log/listener.log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=robinson.com)(PORT=1521))) Services Summary... Service "PLSExtProc" has 1 instance(s).--服务名PLSExtProc及实例名PLSExtProc Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service... Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... Service "orclXDB" has 1 instance(s). --服务名orcl_XDB,实例名为orcl Instance "orcl", status READY, has 1 handler(s) for this service... Service "orcl_XPT" has 1 instance(s).--服务名orcl_XPT,实例名为orcl Instance "orcl", status READY, has 1 handler(s) for this service... The command completed successfully 三、DB_NAME 数据库的唯一标识,是一个不超过8个字符的文本串在创建数据库时定义,被记录在数据文件、控制文件和日志文件当中。 用于实例与数据库的挂接,通常缺省的情况下,INSTANCE_NAME与DB_NAME设置为相同。 在RAC环境中,多实例对应于一个数据库,故INSTANCE_NAME与DB_NAME不同。 对于早期的数据库,单单用DB_NAME参数足以表示一个数据库,随着多个数据库构成分布式数据库,因为数据库名字可能一样,为避免此类命名方式造成了管理上的混乱,引入DB_DOMAIN参数,即数据库名字由DB_NAME和DB_DOMAIN两个参数共同决定的,两个参数中间用.连接,类似于互联网上机器名的管理。两者的组合即被称为GLOBAL_NAME。关于DB_DOMAIN和GLOBAL_NAME请参照后续描述。 实例与数据库的关系 一个实例可以mount并打开任何数据库,但同一时间一个实例仅仅只能打开一个数据库 一个数据库可以被一个或多个实例mount并打开,比如在RAC环境中,一个数据可以被多个实例打开 在非RAC环境中使用不同的实例名来打开同一个数据库将收到错误提示,如下: [oracle@robinson ~]$ export ORACLE_SID=scott --设置实例名为scott并启动该实例 [oracle@robinson ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 1 12:41:49 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 469762048 bytes Fixed Size 1220048 bytes Variable Size 134218288 bytes Database Buffers 331350016 bytes Redo Buffers 2973696 bytes ORA-01102: cannot mount databasein EXCLUSIVE mode --收到错误信息,不能够mount该数据库 SQL>select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ scott STARTED SQL> ho ps -ef | grep oracle --查看后台启动了两个实例一个为orcl,一个为scott oracle 4800 1 0 12:19 ? 00:00:00 ora_pmon_orcl oracle 4805 1 0 12:19 ? 00:00:00 ora_psp0_orcl oracle 4807 1 0 12:19 ? 00:00:00 ora_mman_orcl oracle 4809 1 0 12:19 ? 00:00:00 ora_dbw0_orcl oracle 4811 1 0 12:19 ? 00:00:00 ora_lgwr_orcl oracle 4813 1 0 12:19 ? 00:00:00 ora_ckpt_orcl oracle 4961 1 0 12:41 ? 00:00:00 ora_pmon_scott oracle 4963 1 0 12:41 ? 00:00:00 ora_psp0_scott oracle 4965 1 0 12:41 ? 00:00:00 ora_mman_scott oracle 4967 1 0 12:41 ? 00:00:00 ora_dbw0_scott ---------............部分结果省略.............. -------------- SQL> ho grep name $ORACLE_HOME/dbs/initscott.ora --initscott.ora由initorcl.ora复制而来,故有相同的数据库名称 *.db_name='orcl' --而此时DB_NAME='orcl'已被实例orcl启动,故收到了ORA-01102: cannot mount database in EXCLUSIVE mode --关闭orcl实例后,并启动scott实例,使之加载orcl数据库 SQL> ho env | grep ORA ORACLE_SID=scott ORACLE_BASE=/u01/app/oracle ORACLE_HOME=/u01/app/oracle/10g SQL> startup ORACLE instance started. Total System Global Area 469762048 bytes Fixed Size 1220048 bytes Variable Size 134218288 bytes Database Buffers 331350016 bytes Redo Buffers 2973696 bytes Database mounted. Database opened. --正常启动,即一个数据可以被任意实例mount并打开 SQL>select instance_name,status,database_status from v$instance; INSTANCE_NAME STATUS DATABASE_STATUS ---------------- ------------ ----------------- scott OPEN ACTIVE SQL>selectname,open_mode from v$database; NAME OPEN_MODE --------- ---------- ORCL READ WRITE 总结: 一个实例可以mount并打开任何数据库,但任一时刻仅仅只能打开一个数据库 一个数据库可以被一个或多个实例mount并打开,比如在RAC环境中,一个数据可以被多个实例打开 如数据库orcl 首先被orcl 实例打开。但不能被scott实例打开 当关闭orcl实例后,数据库orcl能够被scott实例mount并打开 四、DB_DOMAIN 通常用于分布式数据库系统中标识一个数据库的逻辑位置。为数据定义一个域,该参数作为Global_names的一部分,即在不同的域中可以使用相同的数据库名称,该参数缺省情况下位空,在RAC环境中需要为每一个实例指定该值,且多实例具有相同的值 SQL> show parameter db_domain NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_domain string 五、GLOBAL_NAME一个是GLOBAL_NAME,一个是GLOBAL_NAMES参数,GLOBAL_NAME是全局数据库名,GLOBAL_NAMES参数设定是否启用全局数据库名。 GLOBAL_NAME的形式为:DB_NAME.DB_DOMAIN 修改global_name,只能用ALTERDATABASE RENAME GLOBAL_NAME TO<db_name.db_domain>命令进行修改,然后修改相应参数。 SQL>select*from global_name; --查看数据库的global_name GLOBAL_NAME -------------------------------------------------------------------------------- ORCL.REGRESS.RDBMS.DEV.US.ORACLE.COM SQL>alterdatabase rename global_name to orcl.robinson.com;--修改数据库的global_name Database altered. SQL>select*from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- ORCL.ROBINSON.COM GLOBAL_NAMES参数通常对于分布式处理,Oracle 建议将该值设为TRUE,用于确保通连接到网络环境使用一致性的命名方式。 一般情况下假定全局数据库的名称为orcl.robinosn.com ,当GLOBAL_NAMES设置为true时,数据库执行调用时会核查链接的名字是否和远程 全局数据库名称一致,否则如果为false,可以任意定义数据库链接的名字。 假定远程数据库名称为orcl.robinosn.com ,参数global_names设为true,则必须使用下面的方式来调用 select*from scott.emp@orcl.robinson.com 如果global_names设为false,则可以使用定义的任意名字来调用 select*from scott.emp@orclalias SQL> show parameter global_names --查看global_names参数的设置情况 NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ global_names boolean FALSE 关于GLOBAL_NAMES更多参考:Oracle Database Administrator’s Guide(DistributedDatabase Concepts) 六、GLOBAL_DBNAME 事实上,GLOBAL_DBNAME并不是一个初始化参数文件中的参数,而是在配置侦听器中用于标识数据库服务 下面是来自Oracle的官方描述 Identifies the database service. While processing a client connection request, the listener tries to match the value of this parameter with the value of the SERVICE_NAME parameter in the client connect descriptor. If the client connect descriptor uses the SID parameter, then the listener does not attempt to map the values. This parameter is primarily intended for configurations with Oracle8 release 8.0 databases(where dynamic service registration is not supported for dedicated servers). This parameter may also be required for use with Oracle8i and higher database services by some configurations. The value for this parameter is typically obtained from the combination of the DB_NAME and DB_DOMAIN parameters (DB_NAME.DB_DOMAIN) in the initialization parameter file, but the value can also contain any valid name used by clients to identify the service. 也称为全局数据库名称,是对一个数据库(Oracle database)的唯一标识,oracle建议用此种方法命令数据库。 该值是在创建数据库是决定,缺省值为DB_NAME.DB_DOMAIN。 在以后对参数文件中DB_NAME与DB_DOMAIN参数的任何修改不影响GLOBAL_NAME的值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: