SQLServer_FDW lets PostgreSQL query SQL Server tables natively in a cloud-first setup.
Running micro-services in Kubernetes often means mixing databases. SQLServer_FDW keeps data where it lives while enabling PostgreSQL to JOIN, SELECT, or INSERT into SQL Server—no ETL.
Connect as superuser and run CREATE EXTENSION IF NOT EXISTS sqlserver_fdw;
. The extension ships in popular images like postgres:alpine; otherwise, install the postgresql-XX-sqlserver-fdw
package.
Create a foreign server, user mapping, and foreign table.Use options to define SQL Server host, port, and database. COPY bulk loads are also supported.
After defining the foreign table, reference it like any PostgreSQL table. Combine it with local tables for analytics, or wrap it in a view for developers.
Yes—INSERT
, UPDATE
, and DELETE
work if readonly
is off in IMPORT FOREIGN SCHEMA
.Use transactions for safety.
IMPORT FOREIGN SCHEMA
to refresh metadata automatically.COLUMN OPTIONS (column_name 'true')
to push filters down for performance.Missing COLLATE—SQL Server uses case-insensitive collations. Explicitly cast text with COLLATE "C"
in JOINs.
Forgetting firewall rules—Cloud MSSQL needs an inbound rule for the Postgres pod IP.
The query below shows real-time SQL Server order totals beside PostgreSQL product cost.
SELECT p.id, p.name, oi.quantity, oi.quantity * p.price AS line_total
.
FROM orderitems_mssql oi
JOIN products p ON p.id = oi.product_id;
Yes. It is maintained by the PostgreSQL community and widely deployed. Test performance and failover in staging.
Predicate pushdown works for simple filters. Complex aggregates may execute locally; monitor EXPLAIN
plans.
Run IMPORT FOREIGN SCHEMA
again or drop and recreate the foreign table.