Skip to content
Home » Oracle » How to Set Client-Side Transparent Application Failover (TAF)

How to Set Client-Side Transparent Application Failover (TAF)

Transparent Application Failover (TAF)

Besides connect-time failover to the standby database, there is a function called Transparent Application Failover (TAF) can do run-time failover to enable user to continue his work transparently when connection failed over to other database (listener).

There are two types of run-time failover method, both methods are suitable for RAC architecture, but not for Data Guard, because under normal condition, the primary and standby database are under open and mount respectively, they are NOT both online.

  1. PRECONNECT Method
  2. BASIC Method

PRECONNECT Method

This method connects to both main and backup database, if a main connection fails, Oracle Net switch to the backup connection immediately. So it's also called Fast Run-Time Failover.

There are must be two entries in tnsname.ora to backup each other's connections mutually. See the example below.

# Transparent Application Failover Entries
PRIMDB01_TAF =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary01-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = compdb.example.com)
      (FAILOVER_MODE =
        (BACKUP = PRIMDB02_TAF)
        (TYPE = select)
        (METHOD = preconnect)
      )
    )
  )

PRIMDB02_TAF =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary02-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = compdb.example.com)
      (FAILOVER_MODE =
        (BACKUP = PRIMDB01_TAF)
        (TYPE = select)
        (METHOD = preconnect)
      )
    )
  )

The attribute FAILOVER_MODE represents TAF feature that must be set in these entries. In which, three sub-attributes are:

1. BACKUP

This is to set where the backup connection to go, you can see the two entries are symmetric to backup each other.

2. TYPE

We choose "select" to enable users to continue fetching on the backup database after failure.

3. METHOD

Here, we choose Fast Run-Time Failover to preconnect the backup database.

BASIC Method

If a current connection fails to continue, then Oracle Net connects to the other address to continue his query.

There's only one entry needs to be configured.

# Transparent Application Failover
PRIMDB_TAF =
  (DESCRIPTION =
    (LOAD_BALANCE = ON)
    (FAILOVER = ON)
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary01-vip)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = primary02-vip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = compdb.example.com)
      (FAILOVER_MODE =
        (TYPE = select)
        (METHOD = BASIC)
      )
    )
  )

Functions test

1. PRECONNECT method

Test PRECONNECT method with PRIMDB01_TAF TNS name.

C:\Documents and Settings\Administrator>sqlplus system/system@primdb01_taf

SQL> COLUMN SERVER FORMAT A7;
SQL> COLUMN "CLIENT MACHINE" FORMAT A25;
SQL> COLUMN FAILOVER_TYPE FORMAT A10;
SQL> COLUMN FAILOVER_METHOD FORMAT A10;
SQL> COLUMN FAILED_OVER FORMAT A3;
SQL> COLUMN NO FORMAT 999;
SQL> SELECT VI.INSTANCE_NAME SERVER, VS.MACHINE "CLIENT MACHINE", VS.FAILOVER_TYPE, VS.FAILOVER_METHOD, VS.FAILED_OVER, COUNT(*) NO FROM V$SESSION VS, V$INSTANCE VI GROUP BY VI.INSTANCE_NAME, VS.MACHINE, VS.FAILOVER_TYPE, VS.FAILOVER_METHOD, VS.FAILED_OVER;

SERVER  CLIENT MACHINE            FAILOVER_T FAILOVER_M FAI   NO
------- ------------------------- ---------- ---------- --- ----
primdb1 primary01.example.com     NONE       NONE       NO    78
primdb1 WORKGROUPUSER-UGOC234R3   SELECT     PRECONNECT NO     1

The connection is on primdb1 which is the first node of primary RAC. Now, we stop the instance of current connection.

[oracle@primary01 ~]$ srvctl stop instance -d compdb -i primdb1

Then, we continue the query.

SQL> /

SERVER  CLIENT MACHINE            FAILOVER_T FAILOVER_M FAI   NO
------- ------------------------- ---------- ---------- --- ----
primdb2 primary02.example.com     NONE       NONE       NO    79
primdb2 standby02.example.com     NONE       NONE       NO     1
primdb2 WORKGROUPUSER-UGOC234R3   SELECT     PRECONNECT YES    1

Now, it's on primdb2 which is the second node of primary RAC, and we don't feel any interruption.

2. BASIC method

First, primdb1 needs to be back.

[oracle@primary01 ~]$ srvctl start instance -d compdb -i primdb1

Test Basic method with PRIMDB_TAF tnsname.

C:\Documents and Settings\Administrator>sqlplus system/system@primdb_taf

SQL> COLUMN "INSTANCE NAME" FORMAT A15;
SQL> SELECT SYS_CONTEXT('USERENV','INSTANCE_NAME') "INSTANCE NAME" FROM DUAL;

INSTANCE NAME
---------------
primdb1

Now, we stop the instance of current connection.

[oracle@primary01 ~]$ srvctl stop instance -d compdb -i primdb1

Then, we continue the query.

SQL> /

INSTANCE NAME
---------------
primdb2

Same result as PRECONNECT, but PRECONNECT will be faster theoretically.

Conclusions

Above local naming methods have further features as below:

  1. The failover target of Run-Time Failover can be a local listener with a different PORT and different address.
  2. The function of Run-Time Failover usually includes the function of Connect-Time Failover. If you already have a solution of Run-Time Failover, it's usually not necessary to integrate another Connect-Time Failvoer solution.

For a RAC database system, Oracle recommends we use server-side TAF to failover sessions from one to another.

More configuration about TAF can be found at: Oracle Database Release 19 : Net Services Administrator's Guide : 13.3 Configuring Transparent Application Failover

Leave a Reply

Your email address will not be published. Required fields are marked *