一. 查看service
1.1 先看下一个监听查看的示例:
[oracle@db2 ~]$ lsnrctl service
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 19-JUL-2011 01:24:43
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
Services Summary...
Service "PLSExtProc"has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) forthis service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "dave2"has 1 instance(s).
Instance "dave2", status READY, has 1 handler(s) for thisservice...
Handler(s):
"DEDICATED" established:5 refused:0 state:ready
LOCAL SERVER
Service"dave2XDB" has 1 instance(s).
Instance "dave2", status READY, has 1 handler(s) for thisservice...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: db2, pid: 11691>
(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=35619))
Service "dave2_XPT"has 1 instance(s).
Instance "dave2", status READY, has1 handler(s) for this service...
Handler(s):
"DEDICATED" established:5 refused:0 state:ready
LOCAL SERVER
The command completed successfully
[oracle@db2 ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 19-JUL-2011 01:32:14
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version10.2.0.1.0 - Production
Start Date 12-JUL-2011 23:58:55
Uptime 6 days 1 hr. 33 min. 19 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=1521)))
Services Summary...
Service "PLSExtProc"has 1 instance(s).
Instance"PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "dave2" has 1 instance(s).
Instance"dave2", status READY, has 1 handler(s) for this service...
Service "dave2XDB" has 1 instance(s).
Instance"dave2", status READY, has 1 handler(s) for this service...
Service "dave2_XPT" has 1 instance(s).
Instance "dave2", status READY, has 1 handler(s) for this service...
The command completed successfully
我们通常配置net service name,使用的service 和实例名是相同的。
1.2 官网对Service的说明
1.2.1 Purpose
Toobtain detailed information about the database services, instances, and servicehandlers (dispatchers and dedicated servers) to which the listener forwardsclient connection requests.
1.2.2 Syntax
From the operating system:
lsnrctlSERVICES listener_name
From the Listener Control utility:
LSNRCTL>SERVICES listener_name
1.2.3 Arguments
listener_name: The listener name, if thedefault name of LISTENER is not used.
From:
http://download.oracle.com/docs/cd/E11882_01/network.112/e10835/lsnrctl.htm#NETRF112
二. 说明
关于监听的注册问题,之前整理过一篇blog:
Oracle Listener 动态注册 与 静态注册
http://blog.csdn.net/tianlesoftware/article/details/5543166
注册到监听器中的服务值从init.ora文件中的参数service_names取得。如果该参数没有设定值,数据库将拼接init.ora文件中的 db_name和db_domain的值来注册自己。如果选择提供service_names值,您可以使用完全限定的名称(比如 orcl.oracle.com)或缩写的名称(比如orcl)。如果选择缩写的名称并设置了db_domain参数,注册到监听器中的服务将是 service_name值和db_domain值的拼接。例如下面的设置将导致服务orcl.oracle.com被注册到监听器中:
db_domain=oracle.com
service_names=orcl ;
我的这个测试实例是dave2.并且没有配置service_names,所以这里我们配置net service 使用的也是Dave2.
在services 里看到有如下几个service:
Service "PLSExtProc" has 1instance(s).
Service "dave2" has 1instance(s).
Service "dave2XDB" has 1instance(s).
Service "dave2_XPT" has 1instance(s).
2.1 Dave2 service
Dave2是我们实例的service。
2.2 Dave2XDB Service
dave2XDB是XML database的serveice,这个在我之前的blog 有说明:
How to Deinstall and Reinstall XML Database ORA-04063XDB.DBMS_XDBUTIL_INT
http://blog.csdn.net/tianlesoftware/article/details/5587706
How to configure XDB for using ftp and http protocols withASM
http://blog.csdn.net/tianlesoftware/article/details/6337281
MOS 的文档上有详细说明:[ID 1292089.1]
当我们配置dispatchers参数之后,对应的service就可以自动变成可用状态。
SYS@dave2(db2)> show parameterdispatchers
NAME TYPE VALUE
--------------------------- -----------------------------------------
dispatchers string (PROTOCOL=TCP)(SERVICE=dave2XDB)
max_dispatchers integer
可以通过v$service 视图查看:
SYS@dave2(db2)> select name fromv$services;
NAME
----------------------------------------------------------------
dave2XDB
dave2
SYS$BACKGROUND
SYS$USERS
移除XDB 的方法,在10g的OTN上有说明:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/appaman.htm#sthref2384
Removethe dispatcher by removing the Oracle XML DB dispatcher entry from the init.orafile as follows:
dispatchers="(PROTOCOL=TCP)(SERVICE=<sid>XDB)"
If the server parameter file is used, runthe following command when the instance is up and while logged in as SYS:
ALTERSYSTEM RESET dispatchers scope=spfile sid='*';
示例:
SYS@dave2(db2)> ALTER SYSTEM RESETdispatchers scope=spfile sid='*';
System altered.
但是查看dba_services 还是可以查到该值:
SYS@dave2(db2)> select name fromdba_services where name='dave2XDB';
NAME
---------------
dave2XDB
SYS@dave2(db2)> show parameter dispatchers
NAME TYPE VALUE
--------------------------- -----------------------------------------
dispatchers string (PROTOCOL=TCP)(SERVICE=dave2XDB)
max_dispatchers integer
将监听重启一下:
[oracle@db2 ~]$ lsnrctl stop
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 19-JUL-2011 19:34:18
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
The command completed successfully
[oracle@db2 ~]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 19-JUL-2011 19:34:26
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting/u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 -Production
System parameter file is/u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to/u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=1521)))
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version10.2.0.1.0 - Production
Start Date 19-JUL-2011 19:34:27
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=1521)))
Services Summary...
Service "PLSExtProc"has 1 instance(s).
Instance "PLSExtProc",status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@db2 ~]$ lsnrctl service
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 19-JUL-2011 22:43:44
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) forthis service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "dave2" has 1instance(s).
Instance "dave2", status READY, has 1 handler(s) for thisservice...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "dave2_XPT" has 1instance(s).
Instance "dave2", status READY, has 1 handler(s) for thisservice...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully
--SIDXDB 已经没有了
SYS@dave2(db2)>show parameter dispa
NAME TYPE VALUE
----------------------------------------------- ------------------------------
dispatchers string
max_dispatchers integer
通过参数已经看不到了。但通过dba_services还可以查到。
SYS@dave2(db2)> select name fromdba_services where name='dave2XDB';
NAME
----------------------------------------------------------------
dave2XDB
SYS@dave2(db2)> select comp_name,status, version from DBA_REGISTRY where comp_name='Oracle XML Database';
COMP_NAME STATUS VERSION
--------------- ----------------------------------------------------
Oracle XML Data VALID 10.2.0.1.0
如果要停用XML DB 特性,可以drop xdb 服务
SYS@dave2(db2)> execdbms_service.delete_service('dave2XDB');
PL/SQL procedure successfully completed.
然后查看dba_services 视图,就没有该记录了
SYS@dave2(db2)> select name fromdba_services where name='dave2XDB';
no rows selected
2.3. _XPT Service
在MOS 上有文档对XPT 说明 [ID 339940.1]
该service 是给Data Guard 预留的。 如果没有使用DG ,删除该服务没有影响。 停用该service 需要修改一个参数:__dg_broker_service_names. 该参数前面是2个_. 这个需要注意一下。 这个参数是个隐含参数,使用如下SQL 查看:
SYS@dave2(db2)> SELECT ksppinm, ksppstvl, ksppdesc FROM x$ksppi x, x$ksppcv y WHERE x.indx = y.indx AND TRANSLATE (ksppinm, '_','#') LIKE '#%' and ksppinm like '__dg_%';
KSPPINM KSPPSTVL KSPPDESC
-------------------------------------------------- ----------------------------
__dg_broker_service_names dave2_XPT service names for broker use
更多内容参考:
Oracle 参数分类 和 参数的查看方法
http://blog.csdn.net/tianlesoftware/article/details/5583655
要停用该服务,把__dg_broker_service_names参数设置为空就ok了。
SYS@dave2(db2)> altersystem set "__dg_broker_service_names" = '' scope=both;
System altered.
[oracle@db2 ~]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 20-JUL-2011 01:22:17
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version10.2.0.1.0 - Production
Start Date 19-JUL-2011 19:34:27
Uptime 0 days 5 hr. 47 min. 50 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) forthis service...
Service "dave2" has 1instance(s).
Instance "dave2", status READY, has 1 handler(s) for this service...
The command completed successfully
2.4 PLSExtProc Service
先看listener.ora文件,这个文件是在我们安装数据库的时候生成的。
[oracle@db2 admin]$ cat listener.ora
# listener.ora Network Configuration File:/u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db2)(PORT = 1521))
)
)
其中的Listener配置的是实例的监听信息。PLSExtProc 是一个外部程序的配置监听,在默认安装时,会安装一个PL/SQL外部程序(ExtProc)条目在listener.ora中,是oracle为调用外部程序默认配置的监听,它的名字通常是ExtProc或PLSExtProc,但一般不会使用它,可以直接从listener.ora中将这项移除,因为对ExtProc已经有多种攻击手段了,在不使用外部程序时,oracle也是建议删除的。
PLSExtPro是pl/sqlexternal procdure 的意思,就是在pl/sql中调用外部语句,如c,java写的过程。
现在,Oracle已经全面支持JAVA了,这东西也就过时了,之所以继续保留是考虑到兼容以前老版本(Oracle8,9i)的数据库实例。
官网的说明如下:
Youcan use the SID_LIST section of the listener.ora to statically configureservice information for the listener.
The SID_LIST section is required for Oracle8 release 8.0 orOracle7 database services, as well as externalprocedure calls and HeterogeneousServices, and some management tools, including Oracle Enterprise Manager.
SID_LIST_listener_name=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=global_database_name)
(SID_NAME=sid)
(ORACLE_HOME=oracle_home))
(SID_DESC=...))
For later database releases, the listener uses thedynamic service information about the database and instance it has receivedthrough service registration before using statically configured information inthe listener.ora file. Therefore, the SID_LIST is notrequired, unless Oracle Enterprise Manager is used to monitor an Oracle9i orOracle8 database.
From:
http://download.oracle.com/docs/cd/B28359_01/network.111/b28317/listener.htm
所以,要停用PLSExtProc,只需要在listener.ora 里删除这部分配置,然后restart listener 即可。
[oracle@db2 admin]$ cat listener.ora
#SID_LIST_LISTENER =
# (SID_LIST =
# (SID_DESC =
# (SID_NAME = PLSExtProc)
# (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
# (PROGRAM = extproc)
# )
# )
[oracle@db2 admin]$lsnrctl stop
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 20-JUL-2011 01:42:40
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
The command completed successfully
[oracle@db2 admin]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 20-JUL-2011 01:42:53
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting/u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 -Production
System parameter file is/u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to/u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=1521)))
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version10.2.0.1.0 - Production
Start Date 20-JUL-2011 01:42:54
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db2)(PORT=1521)))
The listener supports noservices
The command completed successfully
--这里提示监听没有services,这中情况下,我们的远程端是连不上数据库的。我们通过service 确认一下:
[oracle@db2 admin]$lsnrctl service
LSNRCTL for Linux: Version 10.2.0.1.0 -Production on 20-JUL-2011 01:43:05
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
The listener supports noservices
The command completed successfully
出现这种现象的原因和动态注册和静态注册有关。 在之前的blog里有说明:
Oracle Listener 动态注册 与 静态注册
http://blog.csdn.net/tianlesoftware/article/details/5543166
因为我们没有停数据库,直接重启的监听,而且我们也没有配置静态注册,在这种情况下,就出现了监听没有service的情况,我们只需要使用register命令,将实例注册到监听就ok了。
SYS@dave2(db2)> alter system register;
System altered.
在查看一下service:
[oracle@db2 ~]$ lsnrctl service
LSNRCTL for Linux: Version 10.2.0.1.0 - Productionon 20-JUL-2011 01:45:05
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db2)(PORT=1521)))
Services Summary...
Service "dave2"has 1 instance(s).
Instance "dave2", status READY, has 1 handler(s) for thisservice...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully
现在监听里就只有我们一个实例的service了。