we can use the DBMS_SERVICE procedures and SRVCTL to create/manage Oracle services. Anyway Oracle recommends using srvctl to manage services, if we use Oracle Clusterware and Oracle Restart (DBMS_SERVICE procedures do not update the CRS attributes).
Example (create service by using srvctl):
$ srvctl add service -d orcl -s service1 -r orcl1
$ lsnrctl services | grep service1
--- Not Found ---
$ ./crsstat service1
HA Resource Target State (Host)
----------- ------ -----
ora.orcl.service1.svc OFFLINE OFFLINE
$ srvctl start service -d orcl -s service1
$ ./crsstat service1
HA Resource Target State (Host)
----------- ------ -----
ora.orcl.service1.svc ONLINE ONLINE on rhel5-test
$ lsnrctl services | grep service1
Service "service1" has 1 instance(s).
Example (create service by using DBMS_SERVICE):
SQL> exec DBMS_SERVICE.CREATE_SERVICE('service2','service2');"DBMS_SERVICE procedures do not update the CRS attributes"... So,we don't see ;)
PL/SQL procedure successfully completed.
$ ./crsstat service2
HA Resource Target State (Host)
----------- ------ -----
$ lsnrctl services | grep service2
--- Not Found ---
SQL> show parameter service_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string service1
SQL> alter system set service_names='service1,service2';
System altered.
SQL> show parameter service_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string service1,service2
$ lsnrctl services | grep service2
Service "service2" has 1 instance(s).
$ ./crsstat service2
HA Resource Target State (Host)
----------- ------ -----
Reference:
--- begin crsstat begin ---
#!/bin/bash
if [ $# -le 1 ]
then
GREP_KEY=$1
else
echo "Please Check arguments."
echo
echo "./crsstat [Word]"
echo
echo " [Word] use to find word in result "
echo " ./crsstat listen"
exit 0
fi
if [ -z $ORA_CRS_HOME ]
then
ORA_CRS_HOME=$CRS_HOME
if [ ! -d $ORA_CRS_HOME ]
then
echo "Please Check ORA_CRS_HOME Environment ($ORA_CRS_HOME)"
exit 1
fi
fi
AWK=/usr/bin/awk
if [ ! -x $AWK ]
then
AWK=/bin/awk
fi
$AWK \
'BEGIN {printf "%-45s %-10s %-12s\n", "HA Resource", "Target", "State (Host)"; printf "%-45s %-10s %-12s\n", "-----------", "------", "-----";}'
$ORA_CRS_HOME/bin/crs_stat | $AWK \
'BEGIN { FS="="; state = 0; }
$1~/NAME/ && $2~/'$GREP_KEY'/ {appname = $2; state=1;}
state == 0 {next;}
$1~/TARGET/ && state == 1 {apptarget = $2; state=2;}
$1~/STATE/ && state == 2 {appstate = $2; state=3;}
state == 3 {printf "%-45s %-10s %-12s\n", appname, apptarget, appstate; state=0;}'
--- end crsstat ---
2 comments:
Thanks for the excellent article ka~
:P
Post a Comment