oracle rac srvctl create service

oracle rac创建service的另外一个方法是使用srvctl工具,使用srvctl工具的好处是无需gui的配合,直接在命令行即可搞定了。

//先看看srvctl add service的使用方法
[oracle@rac1 ~]$ srvctl add service -h
Usage: srvctl add service -d <name> -s <service_name> -r “<preferred_list>” [-a “<available_list>”] [-P <TAF_policy>]
-d <name> Unique name for the database
-s <service> Service name
-r “<pref_list>” List of preferred instances
-a “<avail_list>” List of available instances
-P <TAF_policy> TAF policy (NONE, BASIC, or PRECONNECT)
Usage: srvctl add service -d <name> -s <service_name> -u {-r “<new_pref_inst>” | -a “<new_avail_inst>”}
-d <name> Unique name for the database
-s <service> Service name
-u Add a new instance to service configuration
-r <new_pref_inst> Name of new preferred instance
-a <new_avail_inst> Name of new available instance
-h Print usage
//添加一个service,名字叫service2,rac1作为pre_list成员,rac2作为avail_list成员,TAF policy配置为PRECONNECT
[oracle@rac1 ~]$ srvctl add service -d rac -s service2 -r “rac1” -a “rac2” -P PRECONNECT

//crs_stat 查看一下添加的结果,有两个状态为offline的。
[oracle@rac1 ~]$ crs_stat -t
Name Type Target State Host
————————————————————
ora.rac.db application ONLINE ONLINE rac1
ora….c1.inst application ONLINE ONLINE rac1
ora….c2.inst application ONLINE ONLINE rac2
ora….ice1.cs application ONLINE ONLINE rac1
ora….ac1.srv application ONLINE ONLINE rac1
ora….ice2.cs application OFFLINE OFFLINE
ora….ac1.srv application OFFLINE OFFLINE
ora….C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora….C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
//新增加的两个offline的资源
NAME=ora.rac.service2.cs
TYPE=application
TARGET=OFFLINE
STATE=OFFLINE

NAME=ora.rac.service2.rac1.srv
TYPE=application
TARGET=OFFLINE
STATE=OFFLINE

//service创建完毕后,需要配置这个服务,将其激活,但此操作似乎是多余的,接下来会收到报错
[oracle@rac1 ~]$ srvctl enable service -d rac -s service2
PRKP-1018 : Service service2 already enabled.

//来启动enable完毕的service
[oracle@rac1 ~]$ srvctl start service -d rac -s service2
//刚才offline的两个服务自动被启动了,状态为online
[oracle@rac1 ~]$ crs_stat -t
Name Type Target State Host
————————————————————
ora.rac.db application ONLINE ONLINE rac1
ora….c1.inst application ONLINE ONLINE rac1
ora….c2.inst application ONLINE ONLINE rac2
ora….ice1.cs application ONLINE ONLINE rac1
ora….ac1.srv application ONLINE ONLINE rac1
ora….ice2.cs application ONLINE ONLINE rac1
ora….ac1.srv application ONLINE ONLINE rac1
ora….C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora….C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
//使用srvctl config来查看service的状态,可以看到新创建的service2的一些信息,这里TAF选择的是PRECONNECT。
[oracle@rac1 ~]$ srvctl config service -d rac -a
service1 PREF: rac1 AVAIL: rac2 TAF: basic
service2 PREF: rac1 AVAIL: rac2 TAF: PRECONNECT
//srvctl工具创建的服务能够自动添加到spfile中,show parameter已经能够查到其踪迹了
SQL> show parameter service

NAME TYPE VALUE
———————————— ———– ——————————
service_names          string           service1,   rac.world,    service2
//service2的添加已经反应到了spfile参数文件中(不知道如果是pfile会如何)

//查看一下在数据字典中添加了什么内容?
1* select name,FAILOVER_METHOD,FAILOVER_TYPE,FAILOVER_RETRIES,FAILOVER_DELAY from dba_services
SQL> /

