Summary of DBMS_SERVICE Subprograms
1、使用 DBMS_SERVICE 创建 service 资源
DBMS_SERVICE.CREATE_SERVICE( service_name IN VARCHAR2, network_name IN VARCHAR2, goal IN NUMBER DEFAULT NULL, dtp IN BOOLEAN DEFAULT NULL, aq_ha_notifications IN BOOLEAN DEFAULT NULL, failover_method IN VARCHAR2 DEFAULT NULL, failover_type IN VARCHAR2 DEFAULT NULL, failover_retries IN NUMBER DEFAULT NULL, failover_delay IN NUMBER DEFAULT NULL, clb_goal IN NUMBER DEFAULT NULL, edition IN VARCHAR2 DEFAULT NULL);
--The network name of the service as used in SQLNet connect descriptors for client connections. This is limited to the NET service_names
character set (see Oracle Database Net Services Reference).
示例:
set linesize 200 col name for a20 col network_name for a20
beginDBMS_SERVICE.CREATE_SERVICE(service_name=>'ractest3',
network_name=>'ractest3',failover_method=>dbms_service.failover_method_basic,failover_type=>dbms_service.failover_type_select,failover_retries=>180,failover_delay=>5);end;/使用 dbms_service 存储过程创建 service 资源时无法知道 service 服务的首选节点列表、备用节点列表,因为这些属性是由 clusterware 管理和控制的。2、使用 DBMS_SERVICE 修改 service 资源beginDBMS_SERVICE.MODIFY_SERVICE(service_name=>'ractest3',failover_method=>dbms_service.failover_method_basic,failover_method=>dbms_service.failover_type_session);end;/3、使用 DBMS_SERVICE 启动 service 资源
beginDBMS_SERVICE.START_SERVICE(service_name=>'ractest3',instance_name=>'rac1');end;/通过上述方法启动 service 资源后,可以通过如下方式查看 service 状态:[oracle@rac1 admin]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 14-AUG-2013 22:27:11 Copyright (c) 1991, 2011, 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.3.0 - Production Start Date 14-AUG-2013 19:59:06 Uptime 0 days 2 hr. 28 min. 5 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/11.2.0/grid/network/admin/listener.ora Listener Log File /u01/app/grid/diag/tnslsnr/rac1/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.8.21)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.8.11)(PORT=1521))) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM1", status READY, has 1 handler(s) for this service... Service "rac" has 1 instance(s). Instance "rac1", status READY, has 1 handler(s) for this service... Service "racXDB" has 1 instance(s). Instance "rac1", status READY, has 1 handler(s) for this service... Service "ractest3" has 1 instance(s). Instance "rac1", status READY, has 1 handler(s) for this service... The command completed successfully
SQL> select * from gv$services where name='ractest3'; INST_ID SERVICE_ID NAME NAME_HASH NETWORK_NAME CREATION_DATE CREATION_DATE_HASH GOAL D AQ_ CLB_G ---------- ---------- ---------- ---------- -------------------- ------------------- ------------------ ------------ - --- ----- 1 7 ractest3 3415106618 ractest3 2013-08-14 22:12:02 2590462208 NONE N NO LONG4、使用 DBMS_SERVICE 停止 service 资源beginDBMS_SERVICE.STOP_SERVICE(service_name=>'ractest3',instance_name=>'rac1');end;/[oracle@rac1 admin]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 14-AUG-2013 22:32:09 Copyright (c) 1991, 2011, 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.3.0 - Production Start Date 14-AUG-2013 19:59:06 Uptime 0 days 2 hr. 33 min. 3 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/11.2.0/grid/network/admin/listener.ora Listener Log File /u01/app/grid/diag/tnslsnr/rac1/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.8.21)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.8.11)(PORT=1521))) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM1", status READY, has 1 handler(s) for this service... Service "rac" has 1 instance(s). Instance "rac1", status READY, has 1 handler(s) for this service... Service "racXDB" has 1 instance(s). Instance "rac1", status READY, has 1 handler(s) for this service... The command completed successfully5、使用 DBMS_SERVICE 删除 service 资源beginDBMS_SERVICE.DELETE_SERVICE(service_name=>'ractest3');end;/SQL> begin 2 DBMS_SERVICE.DELETE_SERVICE(service_name=>'ractest3'); 3 end; 4 / PL/SQL procedure successfully completed. SQL> select * from gv$services where name='ractest3'; no rows selected注意:使用 DBMS_SERVICE 包创建的 service 资源无法注册到 OCR 中,因此无法通过 srvctl 等工具对这些不存在的资源进行管理,当 RAC 节点出现故障时,这些资源也无法随 VIP failover 到幸存的节点上。srvctl 对 service 的管理以及 clusterware 对 service 的高可用性切换都是基于一定的规则调用 dbms_service 包实现的。转载请注明作者出处及原文链接,否则将追究法律责任:
作者:xiangsir
原文链接:http://blog.csdn.net/xiangsir/article/details/9973037
QQ:444367417
MSN:xiangsir@hotmail.com