This topic describes the data types and parameters that are supported by Db2 Reader and how to configure Db2 Reader by using the codeless user interface (UI) and code editor.
Background information
Db2 Reader can read data from Db2.
- Db2 Reader generates an SQL statement based on the settings of the table, column, and where parameters and sends the generated statement to the Db2 database.
- If you specify the querySql parameter, Db2 Reader sends the value of this parameter to the Db2 database.
The version of the Db2 JDBC driver that Db2 Reader uses is IBM Data Server Driver for JDBC and SQLJ 4.11.77. For more information about the mapping between the versions of Db2 JDBC drivers and Db2 versions, see IBM Support.
Data types
Db2 Reader supports most Db2 data types. Make sure that the data types of your database are supported.
Data Integration data type | Db2 data type |
---|---|
Integer | SMALLINT |
Floating point | DECIMAL, REAL, and DOUBLE |
String | CHAR, CHARACTER, VARCHAR, GRAPHIC, VARGRAPHIC, LONG VARCHAR, CLOB, LONG VARGRAPHIC, and DBCLOB |
Date and time | DATE, TIME, and TIMESTAMP |
Binary | BLOB |
Parameters
Parameter | Description | Required | Default value |
---|---|---|---|
datasource | The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor. | Yes | No default value |
jdbcUrl | The JDBC URL of the Db2 database. The URL must be in the jdbc:db2://ip:port/database format in accordance with official Db2 specifications. You can also specify the information
of the attachment facility.
|
Yes | No default value |
username | The username that you use to connect to the database. | Yes | No default value |
password | The password that you use to connect to the database. | Yes | No default value |
table | The name of the table from which you want to read data. Each synchronization node can be used to synchronize data to only one table. | Yes | No default value |
column | The names of the columns from which you want to read data. Specify the names in a
JSON array. The default value is [ * ], which indicates all the columns in the source table.
|
Yes | No default value |
splitPk | The field that is used for data sharding when Db2 Reader reads data. If you specify
this parameter, the source table is sharded based on the value of this parameter.
Data Integration then runs parallel threads to read data. This improves data synchronization
efficiency.
|
No | "" |
where | The WHERE clause. Db2 Reader generates an SQL statement based on the settings of the
table, column, and where parameters and uses the generated statement to read data.
For example, you can set this parameter to |
No | No default value |
querySql | The SQL statement that is used for refined data filtering. If you specify this parameter,
Data Integration filters data based on the value of this parameter.
For example, if you want to join multiple tables for data synchronization, set this
parameter to |
No | No default value |
fetchSize | The number of data records to read at a time. This parameter determines the number
of interactions between Data Integration and the database and affects read efficiency.
Note If you set this parameter to a value greater than 2048, an out of memory (OOM) error
may occur during data synchronization.
|
No | 1024 |
Configure Db2 Reader by using the codeless UI
This method is not supported.
Configure Db2 Reader by using the code editor
{
"type":"job",
"version":"2.0",// The version number.
"steps":[
{
"stepType":"db2",// The reader type.
"parameter":{
"password":"",// The password that you use to connect to the Db2 database.
"jdbcUrl":"",// The JDBC URL of the Db2 database.
"column":[
"id"
],
"where":"",// The WHERE clause.
"splitPk":"",// The shard key.
"table":"",// The name of the table from which you want to read data.
"username":""// The username that you use to connect to the Db2 database.
},
"name":"Reader",
"category":"reader"
},
{
"stepType":"stream",
"parameter":{},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":"0"// The maximum number of dirty data records allowed.
},
"speed":{
"throttle":true,// Specifies whether to enable bandwidth throttling. The value false indicates that bandwidth throttling is disabled, and the value true indicates that bandwidth throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"concurrent":1 // The maximum number of parallel threads.
"mbps":"12"// The maximum transmission rate.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Additional information
- Data synchronization between primary and secondary databases
A secondary Db2 database can be deployed for disaster recovery. The secondary database continuously synchronizes data from the primary database based on binary logs. Data latency between the primary and secondary databases cannot be prevented. This may result in data inconsistency.
- Data consistency control
Db2 is a relational database management system (RDBMS) that supports strong consistency for data queries. A database snapshot is created before a synchronization node starts. Db2 Reader reads data from the database snapshot. Therefore, if new data is written to the database during data synchronization, Db2 Reader cannot obtain the new data.
Data consistency cannot be ensured if you enable Db2 Reader to use parallel threads in a single synchronization node.
Db2 Reader shards the source table based on the value of the splitPk parameter and uses parallel threads to read data. These parallel threads belong to different transactions and read data at different points in time. Therefore, the parallel threads observe different snapshots.
Data inconsistencies cannot be prevented if parallel threads are used for a synchronization node. The following workarounds can be used:- Enable Db2 Reader to use a single thread to read data in a synchronization node. This indicates that you do not need to specify a shard key for Db2 Reader. This way, data consistency is ensured, but data is synchronized at low efficiency.
- Make sure that no data is written to the source table during data synchronization. This ensures that the data in the source table remains unchanged during data synchronization. For example, you can lock the source table or disable data synchronization between primary and secondary databases. This way, data is efficiently synchronized, but your ongoing services may be interrupted.
- Character encoding
Db2 Reader uses JDBC to read data. This enables Db2 Reader to automatically convert the encoding formats of characters. Therefore, you do not need to specify the encoding format.
- Incremental data synchronization
Db2 Reader uses JDBC to connect to a database and uses a SELECT statement with a
WHERE
clause to read incremental data.- For batch data, incremental add, update, and delete operations (including logically delete operations) are distinguished by timestamps. Specify the WHERE clause based on a specific timestamp. The time indicated by the timestamp must be later than the time indicated by the latest timestamp in the previous synchronization.
- For streaming data, specify the WHERE clause based on the ID of a specific record. The ID must be greater than the maximum ID involved in the previous synchronization.
If the data that is added or modified cannot be distinguished, Db2 Reader can read only full data.
- Syntax validation
Db2 Reader allows you to specify custom SELECT statements by using the querySql parameter but does not verify the syntax of these statements.