oracle DBID,SID,DB_NAME,DB_DOMAIN,INSTANCE_NAME,DB_UNIQUE_NAME, SERVICE_NAMES 及监听参数的说明
DBID,SID,DB_NAME,DB_DOMAIN,INSTANCE_NAME,DB_UNIQUE_NAME, SERVICE_NAMES 及监听参数的说明
DB 相关的: DBID, SID
PFILE 中的参数: DB_NAME, DB_DOMAIN, INSTANCE_NAME,DB_UNIQUE_NAME,SERVICE_NAMES,GLOBAL_NAME,GLOBAL_NAMES
Listener.ora 中参数:SID_NAME, GLOBAL_DBNAME
Tnsnames.ora 中参数:SERVICE_NAME, SID
1 与 DB 相关的 2 个参数
DBID(DataBase IDentifier)
Oracle 官网对 DBID 的解释如下:
An internal, uniquely generated number that differentiates databases. Oracle creates this number automatically when you create the database
DBID 可以看成是 db_name 在数据库内部的表示。 DBID 是在创建数据库时,用 db_name 结合一种算法来创建的。 具体用什么算法,不太清楚。它存在
与数据文件和控制文件,用于表示数据文件的归属。 所以这个 DBID 是唯一的。对于不同的数据库, DBID 是不同的,但是 db_name 有可能相同。
SYS@ orcl >select dbid from v$database; DBID ---------- 1534031567
SID(system identifier)
SYS@ orcl >select instance_name from v$instance; INSTANCE_NAME ---------------- orcl
尽管v$instance中字段 instance_name 看起来是实例名,但是实际上存储的是 sid。 在win下, 不管oracle_home是否相同sid不能重复。
2 Pfile 中的参数
SYS@ orcl >create pfile='/tmp/pfile20180509.sql' from spfile; File created. [oracle@DSI ~]$ cat /tmp/pfile20180509.sql orcl.__db_cache_size=322961408 orcl.__java_pool_size=4194304 orcl.__large_pool_size=8388608 orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orcl.__pga_aggregate_target=318767104 orcl.__sga_target=469762048 orcl.__shared_io_pool_size=0 orcl.__shared_pool_size=121634816 orcl.__streams_pool_size=0 *.audit_file_dest='/u01/app/oracle/admin/orcl/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.log_archive_dest_1='location=/u01/app/oracle/arch' *.memory_target=786432000 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1'
DB_NAME
Database identifier. Must correspond to the value used in the CREATE DATABASE statement. Maximum 8 characters.
DB_NAME 是数据库名,它的长度不能超过8个字节,超过8个会被截断。
对于 RAC 环境,各个节点之间的 DB_NAME 都是相同的,INSTANCE_NAME 不同,DB_DOMAIN相同,DB_UNIQUE_NAME相同。
对于 Data Guard 环境, DB_NAME 相同, DB_UNIQUE_NAME 不同。
查看db_name
SYS@ orcl >show parameter db_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_name string orcl SYS@ orcl > select dbid,name from v$database; DBID NAME ---------- --------- 1534031567 ORCL
DB_DOMAIN
Property | Description |
Default value | There is no default value. |
Modifiable | No |
Range of values | Any legal string of name components, separated by periods and up to 128 characters long (including the periods). This value cannot be NULL |
Basic | Yes |
Oracle RAC | You must set this parameter for every instance, and multiple instances must have the same value |
DB_UNIQUE_NAME
Property | Description |
Parameter type | String |
Syntax | DB_UNIQUE_NAME = database_unique_name |
Default value | Database instances: the value of DB_NAME Automatic Storage Management instances: +ASM |
Modifiable | No |
Basic | Yes |
Oracle RAC | Multiple instances must have the same value. |
-- 对于 DB_NAME 系统的的数据库必须要有不同的 DB_UNIQUE_NAME。
DB_UNQUIE_NAME 的会影响到 Service_names,也会影响到动态监听的时候的 service_name。
如在 Data Guard 环境下,如果采用动态注册,那么注册的Service 就是 DB_UNIQUE_NAME。 但 instance 还是 instance_name,即 SID
如:
Service " orcl_st " has 1 instance(s).
Instance "orcl", status BLOCKED, has 1 handler(s) for this service...
Service " orcl_st _XPT" has 1 instance(s).
Instance "orcl", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully
INSTANCE_NAME
Property | Description |
Parameter type | String |
Syntax | INSTANCE_NAME = instance_id |
Default value |
The instance's SID Note: The SID identifies the instance's shared memory on a host, |
Modifiable | No |
Range of values | Any alphanumeric characters and the underscore (_) character |
Basic | No |
--INSTANCE_NAME 的默认值就是 SID。 一般跟数据库库名称相同,也可以不相同。
SYS@ orcl >show parameter db_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_name string orcl SYS@ orcl > show parameter instance_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string orcl
--INSTANCE_NAME 会影响进程的命名:
[oracle@DSI ~]$ ps -ef|grep pmon ##单实例 oracle 17779 1 0 May08 ? 00:00:04 ora_pmon_orcl oracle 22576 17549 0 15:19 pts/3 00:00:00 grep pmon [oracle@rac05 ~]$ ps -ef|grep pmon ##rac grid 4076 1 0 Apr26 ? 00:03:01 asm_pmon_+ASM1 oracle 4658 1 0 Apr26 ? 00:03:36 ora_pmon_bol1 oracle 21999 19674 0 15:20 pts/0 00:00:00 grep pmon --initSID.ora 和 orapwSID 文件要与 INSTANCE_NAME 保持一致: [oracle@DSI ~]$ cd $ORACLE_HOME/dbs [oracle@DSI dbs]$ ll -rw-rw---- 1 oracle oinstall 1544 May 8 17:02 hc_orcl.dat -rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora -rw-r----- 1 oracle oinstall 24 Apr 22 10:07 lkORCL -rw-r----- 1 oracle oinstall 1536 Apr 22 10:28 orapworcl -rw-r----- 1 oracle oinstall 10076160 Apr 30 15:45 snapcf_orcl.f -rw-r----- 1 oracle oinstall 2560 May 8 22:00 spfileorcl.ora
SERVICE_NAMES
Property | Description |
Parameter type | String |
Syntax | SERVICE_NAMES =db_service_name [, db_service_name [ ... ] ] |
Default value | DB_UNIQUE_NAME.DB_DOMAIN if defined |
Modifiable | ALTER SYSTEM |
Range of values | Any ASCII string or comma-separated list of string names |
Basic | No |
Oracle RAC |
Do not set the SERVICE_NAMES parameter for Oracle RAC environments. Instead, define services using Oracle Enterprise |
--服务名是复数, service_names 可以是多个值
在 Data Guard 中, 如果采用动态注册, 建议在 primary, standby 上使用相同的 service_names,这样可能便于尽可能的实现透明切换。
如果配置了静态注册的监听在 primary, standby 上也务必保持在 listener 中要求输入的服务名相同,尽可能的实现透明切换。
SYS@ orcl >show parameter service_names NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ service_names string orcl
GLOBAL_NAME
global_name 是由 db_name.db_domain 构成。
SYS@ orcl >select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- ORCL
Property | Description |
Parameter type | Boolean |
Default value | false |
Modifiable | ALTER SESSION, ALTER SYSTEM |
Range of values | true | false |
Basic | No |
Global_names 是一个布尔值, global_names 的作用是创建 db link 时是否强制使用远程数据库的 global_name,如果 global_names=true,则 db link name 必须要
求是 remote database 的 global_name,否则创建之后 db link 不能连同,缺省值是false。多用于分布式系统
SYS@ orcl >show parameter global_names; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ global_names
rac: --instance1 *.db_domain='' *.db_name='bol' bol2.instance_number=2 bol1.instance_number=1 --instance2 *.db_domain='' *.db_name='bol' bol2.instance_number=2 bol1.instance_number=1 dg: --primary *.db_domain='' *.db_name='bol' bol2.instance_number=2 bol1.instance_number=1 --standby *.db_domain='' *.db_name='bol' *.service_names='orcl' *.db_unique_name='orcl'
db_name 还有一个非常重要的作用就是动态注册监听. 关于动态注册和静态注册,参考 Blog:
Oracle Listener 动态注册 与 静态注册
http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5543166.aspx
不管是否指定了 service_name,或者说 service_name 的值是什么, pmon 都会使用 db_name 动态注册监听的。
注册到监听器中的服务值从 init.ora 文件中的参数 service_names 取得。
如果该参数没有设定值,数据库将拼接 init.ora 文件中的 db_name 和 db_domain 的值来注册自己。
如果选择提供 service_names 值,您可以使用完全限定的名称(比
如 orcl.oracle.com)或缩写的名称(比如 orcl)。如果选择缩写的名称并设置了
db_domain 参数, 注册到监听器中的服务将是 service_name 值和 db_domain 值的拼接。
3 Listener.ora 文件中的参数
==rac [oracle@rac05 ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-MAY-2019 14:57:24 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 26-APR-2019 17:27:58 Uptime 12 days 21 hr. 29 min. 25 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora Listener Log File /u01/app/grid/diag/tnslsnr/rac05/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.15.8.15)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.15.8.17)(PORT=1521))) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM1", status READY, has 1 handler(s) for this service... Service "bol" has 2 instance(s). Instance "bol1", status UNKNOWN, has 1 handler(s) for this service... Instance "bol1", status READY, has 1 handler(s) for this service... Service "bolXDB" has 1 instance(s). Instance "bol1", status READY, has 1 handler(s) for this service... The command completed successfully [oracle@rac05 ~]$ cat /u01/app/11.2.0/grid/network/admin/listener.ora LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = bol) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = bol1) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER)) ) ADR_BASE_LISTENER = /u01/app/grid ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent LISTENER_SCAN1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER_SCAN1)) ) ADR_BASE_LISTENER_SCAN1 = /u01/app/grid
==单实例
[oracle@DSI ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-MAY-2019 14:56:11 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DSI)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 06-MAY-2019 09:45:00 Uptime 3 days 5 hr. 11 min. 11 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/DSI/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DSI)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Services Summary... Service "orcl" has 2 instance(s). Instance "orcl", status UNKNOWN, has 1 handler(s) for this service... Instance "orcl", status READY, has 1 handler(s) for this service... Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... The command completed successfully [oracle@DSI ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcl) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = DSI)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
SID_NAME
SID_NAME 指数据库的运行的实例名,和 instance_name 保持一致
GLOBAL_DBNAME
配置静态监听注册时, 需要输入 SID 和 GLOBAL_NAME。
GLOBAL_DBNAME 是 listener 配置的对外网络连接名称, 我们可以写成任意值。
在客户端配置监听的 tnsnames.ora 文件中的 service_name 与这个GLOBAL_DBNAME 保持一致就可以了。因为客户端访问数据库是通过监听来实现的。
如果采用动态注册的话, PMON 进程会根据初始化参数 initSID.ora 中的
instance_name,service_names 两个参数将实例和服务动态注册到 listener 中, 这时
自动注册的对外网络连接名称就是 initSID.ora 文件中 service_names
因为 service_names 可以有多个值,如果有多个值,就会注册多个。 但是他
们对应都是同一个 instance_name。 这样,我们在客户端配置 tnsnames.ora 时,
在 service_name 写其中任意一个都可以正常连上数据库。
4 Tnsnames.ora 文件
[oracle@DSI ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora orcl = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.15.7.25)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
SERVICE_NAME
如果服务器采监听采用了静态注册,那么这个参数就等于 Listener.ora 文件中的 GLOBAL_DBNAME 的值
如果是动态注册,那么这个值就是 initSID.ora 文件中 service_names 中的值。
SID
在 tnsnames.ora 文件中还可以使用 SID。 如果使用该参数,只需要把该参数指定为 instance_name 就可以了。
参考:Blog:http://blog.csdn.net/tianlesoftware/archive/2010/12/20/6086066.aspx