Oracle RAC has both ha (high availiablity) and lb (loadbalance ). the foundation of its high availability is Failover (Failover ). it means that the failure of any node in the cluster will not affect the user's use, and the user connected to the faulty node will be automatically transferred to the healthy node. In terms of user experience, the user cannot feel this switching.
Oracle 10g RAC failover can be divided into three types:
1. client-side connect time failover
2. TAF
3. Service-side TAF
Note: global_name cannot be set in the listener. ora file, because this parameter will disable connect-time failover and transparent application failover.
I. client-side connect time failover
Client-side connect time failover: if multiple addresses are configured in the client tnsname, the user attempts to connect to the first address in the address table when initiating a connection request, if the connection fails, continue to use the second address until the connection is successful or all the addresses are traversed.
This type of failover features: it only works at the time when a connection is established. That is to say, this type of failover detects node faults only when a connection is initiated. If the node does not respond, the next address in the address list is automatically attempted. Once the connection is established, the node will not be processed if it fails. The client shows that the session is disconnected, and the userProgramThe connection must be established again.
To enable this type of failover, add the Failover = on entry to tnsnames. ora of the client. This parameter is on by default. Therefore, the client can obtain the Failover capability even if this entry is not added.
Example:
RAC =
(Description =
(Address = (Protocol = TCP) (host = rac1-vip) (Port = 1521 ))
(Address = (Protocol = TCP) (host = rac2-vip) (Port = 1521 ))
(Load_balance = yes)
(
CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = RAC)
)
)
Note: rac1-vip, rac2-vip to add to hosts file, otherwise it may not parse.
Ii. TAF (transparent application failover)
Most popular application systems (such as Weblogic and JBoss) have established several persistent connections to the database at startup, and reuse these connections throughout the application lifecycle. The client-side connet time failover works in a way that it does not greatly help application availability.
Therefore, in Oracle 8.1.5, only the new failover mechanism-TAF is introduced. The so-called TAF means that after the connection is established, when the application system runs, if an instance fails, the user connected to the instance will be automatically migrated to other healthy instances. For applications, this migration process is transparent and does not require user intervention. Of course, this transparency should be guided because your uncommitted transactions will be rolled back. The user program with client-side connect time failover is interrupted and a connection error is thrown. the user must restart the application. This method of TAF has greatly improved the HA.
TAF configuration is also very simple. You only need to add the failover_mode configuration item in tnsnames. ora of the client. This entry has four sub-projects to be defined.
1. Method: You can define when to create a connection to your instance. There are two optional values: basic and preconnect.
Basic: the connection that is created to another instance only when a node fault is detected.
Preconnect: A Connection established to all instances at the same time when a connection is established. When a fault occurs, the connection can be switched to another link immediately.
Comparison of the two methods: the basic method has a time delay when failover is used. Although the preconnect method has no time delay, establishing multiple redundant connections consumes more resources, the two are the differences between changing resources by time and changing resources by time.
2. Type: defines how to handle the completed SQL statement when a fault occurs. There are two types: Session and select.
These two methods will automatically roll back uncommitted transactions. The difference lies in the processing of the SELECT statement. For the SELECT statement, the SELECT statement that the user is executing will be transferred to the new instance, the subsequent result set is returned on the new node, while the returned record set is discarded.
Assume that the user is performing a query on node 1, and there are a total of 100 records in the result set. Now 10 records have been returned from node 1, and node 1 is down, the user connection is transferred to node 2. In session mode, the query statement needs to be re-executed. In select mode, the remaining 90 days of records will be returned from node 2, 10 records that have been returned from node 1 will not be returned to the user again. For the user, the switch cannot be felt.
Obviously, in order to implement the select method, Oracle must save more content for each session, including the cursor and user context. More resources are required to change the time of resources.
3. Delay and retries: these two parameters represent the Retry Interval and number of retries respectively.
Example:
RAC =
(Description =
(Address = (Protocol = TCP) (host = rac1-vip) (Port = 1521 ))
(Address = (Protocol = TCP) (host = rac2-vip) (Port = 1521 ))
(Load_balance = yes)
(
CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = RAC)
(
Failover_mode =
(Type = session)
(Method = Basic)
(Retries = 180)
(Delay = 5)
)
)
)
3. service-side TAF
service-sidetaf can be considered as a variant of TAF. First, service-sidetaf is also a TAF. All TAF features include, second, this TAF is configured on the server, unlike the TAF configured on the client.
client-side TAF modifies tnsnames on the client. configured in the ora file. If many clients use this database, they need to change all the computers each time they smile and adjust, which is both inefficient and error-prone. The service-side TAF saves the fail_mode configuration in the database by combining the service, saving all TAF configurations in the data dictionary, thus saving the client configuration work, currently, the TNS file on the client does not require any TAF configuration options.
in terms of configuration parameters, service-side TAF and TAF have an instance role (instance role) concept. The so-called instance role is when multiple instances participate in a service, you can configure which instance is preferentially used to provide services for the user. You have two optional roles.
preferred: the preferred instance. instances with this role are given priority to provide services.
available: A backup instance. When a user connects to a prefferred instance, the preferred instance is not available before it is transferred to the availbale instance.
to use server-side TAF, you must configure the service. The service can be created when a database is created or modified after the database is created. You can use the dbca Configuration Wizard or command line configuration.
3.1 configure service with dbca
1 ). run dbca and select Oracle RAC Application Clusters database
2 ). on the second page, choose services management
3 ). on the third page, the RAC database list is displayed. You can select the database in which you want to configure the service
4 ). on the serice configuration page, click Add to create a new service and enter the service name. Define the instance role in the instance list box, select the service1 as preferred (preferred instance), and service2 as availiable (Backup instance ). TAF policy has three options: None, basic, and pre-connect. Select basic. Click Finish to complete service configuration.
5) after the service configuration is completed, the service starts automatically.
3.2 using the srvctl command to configure the service
using the command line to configure the service is very useful for remote maintenance. First, let's take a look at the relevant commands
1) create a service
# srvctl add service-D -S -R "preferred-instance-list"-a "available-instance-list "-P
where TAF-policy is optional: basic and preconnect. Example:
srvctl add service-D Rac-s service2-R "Rac1, rac2"-a "rac3, rac4"-P basic
note: in srvctl add service, only perferred creates a service. Register a service of Ora. Raw. DMM. raw1.srv in OCR.
2) view configuration information
# srvctl config service-D database-name [-s service-name] [-A]
If "-S Service-name" is not specified here", the configuration of all services is displayed, including preferred and available instance. use the-A option to display TAF information.
3) whether to automatically run the service
when the database is started, all services are automatically started. Sometimes this feature needs to be disabled for maintenance purposes and then started after maintenance is complete.
# srvctl enable/disable service-D database-name-s service-name-I instance-name
4) start the service
# Srvctl start service-D <database-Name>-S <service-Name>-I instance-name-o start-Option-C connect-string-Q
If no service-name is specified, all services are started. You can use commas to separate multiple services. -I indicates that the service is started on that instance.
5) stop the service
# Srvctl stop service-D <database-Name>-S <service-Name>-I instance-name-C connect-string-Q-F
The-F option can forcibly disable the service and interrupt the connection of all its users.
6) view service status
# Srvctl Status Service-D <database-Name>-s service-name-I instance-name-F-V
Where-F can display the disable instance information, while-V can display the detailed output
7) delete a service
# Srvctl remove service-D database-name-s service-name-I instance-name [-F]
Note: When Using srvctl to create a service, you must note that the TAF policy option must be configured using the dbms_service package.
Example:
Begin
Dbms_service.modify_service (
SERVICE_NAME = '> service1 ',
Failover_method => dbms_service.failover_method_basic,
Failover_type => dbms_service.failover_type_select,
Failover_retries = & gt; 180,
Failover_delay => 5
);
End;
3.3 service configuration considerations
1). The service name of the database is specified using the SERVICE_NAME parameter. A database can have multiple service names, but the maximum SERVICE_NAME is 4 kb. Do not manually modify this parameter.
2) A maximum of 64 services can be created. Each database has two implicit services, so there are only 62 services left for users. You cannot modify the configurations of these two hidden services, or start or stop these two Services manually. The two implied services are: sys $ background and sys $ users.
3) When dbca is used to configure the service, dbca automatically updates OCR and starts the service. when the service is deleted, the service is stopped and the OCR is updated.
4) When srvctl is used, the command only updates the configuration in OCR and does not update the information in data dctionary and listener. Therefore, you need to use the dbma_servie package to update the data dictionary and manually change the Listener Configuration File. Therefore, we recommend that you use dbca to configure and change the service configuration.
5) if the client wants to connect to the database using the service method, it must reference the database using the SERVICE_NAME method in the TNS entry. For example:
RAC =
(Description =
(Address = (Protocol = TCP) (host = rac1-vip) (Port = 1521 ))
(Address = (Protocol = TCP) (host = rac2-vip) (Port = 1521 ))
(Load_balance = yes)
(
CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = RAC)
)
)
Note: No matter whether you use the dbca tool or the srvctl command to configure the service, you cannot configure the TAF type, delay, and retries attributes. You must use the dbms_service package to modify these attributes.
Iv. srvctl command test instance
First, check the RAC startup status:
[Root @ raw1 bin] #./crs_stat-T
Name type target State host
------------------------------------------------------------
Ora. Raw. DB application online raw1
Ora. Raw. Raw. CS application online raw1
Ora... aw1.srv application online raw1
Ora... aw2.srv application online raw2
Ora... w1.inst application online raw1
Ora... w2.inst application online raw2
Ora... sm1.asm application online raw1
Ora... w1.lsnr application online raw1
Ora. raw1.gsd application online raw1
Ora. raw1.ons application online raw1
Ora. raw1.vip application online raw1
Ora... sm2.asm application online raw2
Ora... w2.lsnr application online raw2
Ora. raw2.gsd application online raw2
Ora. raw2.ons application online raw2
Ora. raw2.vip application online raw2
[Root @ raw1 bin] # ps-Ef | grep SMON
Root 17483 3479 0 00:00:00 pts/1 grep SMON
Oracle 26561 1 0? 00:00:01 asm_smon _ + ASM1
Oracle 27082 1 0? 00:00:05 ora_smon_raw1
Everything works.
1) view existing services
[Root @ raw1 bin] # Su-Oracle
[Oracle @ raw1 ~] $ Export oracle_sid = raw1
[Oracle @ raw1 ~] $ Sqlplus/nolog
SQL * Plus: Release 10.2.0.1.0-production on Wed Mar 3 07:45:36 2010
Copyright (c) 1982,200 5, Oracle. All rights reserved.
SQL> Conn/As sysdba
Connected.
SQL> show parameter Service
Name type value
-----------------------------------------------------------------
Service_names string raw
SQL>
2) use the srvctl command to create a DMM Service
[Oracle @ raw2 bin] $ srvctl add service-d Raw-s DMM-R "raw1, raw2"-P basic
[Oracle @ raw2 bin] $ crs_stat-T
Name type target State host
------------------------------------------------------------
Ora. Raw. DB application online raw1
Ora. Raw. DMM. CS application offline
Ora... aw1.srv application offline
Ora... aw2.srv application offline
Ora... w1.inst application online raw1
Ora... w2.inst application online raw2
Ora... sm1.asm application online raw1
Ora... w1.lsnr application online raw1
Ora. raw1.gsd application online raw1
Ora. raw1.ons application online raw1
Ora. raw1.vip application online raw1
Ora... sm2.asm application online raw2
Ora... w2.lsnr application online raw2
Ora. raw2.gsd application online raw2
Ora. raw2.ons application online raw2
Ora. raw2.vip application online raw2
[Oracle @ raw2 bin] $ srvctl add service-d Raw-s DMM-r raw1-A raw2-P basic
Note: In srvctl add service, only perferred creates a service. Register a service of Ora. Raw. DMM. raw1.srv in OCR.
3) Confirm that the service is successfully created. Offline indicates that the service has not been started.
[Oracle @ raw2 bin] $ crs_stat-T
Name type target State host
------------------------------------------------------------
Ora. Raw. DB application online raw1
Ora. Raw. DMM. CS application offline
Ora... aw1.srv application offline
Ora. Raw. Raw. CS application online raw1
Ora... aw1.srv application online raw1
Ora... w1.inst application online raw1
Ora... w2.inst application online raw2
Ora... sm1.asm application online raw1
Ora... w1.lsnr application online raw1
Ora. raw1.gsd application online raw1
Ora. raw1.ons application online raw1
Ora. raw1.vip application online raw1
Ora... sm2.asm application online raw2
Ora... w2.lsnr application online raw2
Ora. raw2.gsd application online raw2
Ora. raw2.ons application online raw2
Ora. raw2.vip application online raw2
4) configure the service to start automatically
[Oracle @ raw2 bin] $ srvctl enable service-d Raw-s DMM
PRKP-1018: Service DMM already enabled.
5) start the service
[Oracle @ raw2 bin] $ srvctl start service-d Raw-s DMM
6) confirm the service status. Online indicates that the instance has been started.
[Oracle @ raw2 bin] $ crs_stat-T
Name type target State host
------------------------------------------------------------
Ora. Raw. DB application online raw1
Ora. Raw. DMM. CS application online raw1
Ora... aw1.srv application online raw1
Ora. Raw. Raw. CS application online raw1
Ora... w1.inst application online raw1
Ora... w2.inst application online raw2
Ora... sm1.asm application online raw1
Ora... w1.lsnr application online raw1
Ora. raw1.gsd application online raw1
Ora. raw1.ons application online raw1
Ora. raw1.vip application online raw1
Ora... sm2.asm application online raw2
Ora... w2.lsnr application online raw2
Ora. raw2.gsd application online raw2
Ora. raw2.ons application online raw2
Ora. raw2.vip application online raw2
the new service is automatically added to the initial parameters:
SQL> show parameter service
name type value
----------------------------- ------------------------
service_names string raw, DMM
7) use service TAF to modify the configuration, and use the dbms_service.modify_service package.
SQL> begin
Dbms_service.modify_service (
SERVICE_NAME => 'dmm ',
Failover_method => dbms_service.failover_method_basic,
Failover_type => dbms_service.failover_type_select,
Failover_retries = & gt; 180,
Failover_delay => 5
);
End;
/
PL/SQL procedure successfully completed.
8) Confirm that the parameter has taken effect.
SQL> select name, failover_method, failover_type, goal, clb_goal from dba_services;
Name failover_method failover_type goal clb_g
------------------------------------------------
Sys $ background none short
Sys $ users none short
Seeddataxdb long
Seeddata. Regress. RDB long
Rawxdb long
Raw long
DMM basic select long
7 rows selected.
9) You can also run the srvctl command to view the configuration information.
[Oracle @ raw2 bin] $ srvctl config service-d Raw-s DMM-
DMM Pref: raw1 avail: raw2 TAF: Basic
10) delete a service
Disable service first:
[Oracle @ raw2 bin] $ srvctl stop service-d Raw-s DMM
[Oracle @ raw2 bin] $ srvctl disable service-d Raw-s DMM
Delete service:
[Oracle @ raw2 bin] $ srvctl remove service-d Raw-s DMM
DMM Pref: raw1 avail: raw2
Service DMM is disabled.
Remove service DMM from the database raw? (Y/[N]) y
If this command is unclear, we can add the-F parameter.
[Oracle @ raw2 bin] #./srvctl remove service-d Raw-s DMM-F
The OCR information has been deleted, but the service content is still in the data dictionary. Continue to clear the content in the data dictionary.
First, view the data dictionary content:
SQL> select name, failover_method, failover_type, goal, clb_goal from dba_services;
Name failover_method failover_type goal clb_g
---------------------------------------------------------------
Sys $ background none short
Sys $ users none short
Seeddataxdb long
Seeddata. Regress. RDB long
Rawxdb long
Raw long
DMM basic select long
7 rows selected.
Clear the contents in the data dictionary:
SQL> begin
2 dbms_service.delete_service (SERVICE_NAME => 'dmm ');
3 end;
4/
PL/SQL procedure successfully completed.
Query the data dictionary again without data. Cleared
SQL> select name, failover_method, failover_type, goal, clb_goal from dba_services;
Name failover_method failover_type goal clb_g
---------------------------------------------------------------
Sys $ background none short
Sys $ users none short
Seeddataxdb long
Seeddata. Regress. RDB long
Rawxdb long
Raw long
6 rows selected.