Friday, April 29, 2011

Setting Transparent Application Failover

According to Oracle:

"Transparent Application Failover (TAF) is a feature of the Java Database Connectivity (JDBC) Oracle Call Interface (OCI) driver. It enables the application to automatically reconnect to a database, if the database instance to which the connection is made fails."

Therefore, if you have some instances running with Dataguard you can set up TAF in those instances and have automatic failover, which involves creating a service controlled by a database trigger that will be up just in the primary instance, as you can see in this transcript:

myserver >sqlplus /nolog

SQL*Plus: Release 11.1.0.7.0 - Production on Tue Feb 1 15:19:59 2011

Copyright (c) 1982, 2008, Oracle. All rights reserved.

SQL> connect / as sysdba

Connected.

SQL> EXEC DBMS_SERVICE.CREATE_SERVICE (service_name => 'taf_mydb',
network_name => 'taf_mydb', aq_ha_notifications => TRUE,
failover_method => 'BASIC', failover_type => 'SESSION',
failover_retries => 180, failover_delay => 5);

PL/SQL procedure successfully completed.

SQL> CREATE OR REPLACE TRIGGER SYS.MANAGE_TAF_SERVICE
AFTER STARTUP ON DATABASE
DECLARE
ROLE VARCHAR(30) := NULL;
BEGIN
SELECT TRIM(DATABASE_ROLE) INTO ROLE FROM V$DATABASE;
IF ROLE = 'PRIMARY' THEN
DBMS_SERVICE.START_SERVICE('taf_mydb');
ELSE
DBMS_SERVICE.STOP_SERVICE('taf_mydb');
END IF;
END;
/

Trigger created.

SQL> alter system archive log current;

System altered.

SQL> exit;

myserver >lsnrctl status LISTENER_mydb

LSNRCTL for Linux: Version 11.1.0.7.0 - Production on 01-FEB-2011 15:29:03

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.50)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER_mydb
Version TNSLSNR for Linux: Version 11.1.0.7.0 - Production
Start Date 31-JAN-2011 15:47:49
Uptime 0 days 23 hr. 41 min. 14 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle_11g/product/11.1.0/network/admin/listener.ora
Listener Log File /oracle_11g/product/diag/tnslsnr/myserver/listener_mydb/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.50)(PORT=1521)))
Services Summary...
Service "taf_mydb" has 1 instance(s).
Instance "mydb", status READY, has 1 handler(s) for this service...
Service "mydb" has 2 instance(s).
Instance "mydb", status UNKNOWN, has 1 handler(s) for this service...
Instance "mydb", status READY, has 2 handler(s) for this service...
Service "mydb_XPT" has 1 instance(s).
Instance "mydb", status READY, has 1 handler(s) for this service...
The command completed successfully

You have to do the above configuration just in your primary database, and this configuration will be propagated to the standby database with the alter system archive log current sentence.

If you read carefully and understood the first paragraph of this post, you might realized that TAF is in fact implemented in the client side; you configured the instances to start a special service that will be active just in the primary instance at any time, but the client is whom decides to which service to connect. Therefore, you have to configure your tnsnames like this:

MYDATABASE =
(DESCRIPTION =
(LOAD_BALANCE = OFF)
(FAILOVER = ON)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.50) (PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.60) (PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = taf_mydb)
(FAILOVER_MODE =
(TYPE = SESSION)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
)

In this example, you will connect to MYDATABASE that is comprised by the primary instance (192.168.1.50) and the standby instance (192.168.1.60). And if you are going to use Java, don't forget that TAF does not work with the Thin drivers, you have to use the OCI drivers instead. Remembering this might save you a lot of problems with your fellow WAS administrators.

More information:

Failover Connections for Data Guard Error with ORA-1033 [ID 461874.1]
Transparent Application Failover

No comments:

Post a Comment