Each database has one or more service names, and the service name is the name provided to the client to connect to the DB instance.
Creating a database defaults to creating a service with the same name as the database, and the default service implements load balancing for all instances, and you can assume that all instances of the database are the preferred nodes for the service created by default.
Manually created service resources differentiate between preferred and alternate nodes, and the client connects to the preferred node of the service resource, regardless of which node it requests, and is connected to the standby node only if the preferred node fails.
Create Service Resource
[Email protected] ~]$ srvctl add service-d king-s sale-r king1-a king2-p basic-e session-m basic-w 5-z 3
-D: Database name
-S: Newly created service name
-R: Preferred Node List
-A: Alternate node list
-P:TAF strategy
-y: Whether to start automatically
-E:TAF type
-Z: Number of retry attempts to connect before failover
-W: The interval of two attempts to connect before failover
Querying Service resource Properties
[Email protected] ~]$ srvctl config service-d king-s sale
Service Name:sale
Service is enabled
Server Pool:king_sale
Cardinality:1
Disconnect:false
Service role:primary
Management policy:automatic
DTP Transaction:false
AQ HA Notifications:false
Failover type:session
Failover Method:basic
TAF Failover Retries:3
TAF Failover Delay:5
Connection Load Balancing Goal:long
Runtime Load Balancing Goal:none
TAF Policy Specification:basic
Edition:
Preferred instances:king1
Available instances:king2
Querying Service Resource Status
[Email protected] ~]$ srvctl status service-d King
Service Sale is not running.
Start Service Resource
[Email protected] ~]$ srvctl start service-d king-s Sale
[Email protected] ~]$ srvctl status service-d King
Service Sale is running on instance (s) king1
COL USERNAME FOR A20COL FAILED_OVER FOR A15SQL> SELECT INST_ID, username,failover_type,failover_method,failed_over from gv$session where username = ' TPCC '; inst_id username FAILOVER_TYPE failover_method failed_ Over---------- -------------------- --------------------------------------- ------------------- ----------- --------------- 1 TPCC SESSION BASIC nosql > select inst_id,username,failover_type,failover_method,failed_over from gv$session where username = ' TPCC '; inst_id username FAILOVER_TYPE FAILOVER_METHOD failed_over---------- -------------------- --------------------------------------- ------------------------------ --------------- 2 TPCC SESSION BASIC yes
Oracle RAC Service Resource Management