Skip to content

Run a standby Stelo Capture server with Db2 HADR

Who needs this

Only sites that keep a second Stelo VM ready to take over, using Db2 HADR (high availability disaster recovery) for the Db2 for LUW databases on the Stelo VM. Otherwise, skip this page. For a SQL Server control database, or a Db2 for LUW source in HADR, see Db2 for LUW: supported configurations.

On the Stelo VM, SQDR keep their state in Db2 for LUW databases: the control database SQDRC and one staging database per Capture Agent (SQDRPn). Db2's HADR keeps a copy of each of these databases on a second server, the standby, so that replication can continue there when the first server, the primary, fails or is down for maintenance. Use it:

  • for high availability: a standby close to the primary (for example in the same data center), ready to take over quickly;
  • for disaster recovery: a standby at another site, for a site failure;
  • to avoid downtime during updates of the hardware, Windows, Db2 or SQDR: update the standby, switch, then update the other server.

This page describes one primary and one standby on Windows. Switching servers (a takeover) is a manual step: plan it, script it (see Scripts) and test it, so that you can act quickly when it's needed. If HADR is already set up and you need to switch servers, go to Take over.

What HADR keeps in step, and what you set up yourself

  • Db2 replicates SQDRC and every staging database from the primary to the standby. Their contents change all the time and must stay in step with each other, so protect them all. They hold the list of Capture Agents, the Replicator Service's configuration, the staged changes and the log positions: configuration changes made in the Data Replicator Manager, the SQDR Control Center or PowerShell reach the standby with them.
  • Stelo Capture runs on both servers. On the standby, every agent shows Standby. After a takeover, the agents start within about a minute, one after another (see Agents on a Db2 HADR standby).
  • The Replicator Service runs on both servers. On the standby it keeps failing to start until a takeover, because its control database isn't available; Windows restarts it (see Configure the Replicator Service).
  • The Replicator Service must find the staging databases on the new primary. With autoRefreshStaging on, it does so by itself when it can't reach a staging database; otherwise you refresh each incremental source (see After a takeover).
  • What isn't replicated: the files on each server (sqdr.properties, the encryption key node.properties, the logs), Windows, Db2 and the ODBC drivers. You set them up once on the standby.

Plan the two servers

Both servers must run:

  • Windows, on the same architecture;
  • the same major version of Db2 for LUW (for example 11.5), with the same instance name; the standby can be at a later fix pack for a while during a rolling update;
  • the same version of SQDR;
  • the same disk layout and paths for the Db2 table spaces and logs, for example S: for the table spaces and L: for the logs and archive logs (the sizes may differ).

Also plan:

  • Licenses for both servers (see Licenses).
  • The same users on both servers: the Db2 user of Stelo Capture (for example sqdr) with the same password. The Db2 service account should match too; if its name differs, grant DBADM on each database to both.
  • Who runs the setup: a user with Db2 authority to run BACKUP and RESTORE (for example a member of the Db2 administrators group, DB2ADMNS) and DBADM in each database. db2pd and starting and stopping services need an administrator command window; the rest doesn't.
  • Network: both servers reach the sources and destinations, by names that resolve to the same systems.
  • Ports: one HADR port per database, open in the firewall on both servers. The scripts use 50599 for SQDRC and 50500+n for SQDRPn (for example 50505 for SQDRP5); the same port can be used on both servers. Open on the standby the ports you use on the primary for the Data Replicator Manager (7737, 7738) and the SQDR Control Center (8080, 8443).
  • Synchronization mode (HADR_SYNCMODE), a balance between possible data loss and commit time: NEARSYNC for a standby nearby (high availability), SUPERASYNC for a remote standby (disaster recovery). See IBM's HADR synchronization mode.
  • Archive logging: HADR needs it, so the scripts switch the databases from circular to archive logging, and a scheduled task must clean up the archive logs (see Ongoing maintenance).
  • Storage maintenance first: if the staging databases have grown (see the folders under S:\DB2\NODE0000), reclaim the space before you set up HADR, so you don't transfer and replicate it (see Reclaim table-space storage).
  • TCP keepalive: see IBM's Configuring TCP/IP keepalive parameters and Detect lost connections quickly with TCP keepalive.

Scripts

