Oracle数据库服务 service
An Oracle database is represented to clients as a service; that is, the database performs work on behalf of clients. A database can have one or more services associated with it.
Oracle连接描述符 connect descrīptor
To connect to a database service, clients use a connect descrīptor that provides the location of the database and the name of the database service.
listener
The address portion of the connect descriptor is actually the protocol address of the listener.
协议地址 protocol address
Much like a business address, the listener is configured to accept requests from clients at a protocol address. This address defines the protocol the listener is listening on and any other protocol specific information.
For some configurations, such as Oracle Real Application Clusters, multiple listeners on multiple nodes can be configured to handle client connection requests for the same database service.
一个4节点10gR2 RAC环境下的连接描述符的例子(来自$ORACLE_HOME/network/admin/tnsnames.ora文件):
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = aif05-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif06-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif14-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aig06-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
)
)
那么,就上面的实例来说,其中的
(ADDRESS = (PROTOCOL = TCP)(HOST = aif05-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif06-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif14-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aig06-vip)(PORT = 1521))
就是4个的协议地址。而(SERVICE_NAME = rac)中的“rac”就是数据库服务的名字。因而通过连接这4个节点的4个不同的,客户端连接请求都可以顺利连接到同一个数据库服务“rac”上。
连接字符串 connect string
连接标识符 connect identifier
网络服务名 net service name
Users initiate a connection request by providing a connect string. A connect string includes a username and password, along with a connect identifier. A connect identifier can be the connect descrīptor itself or a name that resolves to a connect descrīptor. One of the most common connect identifiers is a net service name, a simple name for a service.
那么完整的连接字符串的实例是:
scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sales-server1)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=sales.us.acme.com)))
需要注意的是“@”符号以后的部分(即连接标识符)一定要在同一行上。
同样来自上文提到的同一个RAC的网络服务名的例子(取自文件$ORACLE_HOME/network/admin/tnsnames.ora):
RAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = aif05-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif06-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif14-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aig06-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
)
)
其中等号左边的“RAC”就是网络服务名,而等号右边的就是上文提到的连接描述符。而所谓的连接标识符则要么是“RAC”,要么是等号右边的连接描述符。
在实践中这两者的效用是一致,可以通过下面的方法使用SQL*Plus来简单测试一下。
第一种连接方法利用网络服务名:
sqlplus scott/tiger@RAC
第二种连接方法利用连接描述符:
sqlplus scott/tiger@(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = aif05-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif06-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aif14-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = aig06-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
)
)