NAME FAILOVER_METHOD FAILOVER_TYPE FAILOVER_RETRIES FAILOVER_DELAY
—————————— —————————— —————————— —————- ————–
SYS$BACKGROUND
SYS$USERS
seeddataXDB
seeddata
racXDB
rac.world
service1                                        BASIC                                 SELECT                     170                           4
service2
service2_PRECONNECT

//可以看到在数据字典中,添加了两行与service2相关的内容,name字段中有service2、service2_PRECONNECT
//其中service2在创建过程中,TAF的method选择的是PRECONNECT,这里与之前的basic不同。
//与basic不同的是,可见在dba_services中,name字段多了两行,service2与service_PRECONNECT

//但是在TAF policy的4个选项(method,type,retry,delay)也同样没有配置上,需要借助dbms包来解决。

//使用dbms_service包来配置TAF的四个策略选项,method配置为PRECONNECT,type配置为session,retries=150,delay设置为5
//shit…正当我在模仿如下的脚本准备相应的脚本时,无意间查了一些dbms_service中关于method如何设置为PRECONNECT时,还自己意淫相应的方法为failover_method_preconnect是发现,如下一段文字:

//
Server side TAF method is BASIC. BASIC is the only value currently supported.
This means that a new connection is established at failure time.
It is not possible to pre-establish a backup connection. (which is to say, PRECONNECT is not supported)
//


begin
dbms_service.modify_service(
service_name=>’service2′,
failover_method=>dbms_service.failover_method_basic,
failover_type=>dbms_service.failover_type_session,
failover_retries=>160,
failover_delay=>5,
);
end;
/

//我日….悲催啊。。。”basic is the only value current supported…..”

//得,srvctl更改service为的method为basic,重新来
[oracle@rac1 ~]$ srvctl modify service -d rac -s service2 -h
Usage: srvctl modify service -d <name> -s <service_name> -i <old_inst_name> -t <new_inst_name> [-f]
-d <name> Unique name for the database
-s <service> Service name
-i <old_inst> Old instance name
-t <new_inst> New instance name
-f Disconnect all sessions during stop or relocate service operations
Usage: srvctl modify service -d <name> -s <service_name> -i <avail_inst_name> -r [-f]
-d <name> Unique name for the database
-s <service> Service name
-i <inst> Instance name
-r Upgrade instance to preferred
-f Disconnect all sessions during stop or relocate service operations
Usage: srvctl modify service -d <name> -s <service_name> -n -i <prefered_inst> [-a <available_list>] [-f]
-d <name> Unique name for the database
-s <service> Service name
-n Modify service configuration
-r “<pref_list>” List of preferred instances
-a “<avail_list>” List of available instances
-f Disconnect all sessions during stop or relocate service operations
Usage: srvctl modify service -d <name> -s <service_name> -P <TAF_policy> [-f]
-d <name> Unique name for the database
-s <service> Service name
-P <TAF_policy> TAF policy (NONE, BASIC, or PRECONNECT)
-f Disconnect all sessions during stop or relocate service operations
-h Print usage

//执行更改
[oracle@rac1 ~]$ srvctl modify service -d rac -s service2 -P BASIC
//查看状态
[oracle@rac1 ~]$ srvctl config service -d rac -a
service1 PREF: rac1 AVAIL: rac2 TAF: basic
service2 PREF: rac1 AVAIL: rac2 TAF: BASIC
//crs stack中注册的service相关的两个resource都依旧是online的。
[oracle@rac1 ~]$ crs_stat -t
Name Type Target State Host
————————————————————
ora.rac.db application ONLINE ONLINE rac1
ora….c1.inst application ONLINE ONLINE rac1
ora….c2.inst application ONLINE ONLINE rac2
ora….ice1.cs application ONLINE ONLINE rac1
ora….ac1.srv application ONLINE ONLINE rac1
ora….ice2.cs application ONLINE ONLINE rac1
ora….ac1.srv application ONLINE ONLINE rac1
ora….C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora….C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2

//再看看spfile中的参数,spfile中的记录并没有什么变化。
SQL> show parameter service

NAME TYPE VALUE
———————————— ———–     ——————————
service_names                string               service1,   rac.world,    service2

