Run Microsoft SQL Server locally via Docker and access it from PostgreSQL with tds_fdw.
Self-hosting places Microsoft SQL Server on your own machine or server—no Azure or AWS required. You control versions, patches, and data residency.
Install Docker 24+, psql 15+, and your favorite SQL editor. Allocate ≥4 GB RAM and open port 1433.
Run the Docker command in the Syntax section. It pulls the 2022 image, accepts the EULA, exposes port 1433, and persists data in a named volume.
Connect with sqlcmd or Azure Data Studio and execute T-SQL:
CREATE DATABASE shop;
GO
USE shop;
CREATE TABLE Customers(id INT PRIMARY KEY, name NVARCHAR(50), email NVARCHAR(80), created_at DATETIME);
CREATE TABLE Orders(id INT PRIMARY KEY, customer_id INT, order_date DATETIME, total_amount DECIMAL(10,2));
CREATE TABLE Products(id INT PRIMARY KEY, name NVARCHAR(60), price DECIMAL(10,2), stock INT);
CREATE TABLE OrderItems(id INT PRIMARY KEY, order_id INT, product_id INT, quantity INT);
Install tds_fdw, then run:
CREATE EXTENSION IF NOT EXISTS tds_fdw;
CREATE SERVER mssql_srv FOREIGN DATA WRAPPER tds_fdw OPTIONS (servername 'localhost', port '1433', database 'shop');
CREATE USER MAPPING FOR postgres SERVER mssql_srv OPTIONS (username 'sa', password 'Str0ngPass!');
IMPORT FOREIGN SCHEMA dbo LIMIT TO (Customers, Orders, Products, OrderItems) FROM SERVER mssql_srv INTO public;
Once foreign tables exist, reference them like local tables:
SELECT c.name, SUM(o.total_amount) AS lifetime_value
FROM Customers c
JOIN Orders o ON o.customer_id = c.id
GROUP BY c.name
ORDER BY lifetime_value DESC;
Use strong SA passwords, enable automatic backups via --mount
, monitor container logs, and schedule OS-level updates.
See the section below for quick remedies.
No. You can install the native Linux or Windows packages, but Docker offers faster setup and isolation.
Yes—INSERT, UPDATE, and DELETE work if the foreign table has a primary key and you set row_estimate_method
properly.
Use the Azure SQL Edge image or run SQL Server in an x86-64 VM, because the official image targets AMD64.