Transparent application failover (TAF) is the ability of applications to automatically reconnect to the database if the connection fails. If the server fails, the connection fails as well. The next time the client tries to use the connection, e.g., to execute a new SQL statement, the operating system displays an error to the client. At this point, the user must log in to the database again. With TAF, however, Oracle automatically obtains a new connection to the database. This allows the user to continue to work using the new connection as if the original connection had never failed. If the client is not involved in a database transaction, then users may not notice the failure of the server. Because this reconnect happens automatically, the client application code may not need changes to use TAF. TAF automatically restores:
Unfortunately, TAF cannot automatically restore some session properties. If the application issued ALTER SESSION commands, then the application must reissue them after TAF processing is complete.
Frequently failure of one instance and failover to another takes time. Because of this delay, you may want to inform users that failover is in progress. Additionally, the session on the initial instance may have received some ALTER SESSION commands. These will not be automatically reissued on the second instance. You may need to reissue these commands on the second instance.
To address such problems, you can use the OracleConnection.Failover event. This event is raised during session recovery process when connection is lost. When connection failure is detected Failover event is raised first time. Then application keeps raising it until connection is restored or user stops failover process.
Transparent Application Failover Restrictions:
To enable TAF on the Oracle server, the corresponding entry in the tnsnames.ora file should be modified. The tnsnames.ora file is located at <Oracle_Home>\network\Admin directory where <Oracle_Home> is the directory where your Oracle database or client is installed. For example, the TNS entry for the server with TAF may look like this:
<DBFAILOVER> = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = SERVER)(PORT = 1521)) ) (CONNECT_DATA = (SID = ORCL) (FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC) (RETRIES=100)) ) )
For the detailed information on possible subparameters of FAILOVER_MODE, refer to the Oracle documentation
The following sample shows how TAF may be used. First, we create a connection and subscribe a method for the Failover event of this connection:
First register method as Failover event handler.
To demonstrate the failover, we break the connection at this moment (see below how to do so). We try to execute a simple query, and the failover process starts:
Here is the implementation of the conn_Failover method:When TAF occurs, this method is called. Different values of the State event argument allow to perform appropriate actions on the corresponding stage of the failover process. E.g., it is possible to inform user that the connection failed and is re-establishing, or ask whether it is necessary to reconnect, or ask for credentials if re-authorizing is necessary. Provided that failover succeeds, the query will be executed again with a new connection.
To try TAF, you need to break the connection after it is opened, e.g., by shutting down the Oracle server. This can be done with the SQL*Plus tool. First, it is necessary to login as a user with SYSDBA privileges:
SQL> Connect sys/<password>@<TNSName> as sysdba
Here <password> and <TNSName> should be replaced with the password of the sys user and the TNS name of the server. To shutdown the server, run the command
SQL> shutdown immediate
(the 'immediate' keyword is necessary to tell the server that it should not wait for the pending connection we've opened before). To restart the server, run
SQL> startup
OracleConnection.Failover event | Devart.Data.Oracle Namespace