Set up a Db2 for LUW or Db2 for z/OS destination¶
The Replicator Service writes to Db2 for Linux, UNIX and Windows (LUW) and Db2 for z/OS through an ODBC driver on the Stelo VM. It creates the destination tables and their indexes, loads baselines and snapshots, and applies incremental changes with SQL. Db2 for i has its own page.
Supported configurations¶
| Db2 for LUW | Db2 for z/OS | |
|---|---|---|
| DBMS Type | UDB |
DB2 |
| Versions | Ask Stelo Support for a particular version. | Merge needs Db2 12 or later. Ask Stelo Support for a particular version. |
| Driver on the Stelo VM | StarSQL (installed and licensed with SQDR) or the IBM Db2 ODBC driver. | The same. |
| Snapshot replication | Yes. | Yes. |
| Incremental replication | Yes, from any source with a Capture Agent. | Yes, the same. |
| Apply methods | Batch, Sequence and Merge (see Choosing the apply method). | The same; Merge with Db2 12 or later. |
| Authentication | Remote Credentials: a Db2 user (an operating system or LDAP user) and its password. | Remote Credentials: a z/OS user ID (for example a RACF user) and its password. |
| Encryption | SSL/TLS: see Db2 with StarSQL and IBM Db2 ODBC driver. | The same. |
Docker
The SQDR container includes both drivers (see ODBC drivers in the container).
Prepare the database¶
The database administrator sets up the user the Replicator Service connects as and the schema for the destination tables. Db2 gives the user the privileges it needs on the tables it creates, so the simplest setup is a user that can create tables in a schema of its own. The privileges follow from the SQL the Replicator Service runs (see What the Replicator Service runs on the database).
Db2 for LUW¶
Db2 for LUW users are operating system (or LDAP) users of the Db2 server: create the user there first. Then connect to
the destination database as a user with DBADM and SECADM authority (or SYSADM), and run:
GRANT CONNECT, CREATETAB ON DATABASE TO USER SQDRUSER;
CREATE SCHEMA MYSCHEMA AUTHORIZATION SQDRUSER;
GRANT USE OF TABLESPACE USERSPACE1 TO USER SQDRUSER;
-- Merge groups and ADD Copy: a user temporary table space for the declared temporary tables
CREATE BUFFERPOOL BP32K PAGESIZE 32K;
CREATE USER TEMPORARY TABLESPACE SQDRTEMP PAGESIZE 32K BUFFERPOOL BP32K;
GRANT USE OF TABLESPACE SQDRTEMP TO USER SQDRUSER;
-- ALTER processing: the REORG after an ALTER
GRANT EXECUTE ON PROCEDURE SYSPROC.ADMIN_CMD TO USER SQDRUSER;
Replace SQDRUSER, MYSCHEMA and USERSPACE1 (the table space for the destination tables) with yours. If the
database already has a user temporary table space, grant USE of it instead of creating one. If you name the schema
like the user, you can keep the destination's default Object Schema, the user ID. Why each privilege is needed:
see Privileges on Db2 for LUW.
Db2 for z/OS¶
The z/OS security administrator creates the user ID (for example in RACF), and the Db2 administrator grants the
privileges to create tables. The Replicator Service's CREATE TABLE has no IN clause, so Db2 creates each table in
an implicitly created database and table space, and the privileges are on DSNDB04:
GRANT CREATETAB, CREATETS ON DATABASE DSNDB04 TO SQDRUSER;
Replace SQDRUSER with the user ID. Depending on your Db2 setup, the user may also need USE of the default buffer
pool and storage group; see IBM's CREATE
TABLE authorization rules. The destination's
Object Schema is the tables' qualifier (owner), by default the user ID; another qualifier needs more authority (see
the same rules). Why each privilege or setting is needed: see Privileges on Db2 for z/OS.
For Merge groups and ADD Copy, the work file database needs a table space with a page size of at least 32 KB.
For existing tables or tables you create yourself, see Tables you create yourself.
StarSQL packages¶
StarSQL runs its SQL through SQL packages in the collection named by PkgColID in the connection string (SQDR in the
template). Bind them once with StarAdmin, as for a Db2 source: connect StarAdmin with a user that has BINDADD
authority (and, on z/OS, can create packages in the collection), and choose Bind. StarAdmin grants EXECUTE on
the packages to PUBLIC by default, which SQDRUSER needs. See
Connecting SQDR to a Db2 source: bind the StarSQL packages (StarAdmin).
If the database is already a source, or the control database, of the same Stelo VM, check the collection of that
connection string: packages bound once in a collection serve every connection that uses it.
The IBM Db2 ODBC driver uses IBM's own packages, not StarSQL's (see IBM's documentation for binding them).
Network¶
The Stelo VM must reach the Db2 server's port: for Db2 for LUW, the port of the instance (SVCENAME, often 50000);
for Db2 for z/OS, the DRDA port of the location (often 446).
Create the destination¶
Create the destination as described in Create a destination, with these choices:
-
Driver: StarSQL is installed and licensed with SQDR: there's nothing to install. For the IBM Db2 ODBC driver, see The IBM Db2 ODBC driver.
Docker
The SQDR container includes StarSQL and the IBM Db2 ODBC driver.
-
Name: choose the DBMS Type UDB (Db2 for LUW) or DB2 (Db2 for z/OS). The Replicator Service sets the type the database reports when it connects.
-
Connection: choose ODBC Driver and the driver, then a Template (UDB for Db2 for LUW), and fill in the fields (see Connection string). With StarSQL, set
PkgColIDto the collection of the StarSQL packages. -
Authentication: Remote Credentials with the user and its password. Click Verify.
- Tick Advanced to check the defaults: on the Default step, Object Schema is where new subscriptions
create their tables (the user ID by default); set it to
MYSCHEMAif the schema has another name. See Defaults.
Verify tests the connection, not the privileges (see Test the privileges).
Connection string¶
StarSQL¶
- Db2 for LUW (the UDB template):
HostName=myhost;Port=50000;Server=MYDB;PkgColID=SQDR, with the database name asServer. - Db2 for z/OS (the StarSQL template for Db2):
HostName=myhostip;Port=446;Server=MYLOCATION;IsolationLevel=2;PkgColID=SQDR, with the location name asServer. ItsIsolationLevel=2is for Db2 for i sources; you can keep it. PkgColIDnames the collection (on Db2 for i, the library) that holds the StarSQL packages.- SSL/TLS (Windows): add
Netlib=SQSSL.DLLand use the server's SSL port, for exampleHostName=myhostip;Netlib=SQSSL.DLL;Port=448;Server=MYRDB;IsolationLevel=2;PkgColID=SQDR.
Docker
Put the certificate authority's certificate in /var/sqdr/certs (see
ODBC drivers in the container). The Replicator Service adds
ICONV4UTF8=Y to StarSQL connection strings on Linux.
Bind the StarSQL packages¶
StarSQL runs its SQL through SQL packages on the Db2 system, in the collection named by PkgColID (on Db2 for i, a
library). They're bound once per collection, and every connection that uses the collection shares them. Some are
bound for you: the Add Capture Agent wizard binds them in the agent's control library or collection (see
Db2 for i and Db2 for LUW), and the SQDRC database that Stelo
Capture creates has them in STARSQL. Bind them yourself with StarAdmin for any other collection, for example for a
Db2 source without a Capture Agent, a Db2 for z/OS source, or a Db2 destination.
- Get StarAdmin. It's installed with Stelo Capture: Start menu SQDR Plus (64-bit) › Tools › StarAdmin
(see Programs and files). Without Stelo Capture, install it from its own
installer (ask Stelo Support): run
setup.exeas an administrator and accept the defaults. -
Collect the values:
Value What to enter Host The Db2 server's host name or IP address. Port The port Db2 listens on (446 for Db2 for i). Database name The relational database name (RDB) of the Db2 database. Package collection SQDR(orQGPLon Db2 for i), the value you'll use forPkgColID.User and password A Db2 user with authority to create and bind packages in that collection. -
On Db2 for i, create the library for the collection, unless you use
QGPL:CRTLIB SQDR. - Connect. Start StarAdmin and enter the values in the Connection Settings dialog. When it connects, it binds one package right away. If it can't connect, see the common error messages in Binding StarSQL Packages Using StarAdmin, correct the values and try again.
- Bind. Keep the default Package Settings and Grant Options (they grant
EXECUTEon the packages toPUBLIC), and select Command › Bind. If the summary reports errors, correct them (see the same document) and bind again; if you can't, send the whole summary to Stelo Support.
Then name the collection in the connection string of the source or destination, for example
Server=MYRDB;HostName=myhostip;Port=446;IsolationLevel=2;PkgColID=SQDR (IsolationLevel=2 for Db2 for i sources).
IBM Db2 ODBC driver¶
- Template:
Hostname=myhostip;Port=446;Database=MYRDB;Protocol=TCPIP;LongDataCompat=1;Authentication=SERVER.Databaseis the RDB name on Db2 for i, the database name on Db2 for LUW and the location name on Db2 for z/OS. UseAuthentication=ENCRYPTto encrypt the user ID and password. - LOB columns:
LongDataCompat=1is required to replicate LOB data correctly. For large LOB values, also set the driver'sLOBMaxColumnSizeand the service's Indeterminable-size column limit to the largest size you replicate. - SSL/TLS: add
Security=SSL, the server's SSL port, and the GSKit key database and stash file:SSLClientKeystoredb=C:\mySSLdir\mykeystore.kdb;SSLClientKeystash=C:\mySSLdir\mykeystore.sth. The account the Replicator Service runs as must be able to read the stash file. This driver uses its own key database, not the certificates in/var/sqdr/certsin the container. - The driver doesn't use StarSQL packages.
The IBM Db2 ODBC driver¶
To use the IBM Db2 ODBC driver instead of StarSQL, install IBM's Db2 client (Db2 Connect for Db2 for z/OS) on the Stelo VM. For its connection string, see IBM Db2 ODBC driver.
Group settings for Db2¶
When you create an incremental group to this destination, choose the DML Replication method (see Apply):
- Batch (the default) and Sequence need nothing more.
-
Merge is the fastest method for high volumes (see Choosing the apply method) and needs a key on every member (see Tables without a usable key). On Db2 for z/OS, it needs Db2 12 or later and a 32 KB work file table space (see Db2 for z/OS); on Db2 for LUW, a user temporary table space the user can use (see Db2 for LUW). Check that before you choose Merge:
SELECT T.TBSPACE, T.PAGESIZE, A.GRANTEE FROM SYSCAT.TABLESPACES T JOIN SYSCAT.TBSPACEAUTH A ON A.TBSPACE = T.TBSPACE WHERE T.DATATYPE = 'U' AND A.USEAUTH IN ('Y', 'G');The list should include
SQDRUSER(orPUBLIC, or a group of the user). Without it, every merge fails with SQL0286N and the group reports a polling error.
Check the destination¶
After the first baseline of the incremental group (for snapshots, after the first run):
- Group status. On the Groups page, the group shows Actively monitoring and applying change data (see Group status). If a member failed, its replication events show the Db2 error.
-
Rows at the destination. Compare a table's row count with the source:
SELECT COUNT(*) FROM MYSCHEMA.MYTABLE; -
Changes. Change a few rows at the source; they're applied with the group's next poll (the Poll Interval; see Scheduling). Query the rows again to see them.
What the Replicator Service runs on the database¶
The privileges in Prepare the database follow from these statements:
| When | Statements |
|---|---|
| A subscription is saved or a baseline starts (depending on its Destination DDL Options) | DROP TABLE and CREATE TABLE for the destination table, named with its schema. The CREATE TABLE has no IN clause: Db2 chooses the table space (on z/OS, an implicitly created database and table space). |
| Before a baseline or snapshot copies the data | Truncate table before replication runs TRUNCATE TABLE <table> IMMEDIATE. Delete existing data before replication deletes in batches of the ODBC commit interval on Db2 for LUW (DELETE FROM (SELECT RID_BIT(<table>) FROM <table> ... FETCH FIRST n ROWS ONLY)), and with one DELETE FROM <table> on Db2 for z/OS. See Baseline Replication Options. |
| During the copy | INSERT, with ODBC parameter arrays. Db2 has no native loader: Use native-loader function uses ODBC inserts. |
| Around the copy | CREATE INDEX and DROP INDEX for the index on the replication key (suffix IR) and the source indexes you replicate; ALTER TABLE ... ADD CONSTRAINT ... PRIMARY KEY and ALTER TABLE ... DROP PRIMARY KEY for Allow UPSERT members and replicated primary keys. See The key at the destination. |
| Applying changes with Batch or Sequence | INSERT, UPDATE ... WHERE <key> and DELETE ... WHERE <key>, one row at a time, committed per batch. |
| Applying changes with Merge | A declared temporary table: DECLARE GLOBAL TEMPORARY TABLE SESSION.SQDRWT_<id> (...) WITH REPLACE ON COMMIT PRESERVE ROWS NOT LOGGED on Db2 for LUW, ... ON COMMIT PRESERVE ROWS on Db2 for z/OS (where the Replicator Service drops it first, and empties it with DELETE); a multi-row INSERT into it; then one MERGE INTO <table> .... See How Merge works. |
| With Merge In Place | A permanent merge table next to the destination table (or in the schema of the Decoration), created, emptied with TRUNCATE TABLE ... IMMEDIATE and dropped like a destination table. |
| ALTER processing | ALTER TABLE ... ADD COLUMN, ALTER COLUMN ... SET DATA TYPE, DROP NOT NULL or SET NOT NULL (Db2 for LUW only), DROP COLUMN and RENAME COLUMN. On Db2 for LUW, the service then reorganizes the table: CALL SYSPROC.ADMIN_CMD('REORG TABLE <schema>.<table> USE TEMPSPACE1'). ADD Copy loads a work table (SESSION.SQDRCP_<id>, a declared temporary table, or a regular table SQDRCP_<id> next to the destination table when the group allows checkpoint/restart) and updates the destination table from it with a MERGE. |
Data types¶
The Replicator Service maps the source columns to the types the driver reports; see Data type mapping and its Per-database notes. For Db2:
- Decimal precision. Db2
DECIMALhas at most 31 digits; a source number with more digits maps to a character column (see the default mapping). - Character data. Data from a single-byte source can need more bytes in a UTF-8 database: use the inflation options (see Character data and the host variable error).
- LOB columns. On Db2 for LUW, Create LOB columns as not logged creates
CLOB,BLOBandDBCLOBcolumnsNOT LOGGED(see Options that change the mapping). With the IBM Db2 ODBC driver,LongDataCompat=1is needed for LOB data. - IBM Db2 ODBC driver.
GRAPHIC,VARGRAPHICandDBCLOBare treated as Unicode character types.
Limitations¶
- Merge on Db2 for LUW needs a user temporary table space the user can use (see Db2 for LUW); on Db2 for z/OS, Db2 12 or later and a 32 KB work file table space (see Db2 for z/OS). Every member of a Merge group needs a key.
- TRUNCATE ... IMMEDIATE can't be rolled back, and Db2 doesn't truncate a table that another table's foreign key references; use Delete existing data before replication for such tables.
- Db2 for z/OS: ALTER processing can't make an existing column non-nullable; that change is skipped (see ALTER
processing: limitations). The service doesn't reorganize the table
after an
ALTER. - Db2 for LUW: ALTER processing reorganizes the table after each
ALTER, which takes time on large tables. - Parallel baselines are available for Db2 for LUW, not for Db2 for z/OS (see Parallel baselines with slices).
Troubleshooting¶
Problems and messages, with their causes and fixes, are in Troubleshooting › Db2 for LUW and Db2 for z/OS.
Related¶
- More about preparing a Db2 for LUW or Db2 for z/OS destination
- Prepare a Db2 for LUW database (as a source)
- IBM documentation: Db2 for LUW DECLARE GLOBAL TEMPORARY TABLE, TRUNCATE, CREATE TABLE; Db2 for z/OS DECLARE GLOBAL TEMPORARY TABLE, MERGE