In general, Oracle 11g R2 RAC provides the following features:
- High Availability: shared-everything mode ensures that services are not stopped when a single node fails, and other nodes in the cluster will take over quickly
- Scalability: multiple nodes share the load and can provide processing capabilities far beyond that of a single database. Addition and deletion of nodes can be completed online without downtime
- Ease of use: multiple databases can be added to a cluster.
- Low Cost: RAC can be deployed on standard hardware. The cost saved on the hardware offset the cost of purchasing the license.
Oracle 11g r2 also provides a new feature called RAC One Node. Oracle finds that the deployment of some RAC is purely for high availability, and virtualization is increasingly used by users and has become a new trend. Oracle One Node is built on the following foundations: Oracle Clusterware, Oracle ASM, and Oracle database.
Let's take a look at the RAC structure.
Compared with standalone databases, RAC requires a shared storage, a private network for internal communication within the cluster, a public network for connection to applications and clients, and a virtual IP address to improve the connection speed when a node fails, when a node fails, its virtual ip address immediately points to the ip address of another node (if no vip address is configured, when a node fails, a new connection will wait, until the time out occurs in the communication with the ip address of the node ).
There are two Connection Methods for Failover connection configuration to achieve database connection failover
1. TAF (Transparent Application Failover) let's take a look at the official documentation. TAF allows Oracle Net to transfer an invalid connection from the fault point to another listener. the user can use this new connection to continue the unfinished work. This is a client-side function. TAF can be configured to connect to the client (Transparent Network Substrate) TNS connection string, or use the server service. If the two methods are used at the same time, the server-side service configuration is used. TAF can work in two modes: session failover and select failover. The former will rebuild the failed connection when failover, and the latter will be able to continue the unfinished query in the process (if the previous session of failover is retrieving data from a cursor, the new session will re-run the select statement in the same snapshot and return the remaining rows ). If the session performs the DML operation and is not committed at failover, after failover, if a new operation is performed without rollback, an error message ORA-25402 will be received: transaction must roll backTAF is used in dataguard and can be used for automatic failover.
A typical TNS connection string that uses TAF is as follows: NEWSDB =
(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 = dyora)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
)
Failover_mode
Failover_mode Parameter |
Description |
BACKUP |
The Network Service name of the standby connection. If you use the preconnect connection method, you must specify this parameter. |
DELAY |
The connection Retry Interval (in seconds ). If the RETRIES parameter is specified, if this parameter is not specified, the default value is 1 second. If callback is registered, this parameter is ignored. |
METHOD |
Set the failover method. Basic: the listener that tries to connect to the slave instance only when the slave instance is failover. preconnect: a connection is also generated on the slave instance every time you connect to the database to achieve faster switching. |
RETRIES |
The number of times a connection is attempted after a failover error occurs. If the DELAY parameter is specified, RETRIES is set to 5 times by default. If callback is registered, this parameter is ignored. |
TYPE |
By default, OCI provides three types: session: if the user's connection is lost, it will be re-created on the slave node; select: In addition to re-establishing the connection, data will continue to be obtained from the opened cursor, if this method is used, normal select operations will also generate overhead on the client; none: default value, you can also specify to disable the failover Function |
2. FCF (Fast Connect Failover) oracle11g provides the FCF method to Connect to the database. It supports JDBC Thin and jdbc oci drivers; and connection cache (implicit connection cache) collaborative work provides higher connection performance and high availability. You can set it in the application code without the need to configure additional conditions: the implicit connection cache is enabled, FCF needs to work with the JDBC connection cache mechanism to manage connections for applications to ensure high availability. Applications use service names rather than service identifiers to connect to databases; oracle Notification Service (ONS) is configured and enabled on nodes running JDBC. Java virtual machines running JDBC routines must contain oracle. ons. oraclehome and point to ORACLE_HOME. Example: Configure ONS ods. setONSConfiguration ("nodes = racnode1.example.com: 4200, racnode2.example.com: 4200"); Enable FCF // declare datasource
Ods. setUrl (
"Jdbc: oracle: oci: @ (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = cluster_alias)
(PORT = 1521 ))
(CONNECT_DATA = (SERVICE_NAME = service_name )))");
Ods. setUser ("scott ");
Ods. setConnectionCachingEnabled (true );
Ods. setFastConnectionFailoverEnabled (true ):
Ctx. bind ("myDS", ods );
Ds = (OracleDataSource) ctx. lookup ("MyDS ");
Try {ds. getConnection (); // transparently creates and accesses cache
Catch (SQLException SE {
}
}
Confused? The above java code contains an exception handling. The process is as follows: 1. an instance goes down and leaves some expired connections in the cache. RAC generates an event and sends it to the Java Virtual Machine that contains JDBC 3. the background thread in JVM identifies all connections affected by this RAC event, notifies them through SQL exceptions (ORA-17008) to close the connection and roll back the transaction 4. the connection receives an SQL exception and re-executes the failed operation.
FCF differs from TAF in the following ways: 1. FCF supports application-level connection retries. The application determines how to handle the failover, whether to re-execute or throw an exception. TAF can only re-connect at the OCI/NET level. 2. FCF works well with the connection cache to allow the connection cache manager to manage the cache. Failed Connections will automatically fail in the cache. TAF performs a pre-connection on the network layer. When a connection fails, the connection cache cannot detect 3. based on Oracle RAC events, FCF can quickly detect faults for active/idle connections. 4. FCF implements Load Balancing through instance UP events and is allocated to online RAC instances.
We recommend that you do not use TAF and FCF in one application.