Making queries wait for Db2 Data Gate synchronization updates (WAITFORDATA)
You can postpone the execution of queries against tables in Db2 Data Gate target databases until the latest synchronization updates have been applied.
About this task
The synchronization process runs asynchronously, and synchronization updates are applied in batches. This causes a data recency gap (latency) between the tables in the source database and the tables in the target database. That is, the data in the source database is usually newer than the data in the target database. The gap is zero or minimal shortly after synchronization updates have been applied to the target database. After that, the gap widens again.
If it is a requirement that queries against the target database retrieve data that is as up-to-date as possible, then the best point in time to do this is shortly after the latest batch of updates has been applied. For that reason, a function has been added to Db2 Data Gate that always postpones the execution of queries to such a point in time.
To cause such a delay, you have to add a special register setting (SET CURRENT QUERY WAITFORDATA) at the beginning of the SQL query that is submitted against the target database.
WAITFORDATA delays are valid for synchronized tables only. The thinkable use cases are thus handled as follows:
- Only synchronized tables are referenced by a query
- Query execution is delayed until all referenced tables are synchronized.
- Synchronized and non-synchronized tables are referenced by a query
- The non-synchronized tables are ignored. Query processing starts when the synchronized tables have been updated within the WAITFORDATA delay period.
- Only non-synchronized tables are referenced by a query
- The WAITFORDATA delay is ignored and query processing starts immediately.
- A query references no tables at all
- The delay will be applied none the less, so query processing will be attempted or start after the delay period.
A WAITFORDATA delay period is only considered for SQL queries that read data from tables. Other queries or operations, such as DDL operations, will not be delayed.
Procedure
SET CURRENT QUERY WAITFORDATA = n.m;
where n.m
is a decimal number denoting seconds. The minimum is
0.0
(no delay). The maximum is 3600.0
(a delay of one hour)
SET CURRENT QUERY WAITFORDATA = 120.0;
SELECT * FROM XYZ WHERE [...];
The first line sets the delay of the query execution to 120 seconds. What follows is the SQL code for the query. The execution of the query will be postponed for up to 120 seconds. For all synchronized tables that are referenced by the query, Db2 Data Gate tries to synchronize all committed changes that have been accumulated in the Db2 for z/OS source database at the time the query started. The query will be executed as soon as all required committed changes have been synchronized. If Db2 Data Gate cannot finish the data synchronization during that period, the query fails with a timeout error.
Results
SET
CURRENT QUERY WAITFORDATA
special register, the query is executed, and the result is
returned as usual.If the query fails, one of the error conditions in Table 1 might apply:
Reason | Message text | Common causes/solution |
---|---|---|
SUBSCRIPTION_NOT_RUNNING |
Data synchronization state is invalid. | The data synchronization state of the Db2 Data
Gate instance is not Started. To change
the synchronization state:
|
INVALID_TABLE_STATE |
Tables are in an invalid state. | This condition affects tables in the Error state. It does not apply to tables that are
not enabled for synchronization, which are simply ignored by WAITFORDATA processing. If this error occurs, reload the affected tables. |
TIMEOUT |
Timeout for WAITFORDATA reached. | Pending synchronization updates could not be applied within the WAITFORDATA period. Rerun the query. If it fails again, try a longer WAITFORDATA delay. |