Configuring the HADR standby server
Back up the database from the primary server and restore it on the standby server. Then, set HADR variables on the standby server.
Before you begin
Procedure
- Log in to the primary server as an administrator.
- Run these commands to back up the database on the primary
server:
mkdir temp_backup_directory cd temp_backup_directory db2 backup db database
For example:mkdir mytempbackup cd mytempbackup db2 backup db xmeta
Note: You can store more than one database backup in the same temporary directory.After the backup completes, a confirmation message is displayed:Backup successful. The timestamp for this backup image is :20101101161943
- Transfer the backup files from the primary server to the standby server.
- Log in to the standby server. Use your Db2® user ID.
- Run this command to restore the database on the standby
server:
db2 restore db database from database_backup_directory replace history file
For example:db2 restore db xmeta from mytemprestore replace history file
- On the standby server, run the following commands to specify
the HADR primary server and standby server. In the command, specify
the standby server for
hadr_local_host
. Specify the primary server forhadr_remote_host
(the opposite of the settings on the primary server).db2 update db cfg for database using hadr_local_host standby_IP db2 update db cfg for database using hadr_remote_host primary_IP
The primary_IP address and the secondary_IP address can be an IPv4 address or an IPv6 address. For example:db2 update db cfg for xmeta using hadr_local_host 192.0.2.7 | ::ffff:192.0.2.7 db2 update db cfg for xmeta using hadr_remote_host 192.0.2.6 | ::ffff:192.0.2.6
- On the standby server, run the following commands to specify
the HADR primary and standby service names. In the command, specify
the standby server port name for
hadr_local_svc
. Specify the primary server port name forhadr_remote_svc
(the opposite of the settings on the primary server).db2 update db cfg for database using hadr_local_svc standby_svc_name db2 update db cfg for database using hadr_remote_svc primary_svc_name
For example:db2 update db cfg for xmeta using hadr_local_svc ha_myhadr_int db2 update db cfg for xmeta using hadr_remote_svc ha_myhadr
- On the standby server, run the following command to set
up automatic client reroute. Specify the primary server IP address
and port number in the command:
db2 update alternate server for database database using hostname primary_IP port port
For example:db2 update alternate server for database xmeta using hostname 192.0.2.6 | ::ffff:192.0.2.6 port 60000
- On the standby server, run the following command to verify
your configuration values:
db2 get db cfg for database | grep HADR
For example:db2 get db cfg for xmeta | grep HADR
The command displays a report:HADR database role = STANDARD HADR local host name (HADR_LOCAL_HOST) = mystandby.example.com HADR local service name (HADR_LOCAL_SVC) = ha_myhadr_int HADR remote host name (HADR_REMOTE_HOST) = myprimary.example.com HADR remote service name (HADR_REMOTE_SVC) = ha_myhadr HADR instance name of remote server (HADR_REMOTE_INST) = db2inst1 HADR timeout value (HADR_TIMEOUT) = 120 HADR log write synchronization mode (HADR_SYNCMODE) = SYNC