IBM Db2 active/passive using HADR
High Availability Disaster Recovery (HADR) is a transaction log replication approach that keeps a standby database server in or near synch with changes in the primary database server.
In the event of a failover, HADR on the standby database server takes over and becomes the primary, as described in the following figure:

At a high level, the log writer on the primary database server records changes to its local transaction logs. These logs are critical for crash and instance recovery. The primary HADR sends the log records to the standby HADR where the logs are written out to the standby server's transaction logs. The changes are then applied to the standby server's database. At some point in time, the changes on the primary server are asynchronously written to the database.
The standby database server is kept in “perpetual rollforward” mode applying transaction log entries as they are replicated from the primary.
HADR provides many benefits over the traditional active/passive cluster failover provided by software such as HACMP, VCS or MC/ServiceGuard. First HADR recovery is faster because you do not have to start the standby database server – the standby database server is always running and is either in or near synch with the primary database server. Similarly, you do not have to spend a lot of time in database crash recovery because by design, the standby HADR database server is in or near peer state. Also, you do not have to spend time releasing resources on the failed node and acquiring resources on the standby node. With HADR, the standby database is already connected to and using a separate disk subsystem.
Second, the standby HADR database server does not share disk subsystems with the primary database server. Therefore, with HADR, you can survive a disk subsystem failure whereas cluster failover, which relies on a shared SAN, could incur a potentially prolonged outage until the disk subsystem is repaired.
HADR is provided as part of ESE. With HACMP or the other cluster failover software, you have to purchase additional software licenses.
From a recovery perspective, the HADR provides a less risky failover approach. With HADR, the standby database is already running. In contrast, with cluster failover, resources have to be acquired, services started, etc. There are potential startup risks during the recovery process.
Db2® 9.1's HADR implementation has the following limitations:
- HADR can only replicate to one standby database server – therefore, from the primary database server, you can either HADR to a local standby for local site failover or to a remote site for disaster recover (but not both).
- HADR is only supported on Db2 ESE
- You cannot backup from the standby – you must backup from the primary
Please refer to the IBM® Db2 documentation for more detail.
Client reroute
Client Reroute was introduced in Db2 8.2 along with HADR to enable client applications to automatically reconnect to the standby HADR database server when the primary server fails. Client reroute works by informing the client of the alternate or standby database when it connects to the primary.
The alternate database information is defined on the primary database server with the following command:
db2 update alternate server for database <dbname> using hostname <hhh> port <ppp>
For example, if your primary database DB2PROD is on node N1 port 50000 and the alternate is on node N2 port 50000, issue the following command on node N1:
db2 update alternate server for database DB2PROD using hostname N2 port 50000
Alternates are propagated from the server to the client dynamically when the client issues a CONNECT or CONNECT RESET. This dynamically propagated alternate server information is stored in global driver memory, and is also updated in the JNDI store of Db2 active servers.
Initially, Db2 Universal JDBC Driver client
reroute support was available only for connections that use the
javax.sql.DataSource
interface. In Db2 9.1
FP3, IBM added client reroute support to
java.sql.DriverManager
.