//看看dba_services中,数据字典中的记录。
SQL> l
1* select name,FAILOVER_METHOD,FAILOVER_TYPE,FAILOVER_RETRIES,FAILOVER_DELAY from dba_services
SQL> /

NAME FAILOVER_METHOD FAILOVER_TYPE FAILOVER_RETRIES FAILOVER_DELAY
—————————— —————————— —————————— —————- ————–
SYS$BACKGROUND
SYS$USERS
seeddataXDB
seeddata
racXDB
rac.world
service1 BASIC SELECT 170 4
service2
service2_PRECONNECT
//dba_services中似乎没有什么反应,依旧存在一个service2_PRECONNECT的东西,再看看lsnrctl中的记录信息
LSNRCTL> set current_listener listener_rac1
Current Listener is listener_rac1
LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.201.149)(PORT=1521)(IP=FIRST)))
STATUS of the LISTENER
————————
Alias LISTENER_RAC1
Version TNSLSNR for Linux: Version 10.2.0.5.0 – Production
Start Date 20-AUG-2012 18:13:34
Uptime 3 days 19 hr. 11 min. 7 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /opt/app/oracle/product/10.2.0/db_1/network/log/listener_rac1.log
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.201.149)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.201.128)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Services Summary…
Service “rac.world” has 2 instance(s).
Instance “rac1”, status READY, has 2 handler(s) for this service…
Instance “rac2”, status READY, has 1 handler(s) for this service…
Service “racXDB.world” has 2 instance(s).
Instance “rac1”, status READY, has 1 handler(s) for this service…
Instance “rac2”, status READY, has 1 handler(s) for this service…
Service “rac_XPT.world” has 2 instance(s).
Instance “rac1”, status READY, has 2 handler(s) for this service…
Instance “rac2”, status READY, has 1 handler(s) for this service…
Service “service1.world” has 1 instance(s).
Instance “rac1”, status READY, has 2 handler(s) for this service…
Service “service2.world” has 1 instance(s).
Instance “rac1”, status READY, has 2 handler(s) for this service…
Service “service2_PRECONNECT.world” has 1 instance(s).
Instance “rac2”, status READY, has 1 handler(s) for this service…
The command completed successfully
//监听中还是记录了一些service2相关的信息,但是service2以及service2_PRECONNECT多少让人有些疑惑,不知道是modify service之前的状态还是之后的状态。

//即使reload listener之后,还是如下的状态(lsnrctl services查看)
Service “service2.world” has 1 instance(s).
Instance “rac1”, status READY, has 2 handler(s) for this service…
Handler(s):
“DEDICATED” established:0 refused:0 state:ready
REMOTE SERVER
(ADDRESS=(PROTOCOL=TCP)(HOST=rac1-vip.localdomain)(PORT=1521))
“DEDICATED” established:0 refused:0 state:ready
LOCAL SERVER
Service “service2_PRECONNECT.world” has 1 instance(s).
Instance “rac2”, status READY, has 1 handler(s) for this service…
Handler(s):
“DEDICATED” established:0 refused:0 state:ready
REMOTE SERVER
(ADDRESS=(PROTOCOL=TCP)(HOST=rac2-vip.localdomain)(PORT=1521))
The command completed successfully

//也罢,继续使用dbms包完成剩下在数据字典中的更改工作。method=basic,type=session,retry=150,delay=5

begin
dbms_service.modify_service(
service_name=>’service2′,
failover_method=>dbms_service.failover_method_basic,
failover_type=>dbms_service.failover_type_session,
failover_retries=>160,
failover_delay=>5
);
end;
/

//查看dba_services中的状态
SQL> select name,FAILOVER_METHOD,FAILOVER_TYPE,FAILOVER_RETRIES,FAILOVER_DELAY from dba_services;

NAME FAILOVER_METHOD FAILOVER_TYPE FAILOVER_RETRIES FAILOVER_DELAY
—————————— —————————— —————————— —————- ————–
SYS$BACKGROUND
SYS$USERS
seeddataXDB
seeddata
racXDB
rac.world
service1                     BASIC SELECT                                    170                        4
service2                  BASIC SESSION                                    160                          5
service2_PRECONNECT

–EOF—