Skip to content
tds_fdw

tds_fdw

tds_fdw : Foreign data wrapper for querying a TDS database (Sybase or Microsoft SQL Server)

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
8620
tds_fdw
tds_fdw
2.0.5
FDW
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
mysql_fdw
oracle_fdw
babelfishpg_tsql
babelfishpg_tds
wrappers
odbc_fdw
jdbc_fdw
db2_fdw

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
2.0.5
18
17
16
15
14
tds_fdw-
RPM
PGDG
2.0.5
18
17
16
15
14
tds_fdw_$v-
DEB
PGDG
2.0.5
18
17
16
15
14
postgresql-$v-tds-fdw-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
el8.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
el9.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
el9.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
el10.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
el10.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
d12.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
d12.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
d13.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
d13.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
u22.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
u22.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
u24.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
u24.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
u26.x86_64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
u26.aarch64
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PGDG 2.0.5
PackageVersionOSORGSIZEFile URL
tds_fdw_182.0.5el8.x86_64pgdg49.7 KiBtds_fdw_18-2.0.5-1PGDG.rhel8.x86_64.rpm
tds_fdw_182.0.5el8.aarch64pgdg47.1 KiBtds_fdw_18-2.0.5-1PGDG.rhel8.aarch64.rpm
tds_fdw_182.0.5el9.x86_64pgdg47.8 KiBtds_fdw_18-2.0.5-1PGDG.rhel9.x86_64.rpm
tds_fdw_182.0.5el9.aarch64pgdg45.7 KiBtds_fdw_18-2.0.5-1PGDG.rhel9.aarch64.rpm
tds_fdw_182.0.5el10.x86_64pgdg48.4 KiBtds_fdw_18-2.0.5-1PGDG.rhel10.x86_64.rpm
tds_fdw_182.0.5el10.aarch64pgdg47.3 KiBtds_fdw_18-2.0.5-1PGDG.rhel10.aarch64.rpm
postgresql-18-tds-fdw2.0.5d12.x86_64pgdg111.9 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg12+1_amd64.deb
postgresql-18-tds-fdw2.0.5d12.x86_64pgdg111.7 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg12+1_amd64.deb
postgresql-18-tds-fdw2.0.5d12.aarch64pgdg109.1 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg12+1_arm64.deb
postgresql-18-tds-fdw2.0.5d12.aarch64pgdg109.0 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg12+1_arm64.deb
postgresql-18-tds-fdw2.0.5d13.x86_64pgdg111.4 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg13+1_amd64.deb
postgresql-18-tds-fdw2.0.5d13.x86_64pgdg111.8 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg13+1_amd64.deb
postgresql-18-tds-fdw2.0.5d13.aarch64pgdg109.5 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg13+1_arm64.deb
postgresql-18-tds-fdw2.0.5d13.aarch64pgdg109.3 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg13+1_arm64.deb
postgresql-18-tds-fdw2.0.5u22.x86_64pgdg112.5 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg22.04+1_amd64.deb
postgresql-18-tds-fdw2.0.5u22.x86_64pgdg112.5 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg22.04+1_amd64.deb
postgresql-18-tds-fdw2.0.5u22.aarch64pgdg109.3 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg22.04+1_arm64.deb
postgresql-18-tds-fdw2.0.5u22.aarch64pgdg109.3 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg22.04+1_arm64.deb
postgresql-18-tds-fdw2.0.5u24.x86_64pgdg109.8 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg24.04+1_amd64.deb
postgresql-18-tds-fdw2.0.5u24.x86_64pgdg109.9 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg24.04+1_amd64.deb
postgresql-18-tds-fdw2.0.5u24.aarch64pgdg107.3 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg24.04+1_arm64.deb
postgresql-18-tds-fdw2.0.5u24.aarch64pgdg107.2 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg24.04+1_arm64.deb
postgresql-18-tds-fdw2.0.5u26.x86_64pgdg108.4 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg26.04+1_amd64.deb
postgresql-18-tds-fdw2.0.5u26.x86_64pgdg108.8 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg26.04+1_amd64.deb
postgresql-18-tds-fdw2.0.5u26.aarch64pgdg106.4 KiBpostgresql-18-tds-fdw_2.0.5-2.pgdg26.04+1_arm64.deb
postgresql-18-tds-fdw2.0.5u26.aarch64pgdg106.4 KiBpostgresql-18-tds-fdw_2.0.5-1.pgdg26.04+1_arm64.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

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

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

Create this extension with:

CREATE EXTENSION tds_fdw;

Usage

tds_fdw is a foreign data wrapper for querying TDS databases such as Sybase and Microsoft SQL Server through a DB-Library implementation such as FreeTDS.

Create Server

CREATE EXTENSION tds_fdw;

CREATE SERVER mssql_svr
  FOREIGN DATA WRAPPER tds_fdw
  OPTIONS (servername '127.0.0.1', port '1433',
           database 'tds_fdw_test', tds_version '7.1');

Server Options: servername (server address or DSN, supports comma-separated failover list), port, database, dbuse (0 for direct connection, non-0 for dbuse()), tds_version (protocol version), language, character_set, msg_handler (notice or blackhole), sqlserver_ansi_mode, fdw_startup_cost, fdw_tuple_cost.

Create User Mapping

CREATE USER MAPPING FOR postgres
  SERVER mssql_svr
  OPTIONS (username 'sa', password 'secret');

For Azure SQL databases, use the format username@servername for the username option.

Create Foreign Table

Map a remote table directly:

CREATE FOREIGN TABLE mssql_table (
  id integer,
  name varchar(255),
  value numeric(10,2)
)
SERVER mssql_svr
OPTIONS (schema_name 'dbo', table_name 'mytable');

Or use a custom SQL query:

CREATE FOREIGN TABLE mssql_query (
  id integer,
  name varchar(255),
  total numeric(10,2)
)
SERVER mssql_svr
OPTIONS (query 'SELECT id, name, SUM(amount) AS total FROM orders GROUP BY id, name');

Table Options: table_name or query (one required, mutually exclusive), schema_name, match_column_names (map by name vs position), use_remote_estimate, local_tuple_estimate, row_estimate_method (execute or showplan_all).

Column Options: column_name (remote column name if different from local).

Query and Debug

SELECT * FROM mssql_table WHERE id > 100;

-- View the remote query sent to SQL Server
EXPLAIN (VERBOSE) SELECT * FROM mssql_table WHERE id > 100;

Import Foreign Schema

IMPORT FOREIGN SCHEMA dbo
  FROM SERVER mssql_svr
  INTO public
  OPTIONS (import_default 'true');

Import Options: import_default, import_not_null, and keep_custom_types for preserving Sybase user-defined types when matching PostgreSQL domains already exist.

Planner And Runtime Notes

The upstream README says the current version does not support join pushdown or write operations. It does support WHERE and column pushdown when match_column_names is enabled.

Set diagnostic memory-stat variables with PostgreSQL SET, for example:

SET tds_fdw.show_finished_memory_stats = 1;

Available variables are tds_fdw.show_before_row_memory_stats, tds_fdw.show_after_row_memory_stats, and tds_fdw.show_finished_memory_stats.

Pigsty package metadata is version 2.0.5 from PGDG for PostgreSQL 14-18. Upstream docs say the FDW should support PostgreSQL 9.2+ and the current build matrix includes PostgreSQL 13-18, but this stub follows the packaged PostgreSQL versions from db/extension.csv.

Last updated on