Use the tds_fdw foreign-data wrapper to connect PostgreSQL to an AWS-hosted Microsoft SQL Server instance and run cross-database queries.
Centralizing analysis eliminates ETL overhead, lets teams join PostgreSQL data with AWS SQL Server data instantly, and keeps a single source of truth inside your main warehouse.
A running AWS RDS or EC2 SQL Server instance, network access (VPC or public IP), PostgreSQL 13+ with superuser rights, and the tds_fdw
or tds_fdw
-based package such as pgsql-tds-fdw
.
On Ubuntu 22.04 run: sudo apt-get install postgresql-13-tds-fdw freetds-bin
.Mac users can use Homebrew.
Connect as superuser and run CREATE EXTENSION IF NOT EXISTS tds_fdw;
. Verify with \dx
.
Define a foreign server that points at the RDS endpoint, port 1433, and target database.Store credentials in CREATE USER MAPPING
.
Run IMPORT FOREIGN SCHEMA
to create read-through tables like customers
, orders
, and products
in your PostgreSQL public
schema.
Query the foreign tables just like local ones.PostgreSQL planner will push eligible filters down to SQL Server, minimizing network traffic.
Select only needed columns, add indexes in SQL Server to match join predicates, and use SET tds_fdw.fetch_size
for large result sets.
Mismatched data types: Cast SQL Server DATETIME2
to PostgreSQL TIMESTAMP
explicitly.
Network timeouts: Open port 1433 in the AWS security group and increase tds_fdw.connection_timeout
.
.
Yes. Define UPDATE, INSERT, or DELETE permissions in the user mapping and ensure foreign tables have OPTIONS (updatable 'true')
. Test on staging first.
tds_fdw can use FreeTDS SSL parameters. Add encrypt 'yes'
and sslmode 'require'
in CREATE SERVER OPTIONS for encrypted traffic.
Most WHERE clauses and projections are pushed to SQL Server. Check EXPLAIN; lines showing Remote SQL
confirm server-side execution.