Why smaller businesses switch
Usually it is the licence. PostgreSQL costs nothing to use, in production too. Microsoft lists SQL Server Standard at $3,945 per 2-core pack and Enterprise at $15,123 per 2-core pack. If you would rather pay as you go, Standard is $1,418 a year per 2 cores as a subscription, or $73 per core per month billed through Azure Arc. These are Microsoft’s estimated retail prices in dollars, excluding VAT; your reseller sets the final price.
The second reason is that new projects tend to start on PostgreSQL now. Ours do as well – new systems go on PostgreSQL, while MySQL and MariaDB stay where the data already lives. We have deliberately left more than 130 million rows in MySQL because moving them would not make them better. A migration should pay for itself; otherwise it is only risk.
The honest counter-argument: SQL Server Express is free. From SQL Server 2025 an Express database may grow to 50 GB, but the engine uses at most 4 cores and 1,410 MB of buffer pool. If your database is small and the system is a packaged product whose vendor supports only SQL Server, Express is often the cheapest answer. You don’t migrate – you change edition.
Licence cost for a small server
The formula is list price × number of packs × 6.80. We assume 4 cores for core licensing and 10 users for server + CAL. Put in your own numbers, and check the licensing guide’s minimum-core rules before you buy.
| Model | Calculation | In DKK |
|---|---|---|
| Standard, server + 10 CALs (one-off) | $989 + 10 × $230 = $3,289 | about 22,365 |
| Standard, 4 cores (one-off) | 2 × $3,945 = $7,890 | about 53,652 |
| Standard, 4 cores, subscription | 2 × $1,418 = $2,836 a year | about 19,285 a year |
| Standard, 4 cores, pay as you go (Azure Arc) | 4 × $73 = $292 a month | about 1,986 a month |
| Enterprise, 4 cores (one-off) | 2 × $15,123 = $30,246 | about 205,673 |
| PostgreSQL on your own Hetzner server (CPX22) | €16.99 a month, licence 0 | about 127 a month |
The licence is only half the sum. The migration itself costs hours, and those hours decide whether it pays off. Three tables and no procedures can move in a day; a system with a hundred stored procedures can take weeks. The Hetzner row is a server with 2 vCPU and 4 GB RAM at €16.99 a month excluding VAT, checked 20.11.2026 – and you run it yourselves.
The types you have to translate
Most types have a direct counterpart. The trouble comes from small differences: amounts that lose their decimals, timestamps that move by an hour, and lookups that suddenly care about upper and lower case.
SQL Server → PostgreSQL type mapping
| SQL Server | PostgreSQL | What we saw and did |
|---|---|---|
INT IDENTITY(1,1) | bigserial or integer GENERATED … AS IDENTITY | pgloader created bigserial and set the sequence correctly |
BIT | boolean | Worked as is |
TINYINT | smallint | SQL Server allows 0–255, so smallint is required |
MONEY | numeric(19,2) or numeric(19,4) | Became numeric without scale; we set numeric(19,2) |
NVARCHAR(n), VARCHAR(n) | text or varchar(n) | Became text; Danish letters, Cyrillic and emoji survived |
DATETIME, DATETIME2 | timestamptz or timestamp | Read in the session time zone – see below |
DATETIMEOFFSET | timestamptz | Carries its own offset, the easy one |
UNIQUEIDENTIFIER | uuid | Needs a transform; values matched on both sides |
VARBINARY(MAX) | bytea | – |
Computed column AS (…) PERSISTED | GENERATED ALWAYS AS (…) STORED | Became a plain column; we recreated it |
DEFAULT NEWID() / SYSUTCDATETIME() | gen_random_uuid() / now() | SYSUTCDATETIME() stopped the whole run |
Collation …_CI_AS | case-sensitive | email = 'SOEREN@…' found 1 row in SQL Server, 0 in PostgreSQL |
pgloader’s documented defaults turn bit into boolean, money into numeric, text types into text and uniqueidentifier into uuid. AWS DMS has its own type table and, among other things, does not carry over a column’s identity property.
Three tools for three different jobs
pgloader, AWS DMS or Babelfish?
| Criterion | pgloader | AWS DMS | Babelfish for PostgreSQL |
|---|---|---|---|
| What it does | Copies schema and data in one go | Copies data and can keep it in sync (CDC) | Lets PostgreSQL speak SQL Server’s wire protocol and T-SQL |
| Price | Free, open source | Per hour for a replication instance, or per capacity on serverless; schema conversion is free | Open source; on AWS as part of Aurora PostgreSQL |
| Downtime | Writes must stop during the copy | Can be kept short with ongoing replication | The app can keep much of its SQL |
| Procedures and triggers | Not migrated | Not part of the data copy | Run as T-SQL “with some differences” |
| Requirements | Network access to both databases | Full or Bulk-logged recovery model plus MS-CDC or MS-Replication for CDC | Aurora PostgreSQL or your own build of the project |
| Fits | Small and mid-size databases with a maintenance window | Large databases that cannot stop | An application whose code you cannot change |
pgloader is what we use for MySQL migrations, so it is what we tested here. Its documentation now describes a version 4 with Microsoft’s JDBC driver, but the Debian package is 3.6.10 with FreeTDS, and that is what most people get from apt install pgloader.
AWS DMS is built for large databases and short downtime. Ongoing replication needs full backups and the Full or Bulk-logged recovery model, and the limitations list is long: sparse columns, temporal tables and changes to computed columns are among the things it does not handle. You pay per hour for the instance doing the copy, plus storage.
Babelfish takes a different route: the data moves, but the application keeps talking T-SQL on port 1433 while PostgreSQL clients use 5432. AWS itself says T-SQL runs “with some differences”. It suits an old application without source code, but it ties you to Aurora or to building and updating the project yourselves.
The load file we ran
The test ran in throwaway Docker containers on our own test machine: SQL Server 2022 Developer, PostgreSQL 18.6 and pgloader 3.6.10. The source database had Danish and Ukrainian names, amounts in MONEY, a computed VAT column, a foreign key, a view and a stored procedure. The containers were deleted afterwards.
-- shop.load – run with: pgloader shop.load
-- The password comes from the environment: export MIGRATE_PASSWORD=...
LOAD DATABASE
FROM mssql://migrate:{{MIGRATE_PASSWORD}}@sqlserver:1433/butik
INTO postgresql://migrate:{{MIGRATE_PASSWORD}}@localhost:5432/butik
WITH include drop, create tables, create indexes, foreign keys,
reset sequences, workers = 2, concurrency = 1
SET timezone to 'UTC'
CAST type datetime2 to timestamptz drop default,
type money to numeric drop typemod using float-to-string,
type uniqueidentifier to uuid drop default using sql-server-uniqueidentifier-to-uuid
INCLUDING ONLY TABLE NAMES LIKE '%' IN SCHEMA 'dbo'
ALTER SCHEMA 'dbo' RENAME TO 'public'
AFTER LOAD DO
$$ ALTER TABLE kunde ALTER COLUMN oprettet SET DEFAULT now(); $$,
$$ ALTER TABLE kunde ALTER COLUMN eksternid SET DEFAULT gen_random_uuid(); $$,
$$ ALTER TABLE ordre ALTER COLUMN beloeb TYPE numeric(19,2); $$,
$$ ALTER TABLE ordre DROP COLUMN moms,
ADD COLUMN moms numeric(19,2) GENERATED ALWAYS AS (beloeb * 0.25) STORED; $$;
pgloader 3.6.10 talks to SQL Server through FreeTDS, and without this file in the home directory the run crashed on Danish characters:
# ~/.freetds.conf
[global]
tds version = 7.4
client charset = UTF-8
What we ran into, in the order it happened:
- A
SYSUTCDATETIME()default stopped the whole run because pgloader wrote it as a string literal intoCREATE TABLE. Fix:drop defaultin the CAST rule and set the default again after the load. - “Illegal UTF-8 character” followed by a crash. Fix:
client charset = UTF-8for FreeTDS. - Without the
uniqueidentifiertransform pgloader tried to write raw bytes into a uuid column. Withsql-server-uniqueidentifier-to-uuidthe values matched SQL Server exactly. - Amounts lost their decimals (
1995.0) and the VAT column became a plain column. Both fixed inAFTER LOAD. - Time zones. With
SET timezone to 'Europe/Copenhagen'both time columns moved by an hour – including the one stored in UTC withSYSUTCDATETIME(). Work out which columns hold local time (usuallyGETDATE()), load in UTC and convert only those.
-- Only columns written with GETDATE() in SQL Server (Danish local time)
UPDATE ordre
SET bestilt = (bestilt AT TIME ZONE 'UTC') AT TIME ZONE 'Europe/Copenhagen';
Finally we counted rows on both sides: 3 customers and 5 orders in each, and the sequence carried on at 1005. The view and the procedure did not come across, which is expected – you rewrite those yourselves. The row-count query is on our MySQL migration page. One more trap: our source script first failed in sqlcmd on the table with the computed column, because sqlcmd runs with QUOTED_IDENTIFIER off unless you pass -I.
T-SQL to PL/pgSQL: one worked example
The procedure in the source database creates an order, raises an error when the customer is unknown and returns the new order:
-- SQL Server (T-SQL)
CREATE PROCEDURE dbo.OpretOrdre @KundeId INT, @Beloeb MONEY, @OrdreId INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS (SELECT 1 FROM dbo.Kunde WHERE KundeId = @KundeId AND Aktiv = 1)
THROW 50001, 'Kunden findes ikke eller er inaktiv', 1;
INSERT INTO dbo.Ordre (KundeId, Beloeb) VALUES (@KundeId, @Beloeb);
SET @OrdreId = SCOPE_IDENTITY();
SELECT TOP (1) OrdreId, Beloeb, Moms FROM dbo.Ordre WHERE OrdreId = @OrdreId;
END
The same logic in PostgreSQL. SCOPE_IDENTITY() becomes RETURNING, THROW becomes RAISE EXCEPTION, and the result comes back as a table from a function:
-- PostgreSQL (PL/pgSQL)
CREATE OR REPLACE FUNCTION opret_ordre(p_kunde_id integer, p_beloeb numeric)
RETURNS TABLE (ordre_id bigint, beloeb numeric, moms numeric)
LANGUAGE plpgsql AS $$
DECLARE
v_id bigint;
BEGIN
IF NOT EXISTS (SELECT 1 FROM kunde k WHERE k.kundeid = p_kunde_id AND k.aktiv) THEN
RAISE EXCEPTION 'Kunden findes ikke eller er inaktiv' USING ERRCODE = 'P0001';
END IF;
INSERT INTO ordre (kundeid, beloeb) VALUES (p_kunde_id, p_beloeb)
RETURNING ordre.ordreid INTO v_id; -- replaces SCOPE_IDENTITY()
RETURN QUERY
SELECT o.ordreid, o.beloeb, o.moms FROM ordre o WHERE o.ordreid = v_id;
END;
$$;
SELECT * FROM opret_ordre(2, 500); -- new order, VAT computed by the database
It ran on PostgreSQL 18.6 and matched the SQL Server procedure: a new order of 500.00 with VAT 125.00, and an error for an unknown customer. The application now calls SELECT * FROM opret_ordre(…) instead of EXEC, so the app code changes too. If a migration tool such as Alembic compares schemas on top of the database, learn its traps before you let it near a shared database.
Test checklist before the switch
Tests before leaving SQL Server
| Area | Test | Green when |
|---|---|---|
| Data | Row count per table on both sides | Equal in every table |
| Money | Sum of amount columns per table | Equal to the øre |
| Time | 5 rows with known timestamps compared | No one-hour shift |
| Text | Names with æ, ø, å and other alphabets | Identical text, emoji included |
| Search | Login and lookups typed in capitals | Same result as before (citext or a lower() index) |
| Keys | Insert a new row in every table | No duplicate from the sequence |
| Code | All procedures, triggers and views rewritten | Test suite green against PostgreSQL, not another engine |
| Operations | Backup and restore test of the new database | First nightly copy restored |
| Way back | Old database kept read-only | At least 14 days after the switch |
Run the tests on the real engine. We have seen 320 green tests on SQLite while four tables were dead in production on MySQL. Take a dump right before the switch, as we do before every deploy on bkg.dk. The PostgreSQL backup recipe is on the backup page.
Straight about us: we don’t sell a database and take no commission from Microsoft, AWS or anyone else. We move databases for a fixed price. We have not run Babelfish or AWS DMS ourselves; both are described from their documentation.
Sources
- Microsoft – SQL Server 2025 pricing (datasheet) — Enterprise $15,123 and Standard $3,945 per 2 cores, server $989, CAL $230, subscription and Azure Arc prices, checked 20.11.2026
- Microsoft Learn – Editions of SQL Server 2025 — Express: 50 GB, 4 cores, 1,410 MB buffer pool, checked 20.11.2026
- pgloader – MS SQL to PostgreSQL — default casts, FreeTDS and JDBC, checked 20.11.2026
- AWS DMS – SQL Server as a source — limitations and CDC prerequisites, checked 20.11.2026
- AWS DMS – pricing — hourly replication instances, free schema conversion, checked 20.11.2026
- AWS – Babelfish for Aurora PostgreSQL and babelfishpg.org — ports 1433/5432, T-SQL with differences, open source, checked 20.11.2026
- ECB reference rates — 1 EUR = 7.4746 DKK, 1 EUR = 1.0990 USD, 20.11.2026
Questions about SQL Server and PostgreSQL
How much is a SQL Server licence?
Microsoft’s estimated price for Standard is $3,945 per 2 cores, or $989 per server plus $230 per user or device. As a subscription, $1,418 a year per 2 cores. Excluding VAT; the final price comes from your reseller.
Is there a free SQL Server?
Yes, Express is free. From SQL Server 2025 a database may be 50 GB, but the engine uses at most 4 cores and 1,410 MB of buffer pool. The Developer editions are free for development and test only.
Can pgloader migrate stored procedures?
No. pgloader moves tables, data, indexes, foreign keys and sequences. Procedures, triggers and views are rewritten in PL/pgSQL. In our test the view and the procedure did not come across.
Why are timestamps off after the migration?
Because DATETIME has no time zone. pgloader reads the value in the session time zone. Load in UTC and convert only the columns that were stored in Danish local time.
When should we stay on SQL Server?
When the system is a packaged product that only supports SQL Server, or when the database fits the free Express edition. Then a migration is risk without a payoff.
Fixed price, no commitment
Get a fixed price for your database task
Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.
- A fixed price before we start
- An answer by e-mail, no calls
- Your details are used only to answer you