db2_fdw
db2_fdw : foreign data wrapper for DB2 access
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 8630 | db2_fdw | db2_fdw | 18.2.0 |
FDW | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | db_migrator db2fce pg_statement_rollback mysql_fdw orafce postgres_fdw tds_fdw oracle_fdw sqlite_fdw informix_fdw |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 18.2.0 |
18 17 16 15 14 | db2_fdw |
- |
| RPM | PGDG | 18.2.0 |
18 17 16 15 14 | db2_fdw_$v |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 |
| el8.aarch64 | N/A | N/A | N/A | N/A | N/A |
| el9.x86_64 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 |
| el9.aarch64 | N/A | N/A | N/A | N/A | N/A |
| el10.x86_64 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 | PGDG 18.2.0 |
| el10.aarch64 | N/A | N/A | N/A | N/A | N/A |
| d12.x86_64 | N/A | N/A | N/A | N/A | N/A |
| d12.aarch64 | N/A | N/A | N/A | N/A | N/A |
| d13.x86_64 | N/A | N/A | N/A | N/A | N/A |
| d13.aarch64 | N/A | N/A | N/A | N/A | N/A |
| u22.x86_64 | N/A | N/A | N/A | N/A | N/A |
| u22.aarch64 | N/A | N/A | N/A | N/A | N/A |
| u24.x86_64 | N/A | N/A | N/A | N/A | N/A |
| u24.aarch64 | N/A | N/A | N/A | N/A | N/A |
| u26.x86_64 | N/A | N/A | N/A | N/A | N/A |
| u26.aarch64 | N/A | N/A | N/A | N/A | N/A |
Source
github.com/pg-fdw/db2_fdw
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
db2_fdw 18.2.0 queries and modifies IBM Db2 tables through PostgreSQL foreign tables. It pushes down supported filters and only the required columns. Upstream requires PostgreSQL 10.1 or later and an IBM Db2 client 11.1 or later with the same architecture as PostgreSQL. The server process must be able to load that client and access the configured database; installing this extension does not supply the external client or a Db2 server.
Connect and Import Tables
The example assumes that the Db2 client can connect to the catalogued SAMPLE database and that DB2INST1.EMPLOYEE exists. Install the extension as a superuser, then create the server and a role-specific mapping. Use the actual Db2 credentials instead of the example password:
Importing obtains the Db2 column metadata required by the wrapper. Default smart case folding lowercases all-uppercase names. A separate application role needs USAGE on the foreign server, its own user mapping, and appropriate schema/table privileges. Avoid a PUBLIC mapping when credentials are meant for one role. Empty user/password strings select the upstream external-authentication path and depend on the Db2 client environment.
Options and Writes
- Server
dbserverselects the Db2 connection;no_encoding_errorcontrols handling of encoding-conversion errors.batch_sizeis reserved in this release and should not be treated as working batch insertion. - Table
schemaandtableidentify the remote object;readonlyprohibits modifications.prefetchdefaults to 100 and accepts 0–1024;fetch_sizeis accepted but currently fixed to 1.sample_percentcontrols ANALYZE sampling. - Column
keymust identify every remote primary-key column forUPDATEandDELETE. Imported metadata includesdb2type,db2size,db2bytes,db2chars,db2scale,db2nullanddb2ccsid; preserve it when altering imported tables. - IMPORT FOREIGN SCHEMA options
caseandreadonlycontrol name folding and whether imported tables permit writes.
INSERT, UPDATE and DELETE additionally require Db2-side privileges. Review column mapping and remote key definitions before enabling writes; PostgreSQL declarations alone do not create a remote primary key. Unsupported filters are evaluated locally, so inspect EXPLAIN before assuming pushdown.
Diagnostics and Transactions
db2_diag() reports local client/build diagnostics and optionally remote-server details. db2_close_connections() closes connections cached by the current backend; do not call it within a transaction that has modified Db2 data. Long-lived PostgreSQL sessions can retain remote connections and transaction resources.
Types and Maintenance
Common mappings include character types to text/character, BLOB to bytea, integer types to PostgreSQL integer types, and DATE/TIMESTAMP/TIME to their corresponding types. The declared PostgreSQL type and width must accommodate the remote values; failed conversions surface at query time. The control version is 18.2.0 and is relocatable. Normal use requires no shared preload. Follow the versioned README for IBM client environment and connectivity requirements, and distinguish a package upgrade from validation against the actual external database.