ADBC Driver for IBM Db2¶
Driver Version 0.1.0-beta.1 Release Date 2026-11-23 Tested With Db2 latest
This driver provides access to IBM Db2 through the Db2 CLI.
Installing the Db2 CLI driver¶
The driver needs IBM’s Db2 CLI driver (the “clidriver”) at run time. Download it from IBM, then tell your system where its libraries are.
Download¶
Open IBM’s download page: https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/
Open the folder for the version you want (for example
v12.1.0) and download the file for your platform:Platform
File
Linux x86-64
linuxx64_odbc_cli.tar.gzmacOS arm64
macarm64_odbc_cli.tar.gzWindows x86-64
ntx64_odbc_cli.zipUnpack the file. It contains a folder named
clidriver. Keep the whole folder; do not copy only thelibdb2library out of it.
To download from a terminal instead (Linux x86-64 shown; change the file name for other platforms):
mkdir -p "$HOME/db2" && cd "$HOME/db2"
curl -fLO https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/v12.1.0/linuxx64_odbc_cli.tar.gz
tar xzf linuxx64_odbc_cli.tar.gz
On macOS, a file downloaded through a browser may be quarantined and the system
may refuse to load libdb2.dylib. Downloading with curl, or running
xattr -dr com.apple.quarantine clidriver on the unpacked folder, avoids this.
Tell the system where the libraries are¶
Set the variable for your platform in the same shell that starts your program,
before it starts. Replace $HOME/db2 with the folder you unpacked into.
Platform |
Variable |
Value |
|---|---|---|
Linux |
|
|
macOS |
|
|
Windows |
|
|
For example, on Linux:
export LD_LIBRARY_PATH="$HOME/db2/clidriver/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
Connecting¶
Provide a Db2 CLI connection string as the uri database option. The driver
passes the string unchanged to the Db2 CLI function SQLDriverConnect, so it
uses Db2 CLI KEYWORD=value; syntax. It is not parsed as a URL.
import os
from adbc_driver_manager import dbapi
with dbapi.connect(
driver="db2",
db_kwargs={
"uri": "DATABASE=testdb;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;"
f"UID=db2inst1;PWD={os.environ['DB2_PASSWORD']}",
},
) as connection:
pass
Keep the password out of your source code, for example by reading it from an environment variable as above.
Keyword |
Meaning |
|---|---|
|
Name of the database to connect to |
|
Host name or IP address of the Db2 server |
|
Port the Db2 server listens on |
|
Communication protocol; use |
|
User name |
|
Password |
Any other Db2 CLI keyword can be added to the string in the same way.
Connecting with SSL¶
SSL needs a port on which the server accepts SSL connections; ask your database
administrator for it. Add SECURITY=SSL to the connection string:
DATABASE=testdb;HOSTNAME=db2.example.com;PORT=50001;PROTOCOL=TCPIP;UID=db2inst1;PWD=...;SECURITY=SSL
Which other settings you need depends on the server certificate:
Certificate signed by a widely used certificate authority. Per IBM’s documentation, the Db2 CLI driver ships a default set of root certificates, so
SECURITY=SSLalone is normally enough.Self-signed or private certificate. Give the driver the server certificate file (
.arm) withSSLServerCertificate:...;SECURITY=SSL;SSLServerCertificate=/path/to/server.arm
Your own client key database. Use
SSLClientKeystoredb(the.kdbfile) andSSLClientKeystash(the.sthfile that holds its password).
SSL uses IBM’s GSKit libraries, which ship inside the clidriver folder, so keep
the folder intact.
You can set these in the connection string as shown, or as separate database options. The driver adds an option’s keyword to the connection string only when that keyword (in the same capitalization) is not already in it, so use one method per setting.
Database option |
Connection string keyword |
Meaning |
|---|---|---|
|
|
|
|
|
Client key database ( |
|
|
Stash file ( |
|
|
Server certificate ( |
import os
from adbc_driver_manager import dbapi
with dbapi.connect(
driver="db2",
db_kwargs={
"uri": "DATABASE=testdb;HOSTNAME=db2.example.com;PORT=50001;PROTOCOL=TCPIP;"
f"UID=db2inst1;PWD={os.environ['DB2_PASSWORD']}",
"db2.ssl.security": "SSL",
"db2.ssl.server_certificate": "/path/to/server.arm",
},
) as connection:
pass
Feature & Type Support¶
| Feature | Db2 | |
|---|---|---|
| Bind Parameters | ✅ | |
| Bulk Ingestion | Create | ✅ |
| Append | ✅ | |
| Create/Append | ✅ | |
| Replace | ✅ | |
| Temporary Table | ❌ | |
| Target Catalog | ❌ | |
| Target Schema | ✅ | |
| Non-nullable fields are marked NOT NULL | ✅ | |
| Catalog (GetObjects) | depth=catalogs | ✅ |
| depth=db_schemas | ✅ | |
| depth=tables | ✅ | |
| depth=columns (all) | ❌ | |
| Get Parameter Schema | ✅ | |
| Get Table Schema | ✅ | |
| Prepared Statements | ✅ | |
| Transactions | ✅ | |
Types¶
Database to Arrow¶
| Database Type | Db2 |
|---|---|
|
BIGINT |
int64 |
|
BOOLEAN |
bool |
|
DATE |
date32[day] |
|
DOUBLE PRECISION |
double |
|
INT |
int32 |
|
NUMERIC |
string [1] |
|
REAL |
float |
|
SMALLINT |
int16 |
|
TIME |
time32[s] ⚠️ [2] |
|
TIMESTAMP |
timestamp[us] |
|
TIMESTAMP(0) |
timestamp[s] |
|
TIMESTAMP(p) (1 <= p <= 3) |
timestamp[ms] |
|
TIMESTAMP(p) (4 <= p <= 6) |
timestamp[us] |
|
TIMESTAMP(p) (7 <= p <= 9) |
timestamp[ns] |
|
VARBINARY |
binary |
|
VARCHAR |
string |
Arrow to Database¶
| Arrow Type | Db2 Type | |
|---|---|---|
| Bind | Ingest | |
|
binary |
VARBINARY |
|
|
binary_view |
VARBINARY |
|
|
bool |
BOOLEAN |
SMALLINT [3] |
|
date32[day] |
DATE |
|
|
decimal128 |
NUMERIC [1] |
DECIMAL [4] |
|
double |
DOUBLE PRECISION |
|
|
fixed_size_binary |
VARBINARY |
|
|
float |
REAL |
|
|
halffloat |
❌ |
(NA/not tested) |
|
int16 |
SMALLINT |
|
|
int32 |
INT |
|
|
int64 |
BIGINT |
|
|
large_binary |
VARBINARY |
|
|
large_string |
VARCHAR |
|
|
string |
VARCHAR |
|
|
string_view |
❌ |
VARCHAR |
|
time32[ms] |
TIME ⚠️ [2] |
|
|
time32[s] |
TIME |
|
|
time64[ns] |
TIME ⚠️ [2] |
|
|
time64[us] |
TIME ⚠️ [2] |
|
|
timestamp[ms] |
TIMESTAMP(3) |
|
|
timestamp[ns] |
TIMESTAMP(9) |
|
|
timestamp[s] |
TIMESTAMP(0) |
|
|
timestamp[us] |
TIMESTAMP(6) |
|
Compatibility¶
This driver was tested on:
DB2/LINUXX8664
12.01.0500