Skip to content
jdbc_fdw

jdbc_fdw

jdbc_fdw : foreign-data wrapper for remote servers available over JDBC

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
8530
jdbc_fdw
jdbc_fdw
0.5.0
FDW
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
wrappers
multicorn
odbc_fdw
oracle_fdw
mysql_fdw
tds_fdw
db2_fdw
postgres_fdw

Package/source version 0.5.0; SQL extension version 1.2. PGDG RPM is PG14-16 and missing EL aarch64; PIGSTY DEB is PG14-18 on amd64 and arm64, with a downstream PG18 compatibility patch. Live queries require a JDBC driver and remote database.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
MIXED
0.5.0
18
17
16
15
14
jdbc_fdw-
RPM
PGDG
0.4.0
18
17
16
15
14
jdbc_fdw_$vjava-11-openjdk-headless
DEB
PIGSTY
0.5.0
18
17
16
15
14
postgresql-$v-jdbc-fdwdefault-jre-headless, libpq5
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
MISS
MISS
PGDG 0.4.0
PGDG 0.4.0
PGDG 0.4.0
el8.aarch64
MISS
MISS
MISS
MISS
MISS
el9.x86_64
MISS
MISS
PGDG 0.4.0
PGDG 0.4.0
PGDG 0.4.0
el9.aarch64
MISS
MISS
MISS
MISS
MISS
el10.x86_64
MISS
MISS
MISS
MISS
MISS
el10.aarch64
MISS
MISS
MISS
MISS
MISS
d12.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
d12.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
d13.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
d13.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
u22.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
u22.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
u24.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
u24.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
u26.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
u26.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PIGSTY 0.5.0
PackageVersionOSORGSIZEFile URL
postgresql-18-jdbc-fdw0.5.0d12.x86_64pigsty129.5 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-jdbc-fdw0.5.0d12.aarch64pigsty126.7 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-jdbc-fdw0.5.0d13.x86_64pigsty129.5 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~trixie_amd64.deb
postgresql-18-jdbc-fdw0.5.0d13.aarch64pigsty126.5 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~trixie_arm64.deb
postgresql-18-jdbc-fdw0.5.0u22.x86_64pigsty140.1 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~jammy_amd64.deb
postgresql-18-jdbc-fdw0.5.0u22.aarch64pigsty138.4 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~jammy_arm64.deb
postgresql-18-jdbc-fdw0.5.0u24.x86_64pigsty134.9 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~noble_amd64.deb
postgresql-18-jdbc-fdw0.5.0u24.aarch64pigsty133.9 KiBpostgresql-18-jdbc-fdw_0.5.0-1PIGSTY~noble_arm64.deb
postgresql-18-jdbc-fdw0.5.0u26.x86_64pigsty133.8 KiBpostgresql-18-jdbc-fdw_0.5.0-2PIGSTY~resolute_amd64.deb
postgresql-18-jdbc-fdw0.5.0u26.aarch64pigsty132.1 KiBpostgresql-18-jdbc-fdw_0.5.0-2PIGSTY~resolute_arm64.deb

Source

pig build pkg jdbc_fdw;		# build deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install jdbc_fdw;		# install via package name, for the active PG version

pig install jdbc_fdw -v 18;   # install for PG 18
pig install jdbc_fdw -v 17;   # install for PG 17
pig install jdbc_fdw -v 16;   # install for PG 16
pig install jdbc_fdw -v 15;   # install for PG 15
pig install jdbc_fdw -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION jdbc_fdw;

Usage

jdbc_fdw: Foreign data wrapper for remote servers available over JDBC

Create Server

CREATE EXTENSION jdbc_fdw;

CREATE SERVER jdbc_server FOREIGN DATA WRAPPER jdbc_fdw
  OPTIONS (
    drivername 'org.postgresql.Driver',
    url 'jdbc:postgresql://remotehost:5432/mydb',
    jarfile '/usr/share/java/postgresql.jar',
    maxheapsize '256'
  );

Server Options: drivername (required, JDBC driver class), url (required, JDBC connection URL), jarfile (required, absolute path to JDBC driver JAR), querytimeout (query timeout in seconds), maxheapsize (JVM heap size in MB, minimum 1).

Create User Mapping

CREATE USER MAPPING FOR CURRENT_USER SERVER jdbc_server
  OPTIONS (username 'dbuser', password 'dbpass');

Create Foreign Table

CREATE FOREIGN TABLE remote_table (
  id integer OPTIONS (key 'true'),
  name text,
  value numeric
)
SERVER jdbc_server
OPTIONS (table_name 'schema.tablename');

Set key 'true' on primary key columns to enable UPDATE and DELETE operations.

Query Remote Data

SELECT * FROM remote_table WHERE id > 100;

Execute Arbitrary SQL with jdbc_exec

The jdbc_exec function executes SQL against the remote database and returns result sets:

SELECT * FROM jdbc_exec('jdbc_server', 'SELECT id, name FROM remote_schema.remote_table WHERE status = 1')
  AS t(id integer, name text);

This is useful for executing queries that go beyond the foreign table definition, including DDL or complex queries on the remote server.

Last updated on