Stelo provides PowerShell scripts in hadr.zip. Unblock the zip file (its Properties, Unblock) before you extract it.

Script Run it on What it does
primary.ps1 The primary Sets the HADR parameters of one database, switches it to archive logging (archive logs in L:\db2archivedir) and takes an offline backup to your home folder.
standby.ps1 The standby Sets Db2 parameters, restores the backup, sets the HADR parameters and starts HADR as standby.
takeover.ps1 The standby An example of a takeover of several databases.
db2clean.ps1 The primary An example of a scheduled clean-up of archive logs.

Without parameters, the scripts ask for the host names of the two servers and the database name. Every parameter can be given on the command line instead, for example ./primary.ps1 -dbname "SQDRP0" -hadr_syncmode "NEARSYNC". Read each script first, to see whether you need to override a default.

Set up HADR

1. Prepare the standby

  1. Install and license Db2, SQDR as on the primary (see Install on Windows).
  2. Install the ODBC drivers, and create the ODBC data sources, that the sources and destinations use (see the Data Replicator Manager's list of sources and destinations on the primary).
  3. Stop the Stelo Capture services and the Replicator Service.
  4. Check the firewall rules.

2. Set up the primary

The primary's databases are offline during this step.

  1. List the databases to protect: SQDRC, and each staging database in the ControlDB column of the server's Agents tab in the SQDR Control Center.
  2. For each one, check whether archive logging is already on: db2 get db cfg for <database>, value LOGARCHMETH1 (OFF means circular logging). If it's on, give the script your archive folder.
  3. Stop the Replicator Service and the Stelo Capture services, and check with db2 list applications that no connection to these databases is left.
  4. Run primary.ps1 for each database.
  5. Start the services again.
  6. Copy the backup images from your home folder (C:\Users\<user>) to the same folder on the standby.

If the script reports that it can't reach the standby (it checks there that the port is free), it's running as a user without rights on the other server: ignore it if you know the port is free, or run it as a domain user with those rights.

3. Set up the standby

  1. For each database that already exists on the standby (SQDRC, which the SQDR Plus installer created), deactivate and drop it: db2 deactivate db SQDRC, then db2 drop db SQDRC.
  2. Run standby.ps1 for each database. For a remote standby, add -hadr_syncmode "SUPERASYNC".

4. Start HADR on the primary

  1. On the primary, for each database: db2 start hadr on database <database> as primary.
  2. On both servers, check the state in an administrator Db2 command window, and fix any problem it shows: db2pd -hadr -alldbs (or db2pd -hadr -d <database>).

5. Copy the files the standby needs

Copy from the primary to the same place on the standby:

  • C:\ProgramData\StarQuest\SQDR\sqdr.properties, the Replicator Service's connection to SQDRC.
  • C:\ProgramData\StarQuest\sqdrplus\conf\node.properties, the key that encrypts the passwords Stelo Capture stores (rename the standby's own file first). Then, in the standby's conf\sqagent.properties, replace the value of password with the value in the primary's file (see What the move carries over).
  • Files you customized: for example wrapper-local.conf of a service, the SQDR Control Center's certificate (see SSL/TLS), and the certificate store C:\ProgramData\StarQuest\sqdrplus\keyStore if agents connect to sources with SSL/TLS.

6. Configure the Replicator Service

  1. On the primary, set the service property autoRefreshStaging to true (Service Settings › Properties › Advanced). It's stored in SQDRC, so the standby gets it too.
  2. On both servers, in Services, open StarQuest Data Replicator › Recovery, and set Restart service after to 1 minute.

7. Test a takeover, and switch back

Do a planned takeover to the standby and back, and check replication each time. The first time on the standby, check the Java stored procedures as in step 2 of After a takeover.

Take over

Planned takeover

For maintenance, such as a rolling update. No data is lost, and the two servers swap roles.

  1. On the primary, stop the Stelo Capture services and the Replicator Service, and check with db2 list applications that no connection to the databases is left.
  2. On the standby, for each database: db2 takeover hadr on database <database>. With many databases, use a script (see takeover.ps1), so the takeover is quick.
  3. Check with db2pd -hadr -alldbs, then see After a takeover.

To switch back, do the same from the other server. Once both servers are set up, you can leave the services running on both and switch with the takeover command alone: the Launch Agent of the new primary starts the agents within about a minute (several agents one after another), and the Data Replicator Manager shows the standby service with a question mark, without Connect to Service.

Unplanned takeover

When the primary has failed: db2 takeover hadr on database <database> by force.

  • Changes not yet sent to the standby can be lost, depending on the synchronization mode and on what was in progress.
  • Make sure the failed primary doesn't accept Db2 connections, so that you don't end up with two primaries (a "split brain"), with two Replicator Services working on the same sources and destinations.
  • When the old primary is repaired, make it the standby: db2 start hadr on database <database> as standby, check with db2pd, then switch back with a planned takeover if you want.

After a takeover

  1. Start the Stelo Capture services and the Replicator Service, if they aren't running.
  2. Java stored procedures: the Launch Agent checks and replaces them when it starts. If an agent's log still shows SQL4306N, install them in each staging database on the new primary, once, as in SQL4306N on SQDR.GETJARVERSION. Create the folder C:\ProgramData\IBM\DB2\DB2COPY1\function\jar first if it doesn't exist, and don't forget the commit.
  3. Incremental groups in error: if autoRefreshStaging isn't on, the Replicator Service still connects to the old server. On the Advanced tab of each incremental source, click Refresh in Incremental Replication: Agent must show the new primary.

Change the configuration

Make changes on the primary. Changes in the Data Replicator Manager, the SQDR Control Center and PowerShell are stored in SQDRC or the staging databases and reach the standby by themselves. Besides that:

Change What to do on the standby
New Capture Agent with a new staging database Set up HADR for that database (steps 2 to 4).
Capture Agent deleted If its staging database was dropped on the primary, deactivate and drop it on the standby too. If a later agent reuses the name and the restore fails with SQL1036C, restart Db2 on the standby.
Capture Agent with a clientODBCString naming the primary Use a DNS name that follows the primary, so the published connection string is right on both servers.
New connection to SQDRC in the SQDR Configuration Tool Copy sqdr.properties again.

Update the servers

Update the standby first, take over, update the other server, and take over again if you want it back as primary.

To update Db2 (a fix pack): on the standby, update Db2 and restart if asked; stop the SQDR services; take over the databases; run db2updv115 -d <database> for each; check that you can connect; start the services. Then update Db2 on the other server; there's no need to run db2updv115 again, because HADR replicates the change. For a new major version of Db2, see IBM's Upgrade Db2 High Availability Disaster Recovery (HADR) environments.

Ongoing maintenance

  • Archive logs: schedule a task on the primary that deletes old archive logs, so the disk doesn't fill (see db2clean.ps1). The standby doesn't archive logs until it becomes the primary.
  • Storage maintenance (REORG, ALTER TABLESPACE ... REDUCE MAX) on the primary is replicated to the standby.
  • pruneRetention: keep the Capture Agents' pruneRetention at 0 (the default).

Monitor HADR

  • db2pd -hadr -alldbs, in an administrator Db2 command window on one of the servers. With several standbys, run it on the primary, which knows them all.
  • The MON_GET_HADR table function returns the same information over an SQL connection, from any client. See IBM's MON_GET_HADR.
  • IBM Db2 Data Management Console can monitor HADR and send alerts.

Logs aren't shared: the Capture Agents' and services' logs of the time a server was the primary stay on that server.

Stop using HADR

For each database, so that only one copy remains:

  1. On the standby: db2 deactivate db <database>, then db2 drop db <database>.
  2. On the primary: db2 stop hadr on db <database>.
  3. If activating the database then fails with SQL1117N ... ROLL-FORWARD PENDING, run db2 rollforward db <database> to end of logs and stop.

You can switch the databases back to circular logging. The HADR parameters can stay: they're ignored without HADR.

Troubleshooting

SQL1768N Unable to start HADR. Reason Code = 7. Usually a network problem or a mismatch: check that both servers use the same ports for each database and that the firewall allows them. See IBM's SQL1768N.

"primary.ps1 is not digitally signed. You cannot run this script on the current system." Unblock the file: in its Properties, select Unblock and click Apply.

A Db2 for i agent logs CPF2451 Message queue CALOGQ is allocated to another job or CPF2403 Message queue CAQ in SQDR not found after a takeover. Restart the agent.