Friday, September 28, 2018

Creating services with srvctl


In a RAC environment we can create services and run these services on a specific RAC instance/node (or a set of instances/nodes). This makes it possible for the applications to connect to specific instances. In this article I would explain how we create a service and make it run on the instance(s) of our choice, and make it automatically failover to another instance/node if current instance node goes down.

Following set of commands/outpts shows how we create a new service for my database that will run on instance1/node1 (as specified in “-preferred” argument, and failover automatically to instance2/node2 (as specified in argument “-avialable” ), in case instance1/node1 goes down.

-- Create a service. For Oracle versions lower than 12c, use –d, -s, -r, and -a arguments respectively.
[oracle@salman11 ~]$ srvctl add service -db salman12 -service salman12_service -preferred salman121 -available salman122

-- Start the service. For Oracle verions lower than 12c, use –d, and –s arguments respectively.
[oracle@salman11 ~]$ srvctl start service -db salman12 -service salman12_service

-- Check status of service.  For Oracle verions lower than 12c, use –d, and –s arguments respectively
[oracle@salman11 ~]$ srvctl status service -db salman12 -service salman12_service
Service salman12_service is running on instance(s) salman121

-- Check configuration of service. For Oracle verions lower than 12c, use –d, and –s arguments respectively.
[oracle@salman11 ~]$ srvctl config service -db salman12 -service salman12_service
Service name: salman12_service
Server pool:
Cardinality: 1
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Global: false
Commit Outcome: false
Failover type:
Failover method:
TAF failover retries:
TAF failover delay:
Failover restore: NONE
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: NONE
Edition:
Pluggable database name:
Maximum lag time: ANY
SQL Translation Profile:
Retention: 86400 seconds
Replay Initiation Time: 300 seconds
Drain timeout:
Stop option:
Session State Consistency: DYNAMIC
GSM Flags: 0
Service is enabled
Preferred instances: salman121
Available instances: salman122
CSS critical: no

You can also check she status of service using crsctl command.
[grid@salman11 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details      
--------------------------------------------------------------------------------
ora.salman12.db
      1        ONLINE  ONLINE       salman11                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
      2        ONLINE  ONLINE       salman12                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
ora.salman12.salman12_service.svc
      1        ONLINE  ONLINE       salman11                 STABLE

If you check status of the listener, you will see this service registered with the listener on node1 (where instance salman121 is running)
[grid@salman11 ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 27-APR-2017 15:16:53

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                27-APR-2017 13:39:47
Uptime                    0 days 1 hr. 37 min. 5 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/12.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/salman11/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.231.231.50)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.231.231.60)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=salman11.salman.com)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/product/12.2.0/dbhome_1/admin/salman12/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_DATA" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "4e202176e59f367be05332e7e7c0461b.salman.com" has 1 instance(s).
  Instance "salman121", status READY, has 1 handler(s) for this service...
Service "salman12.salman.com" has 1 instance(s).
  Instance "salman121", status READY, has 1 handler(s) for this service...
Service "salman12XDB.salman.com" has 1 instance(s).
  Instance "salman121", status READY, has 1 handler(s) for this service...
Service "salman12_service.salman.com" has 1 instance(s).
  Instance "salman121", status READY, has 1 handler(s) for this service...
Service "salman12pdb.salman.com" has 1 instance(s).
  Instance "salman121", status READY, has 1 handler(s) for this service...
The command completed successfully

If I power off the node salman11, service will fail over to instance2/node2 as can be seen bellow. After the failover, listener on node2 has also registered the service.
--For Oracle versions lower than 12c, use –d, and –s arguments respectively

[grid@salman12 ~]$ srvctl status service -db salman12 -service salman12_service
Service salman12_service is running on instance(s) salman122

[grid@salman11 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details      
--------------------------------------------------------------------------------
ora.salman12.db
      1        ONLINE  OFFLINE                               Instance Shutdown,ST
                                                             ABLE
      2        ONLINE  ONLINE       salman12                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
ora.salman12.salman12_service.svc
      2        ONLINE  ONLINE       salman12                 STABLE


[grid@salman12 ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 27-APR-2017 15:21:11

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                26-APR-2017 15:40:41
Uptime                    0 days 23 hr. 40 min. 30 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/12.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/salman12/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.231.231.51)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.231.231.61)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=salman12.salman.com)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/product/12.2.0/dbhome_1/admin/salman12/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "+ASM_DATA" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "4e202176e59f367be05332e7e7c0461b.salman.com" has 1 instance(s).
  Instance "salman122", status READY, has 1 handler(s) for this service...
Service "salman12.salman.com" has 1 instance(s).
  Instance "salman122", status READY, has 1 handler(s) for this service...
Service "salman12XDB.salman.com" has 1 instance(s).
  Instance "salman122", status READY, has 1 handler(s) for this service...
Service "salman12_service.salman.com" has 1 instance(s).
  Instance "salman122", status READY, has 1 handler(s) for this service...
Service "salman12pdb.salman.com" has 1 instance(s).
  Instance "salman122", status READY, has 1 handler(s) for this service...
The command completed successfully
[grid@salman12 ~]$

When instance1/node1 comes back online, service would still be running on instance2/node2, and will not automatically relocate to its preferred instance/node. We would need to do this manually as follows
-- Check where is service currently running. It is on node2 (saman12) after we shutdown the node1
[grid@salman11 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details      
--------------------------------------------------------------------------------
...
...
...
ora.salman12.db
      1        ONLINE  ONLINE       salman11                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
      2        ONLINE  ONLINE       salman12                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
ora.salman12.salman12_service.svc
      1        ONLINE  ONLINE       salman12                 STABLE
...
...
...
--------------------------------------------------------------------------------

-- Now let relocate service back to instance1/node1. For Oracle verions older than 12, use options –d, -s, -i, -t respectively.
[grid@salman11 ~]$ srvctl relocate service -db salman12 -service salman12_service -oldinst salman122 -newinst salman121

-- We can see that service has now been relocated back to node1.
[grid@salman11 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details      
--------------------------------------------------------------------------------
...
...
...
ora.salman12.db
      1        ONLINE  ONLINE       salman11                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
      2        ONLINE  ONLINE       salman12                 Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /dbhome_1,STABLE
ora.salman12.salman12_service.svc
      2        ONLINE  ONLINE       salman11                 STABLE
...
...
...
--------------------------------------------------------------------------------
[grid@salman11 ~]$

No comments:

Post a Comment

Popular Posts - All Times