db2_fdw
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
db2_fdw | 18.1.1 | FDW | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 8630 | db2_fdw | No | Yes | No | Yes | No | No | - |
| Related | odbc_fdw mysql_fdw oracle_fdw tds_fdw wrappers multicorn jdbc_fdw postgres_fdw |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 18.1.1 | 1817161514 | db2_fdw | - |
| RPM | PGDG | 18.1.1 | 1817161514 | db2_fdw_$v | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 18.1.2 | PGDG 18.1.2 el8.x86_64.pg14 : db2_fdw_14 db2_fdw_14-18.1.2-1PGDG.rhel8.10.x86_64.rpm
db2_fdw_14-18.1.1-1PGDG.rhel8.10.x86_64.rpm
db2_fdw_14-18.0.1-2PGDG.rhel8.x86_64.rpm
db2_fdw_14-18.0.1-1PGDG.rhel8.x86_64.rpm
db2_fdw_14-7.0.0-1PGDG.rhel8.x86_64.rpm
db2_fdw_14-6.0.1-1PGDG.rhel8.x86_64.rpm
db2_fdw_14-5.0.0-1.rhel8.x86_64.rpm
| |||
| el8.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el9.x86_64 | PGDG 18.1.2 | PGDG 18.1.2 el9.x86_64.pg14 : db2_fdw_14 db2_fdw_14-18.1.2-1PGDG.rhel9.7.x86_64.rpm
db2_fdw_14-18.1.1-1PGDG.rhel9.7.x86_64.rpm
db2_fdw_14-18.0.1-2PGDG.rhel9.x86_64.rpm
db2_fdw_14-18.0.1-1PGDG.rhel9.x86_64.rpm
db2_fdw_14-7.0.0-1PGDG.rhel9.x86_64.rpm
db2_fdw_14-6.0.1-1PGDG.rhel9.x86_64.rpm
db2_fdw_14-5.0.0-1.rhel9.x86_64.rpm
| |||
| el9.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el10.x86_64 | PGDG 18.1.2 | ||||
| el10.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| d12.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| d12.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| d13.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| d13.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| u22.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| u22.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| u24.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| u24.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| u26.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| u26.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
Install
You can install db2_fdw directly. First, make sure the PGDG repository is added and enabled:
pig repo add pgdg -u # Add PGDG repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install db2_fdw; # Install for current active PG version
pig ext install -y db2_fdw -v 18 # PG 18
pig ext install -y db2_fdw -v 17 # PG 17
pig ext install -y db2_fdw -v 16 # PG 16
pig ext install -y db2_fdw -v 15 # PG 15
pig ext install -y db2_fdw -v 14 # PG 14
dnf install -y db2_fdw_18 # PG 18
dnf install -y db2_fdw_17 # PG 17
dnf install -y db2_fdw_16 # PG 16
dnf install -y db2_fdw_15 # PG 15
dnf install -y db2_fdw_14 # PG 14
Create Extension:
CREATE EXTENSION db2_fdw;
Usage
Sources: README, current upstream README
db2_fdw is a PostgreSQL foreign data wrapper for querying and modifying IBM Db2 tables from PostgreSQL. It pushes down required columns and WHERE conditions where possible, and provides helper functions for connection cleanup and diagnostics.
Create Server
CREATE EXTENSION db2_fdw;
CREATE SERVER db2srv FOREIGN DATA WRAPPER db2_fdw
OPTIONS (dbserver 'SAMPLE');
Server options: dbserver (required Db2 connection string), batch_size (currently reserved for future batch behavior), and no_encoding_error (ON, OFF, YES, NO, TRUE, or FALSE).
Create User Mapping
CREATE USER MAPPING FOR PUBLIC SERVER db2srv
OPTIONS (user 'db2inst1', password 'secret');
Use empty strings for user and password to enable external authentication through the Db2 client environment.
Create Foreign Table
CREATE FOREIGN TABLE employee (
empno char(6) OPTIONS (key 'true'),
firstname varchar(12),
lastname varchar(15),
salary numeric
)
SERVER db2srv
OPTIONS (schema 'DB2INST1', table 'EMPLOYEE');
Table options: table (required, Db2 table name or simple query, case-sensitive, typically uppercase), schema (table owner), readonly (default false), sample_percent (ANALYZE sampling), prefetch (rows per round-trip, default 100, range 0-1024), fetch_size (accepted but currently fixed at 1), batch_size, and no_encoding_error. max_long is documented upstream as deprecated and no longer used.
Column options: key (set to true for all primary key columns, required for UPDATE and DELETE), plus Db2 metadata options such as db2type, db2size, db2bytes, db2chars, db2scale, db2null, and db2ccsid on imported tables.
Import Foreign Schema
IMPORT FOREIGN SCHEMA "DB2INST1" FROM SERVER db2srv INTO public;
Import Options: case (keep, lower, or smart, default smart), readonly.
CRUD Operations
SELECT * FROM employee WHERE empno = '000010';
INSERT INTO employee (empno, firstname, lastname, salary) VALUES ('999999', 'John', 'Doe', 50000);
UPDATE employee SET salary = 55000 WHERE empno = '999999';
DELETE FROM employee WHERE empno = '999999';
Connection Helpers
SELECT db2_close_connections();
SELECT db2_diag();
SELECT db2_diag('db2srv');
db2_close_connections() closes cached Db2 connections in the current session. db2_diag() reports db2_fdw, PostgreSQL, Db2 client, and optionally remote server diagnostic details.
Data Type Mapping
| DB2 Type | PostgreSQL Types |
|---|---|
| CHAR | char |
| VARCHAR | varchar |
| CLOB | text |
| VARGRAPHIC, GRAPHIC | text |
| BLOB | bytea |
| SMALLINT, INTEGER, BIGINT | smallint, integer, bigint |
| DOUBLE | numeric, float |
| DATE | date |
| TIMESTAMP | timestamp |
| TIME | time |
WHERE conditions and column projections are pushed down to DB2 to minimize data transfer.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.