Migrate PostgreSQL to SQL Server
Certified — live-tested pathThe converter maps 18 PostgreSQL column types to SQL Server. 3 of them change kind on the way (json becomes NVARCHAR(MAX), jsonb becomes NVARCHAR(MAX), uuid becomes NVARCHAR(255)); the table below lists every one. DBShifts converts the schema, copies the rows in parallel batches and checks the result with row counts and checksums.
Free tier · no credit card
PostgreSQL vs SQL Server
PostgreSQL
the most advanced open-source relational database.
SQL Server
Microsoft's enterprise relational database.
PostgreSQL to SQL Server data type mapping
Pulled directly from DBShifts's own conversion rules — not a general reference table, this is what actually runs.
| PostgreSQL | SQL Server |
|---|---|
| integer | INT |
| bigint | BIGINT |
| smallint | SMALLINT |
| boolean | BIT |
| numeric(10,2) | DECIMAL(10,2) |
| real | FLOAT |
| double precision | FLOAT(53) |
| varchar(255) | NVARCHAR(255) |
| text | NVARCHAR(MAX) |
| char(10) | NCHAR(10) |
| date | DATE |
| timestamp | DATETIME2 |
| timestamptz | DATETIMEOFFSET |
| time | TIME |
| bytea | VARBINARY(MAX) |
| json | NVARCHAR(MAX) |
| jsonb | NVARCHAR(MAX) |
| uuid | NVARCHAR(255) |
Example: PostgreSQL to SQL Server schema conversion
PostgreSQL
CREATE TABLE orders ( id bigserial PRIMARY KEY, customer_id integer NOT NULL, total numeric(10,2) NOT NULL, is_gift boolean NOT NULL DEFAULT false, notes text, metadata jsonb, placed_at timestamptz NOT NULL );
SQL Server
IF OBJECT_ID(N'orders', 'U') IS NULL
CREATE TABLE [orders] (
[id] BIGINT IDENTITY(1,1) NOT NULL,
[customer_id] INT NOT NULL,
[total] DECIMAL(10,2) NOT NULL,
[is_gift] BIT NOT NULL DEFAULT 0,
[notes] NVARCHAR(MAX),
[metadata] NVARCHAR(MAX),
[placed_at] DATETIMEOFFSET NOT NULL,
CONSTRAINT [PK_orders] PRIMARY KEY ([id])
);text becomes NVARCHAR(MAX), which cannot be indexed
text maps to NVARCHAR(MAX). SQL Server stores NVARCHAR as UTF-16, two bytes per character for most text, so mostly-ASCII data roughly doubles in size. The bigger issue is indexing: an NVARCHAR(MAX) column cannot be an index key, so an index or unique constraint on a PostgreSQL text column has nothing to land on.
For any text column that carries an index, choose a bounded NVARCHAR(n) before the load. SQL Server's nonclustered key limit is 1,700 bytes, which is 850 UTF-16 characters, and an email or a slug fits comfortably inside that.
boolean becomes BIT, uuid becomes text
boolean becomes BIT. T-SQL has no TRUE or FALSE literals, so WHERE is_gift becomes WHERE is_gift = 1, and every query testing a boolean bare needs that change.
uuid lands as NVARCHAR(255). UNIQUEIDENTIFIER would store it in sixteen bytes, but SQL Server sorts UNIQUEIDENTIFIER by its own byte order, the last six bytes first, so ORDER BY on it disagrees with PostgreSQL. Keep text if anything sorts by the id; switch if only equality lookups touch it.
ON CONFLICT and RETURNING
INSERT … ON CONFLICT has no T-SQL form. SQL Server upserts with MERGE, or an UPDATE followed by an INSERT where no row matched, and both need care under concurrency. RETURNING becomes OUTPUT INSERTED.col.
The rewriter's residue check catches a statement that still contains ON CONFLICT after the rewrite and reports it as not converted, so an upsert does not reach the target looking finished when it is not.
PostgreSQL → SQL Server conversion notes
Engine-specific rules baked into the conversion and transfer pipeline — verified by live certification of this exact pair.
- Arrays (integer[], text[]) are preserved natively on PostgreSQL targets and serialized to JSON elsewhere.
- JSONB, UUID, INET and other rich types fall back to portable representations with every downgrade recorded in the fidelity report.
- SERIAL/identity sequences are recreated and reseeded on the target.
- IDENTITY_INSERT is managed per table so explicit IDs from the source load correctly, then counters are reseeded with DBCC CHECKIDENT.
- Binary columns always carry an explicit length — bare VARBINARY (which means 1 byte) never reaches the target.
- TRUNCATE falls back to DELETE on FK-referenced tables automatically.
Frequently asked questions
Is PostgreSQL to SQL Server migration production-ready in DBShifts?
Yes. PostgreSQL to SQL Server is a certified pair: it passes the live certification suite on real PostgreSQL and SQL Server servers, which checks schema fidelity, row counts, type-aware checksums and paging across batches.
What happens to PostgreSQL types that SQL Server doesn't have?
Each gets the nearest SQL Server type the converter treats as safe: json becomes NVARCHAR(MAX), jsonb becomes NVARCHAR(MAX), uuid becomes NVARCHAR(255). Every such decision is in the migration plan before anything runs, and any mapping can be overridden per column.
Can I keep PostgreSQL and SQL Server in sync after the initial migration?
Yes, until you cut over. DBShifts uses logical decoding through a replication slot, which needs wal_level = logical and the wal2json plugin on the server. With zero-downtime mode on, the slot is created before the first row is copied, so it holds every change made during the copy.
Which PostgreSQL data types need a second look when moving to SQL Server?
The table above carries a note on 3 of them: timestamptz (DATETIMEOFFSET), bytea (VARBINARY(MAX)), jsonb (NVARCHAR(MAX)). Analysis flags the same columns on your own schema before any data moves.
Go deeper
How We Live-Certified All 49 Migration Paths
The certification harness behind this page's claims.
Zero-Downtime Migration with Change Data Capture
Snapshot, stream the changes made meanwhile, and stay in sync until cutover.
Reference
Compared with other tools
Ready to move PostgreSQL to SQL Server?
Set up in under two minutes. Validation and rollback included.
Start Free Migration