MSSQL to PostgreSQL: Migrate Tables and Identity

Read the SQL Server table, query or whole schema and write it into PostgreSQL — types mapped, identity kept as identity, no .bak restore and no CSV file in between.

Download DBCopier — free trial

Version 3.1.2 · Windows, Linux, macOS · 30-day free trial, then $129 one-time · runs fully offline

DBCopier: SQL Server to PostgreSQL batch copy, source and target mapped in one session

How to Transfer SQL Server to PostgreSQL in Four Steps

Step 1: Connect to SQL Server

Server, port (1433), database, and either SQL Server authentication or Windows authentication — a Named Instance and an SSH tunnel are both supported.

Step 1 screenshot

Step 2: Connect to PostgreSQL

Host, port (5432), database, schema, user and password. The same form works for a local server, RDS, Aurora and Azure Database for PostgreSQL.

Step 2 screenshot

Step 3: Pick tables or a query and map the columns

A whole schema, one table, a SELECT, many tables, or similar tables merged into one. The PostgreSQL DDL is generated from the SQL Server definition; replace or append is chosen here.

Step 3 screenshot

Step 4: Run it and check the row counts

Compare count(*) on both sides, then look at one uniqueidentifier and one money value — those are the columns that need an explicit mapping.

Step 4 screenshot

Eight Operations, Three Load Modes

Eight operations, one dialog. Each one is a mode of the same session — the screenshot beside it is what that mode looks like:

Migrate the whole database

Every SQL Server table becomes a PostgreSQL table in one run, and IDENTITY becomes an identity column rather than a plain integer. 📷

Copy one table

The target table is built from the SQL Server definition; nothing else in the database is touched, and the rest of the schema stays as it was. 📷

Copy a query result

Filters and joins run on the SQL Server side and only the returned rows are written — a derived column belongs in the SELECT. 📷

Batch copy many tables

Each table maps to its own target table, replace or append is decided per table, and the whole batch runs from one session you can save. 📷

Merge similar tables into one

One table per month or per branch becomes a single PostgreSQL table; columns are matched by name and rows appended in the order you pick. 📷

Convert SQL Server types

nvarchar to text, datetime2 to timestamp, bit to boolean, uniqueidentifier to uuid, varbinary to bytea. 📷

Keep both sides in step

A full sync replaces the contents; an incremental sync upserts on the key you name, so a nightly run writes only the rows that changed. 📷

Schedule it

The saved session runs from Task Scheduler, cron or launchd, or straight from DBCopier schedule --daily=02:30 --install. 📷

Three load modes, plus one that is often what a “schema migration” search actually means:

  • Replace — the target table is truncated and refilled. Right for a lookup table rebuilt from the source.
  • Append — rows are added. Right when the source itself only holds new rows.
  • Incremental upsert — rows are matched on the key you name and only changed ones are written: sync table data from mssql to postgres run on a timer, not a change stream.
  • Schema only — the DDL is generated and the data is skipped, for the “migrate sql server schema to postgresql” case where the tables are filled by the application afterwards.

SQL Server to PostgreSQL — Type Mapping

What the generated DDL does by default; every row can be overridden per column:

SQL ServerPostgreSQL
int / bigint / smallintinteger / bigint / smallint
tinyint (0–255)smallint — PostgreSQL has no unsigned byte
bitboolean
decimal(p,s) / numeric(p,s)numeric(p,s)
float / realdouble precision / real
moneynumeric(19,4) — money is not a type in PostgreSQL
nvarchar(n) / varchar(n)varchar(n) — or text when n is max
char(n) / nchar(n)char(n)
text / ntexttext
datedate
datetime / datetime2timestamp
datetimeoffsettimestamptz
timetime
uniqueidentifieruuid
varbinary(max) / imagebytea
xmlxml
rowversion / timestampbytea — it is a version stamp, not a time
IDENTITYgenerated identity column, keeping the seed and increment

Managed Target Requirements

The copy is the same; the target's rules are not. All three managed services bring the following, and each one fails in a way that looks like a bad password:

  • SSL is required — a plain connection is refused, so enable SSL on the PostgreSQL side of the session.
  • No superuser — the account cannot create extensions or reassign ownership; the schema it writes into has to already exist and be writable.
  • An IP allowlist — Aurora security groups, Azure firewall rules and RDS VPC settings all block the first connection from an unknown address.
  • Aurora Serverless and Azure Burstable tiers can pause or throttle, which turns a large copy into a timeout rather than an error.

What This Tool Does Not Convert

It moves tables, views' underlying data and query results — not the code around them. Knowing the line is worth more than a failed run:

  • Stored procedures, functions and triggers — T-SQL is not PL/pgSQL. Rewriting them is a code translation job (SSMA and friends), and no table copy does it for you.
  • Views, jobs, SSIS packages and logins — not data, so not copied. A view can be recreated on the target as a query.
  • Collation and case sensitivity — SQL Server databases are often case-insensitive, PostgreSQL is case-sensitive by its own rules; a CITEXT extension or a normalised column is a decision for the target, not a mapping option.
  • Identity values in an existing table — if the target table already exists, the column is written as an ordinary value; only a generated table keeps identity semantics.

Common Pitfalls when Migrating SQL Server to PostgreSQL

  • money, uniqueidentifier, hierarchyid and rowversion need an explicit mapping. They have no same-name equivalent, and the default guess is not always what the application expects — especially rowversion, which is a version stamp, not a timestamp.
  • tinyint is unsigned in SQL Server and PostgreSQL has no unsigned byte: the column becomes smallint, and a report that groups by it will now show 200 where the old one showed -56.
  • An empty string and NULL are different here. SQL Server treats '' as an empty value, Oracle-style systems treat it as NULL; PostgreSQL keeps the empty string, so a NOT NULL column that arrived as '' is data the application did not expect.
  • Case matters after the move. An unquoted identifier is folded to lower case in PostgreSQL, so CustomerID becomes customerid — fine for the database, fatal for an application that quoted its column names.
  • A large copy on a managed target can time out. Aurora Serverless and Azure Burstable tiers pause or throttle; run it during a stable window or in batches rather than blaming the tool for a stalled transfer.

Automate with the CLI

The application is its own command line — DBCopier on Windows, DBCopierCmd on Linux, the binary inside the .app on macOS. A nightly sync is the same session, run headless:

# the task saved from the GUI: source table, mapping and target collection
DBCopier session="mssql-to-postgres.uld" logfile="mssql-to-postgres.log"

# what it would do, without writing
DBCopier session="mssql-to-postgres.uld" --dry-run

# nightly at 02:30 - prints the scheduler entry, --install writes it
DBCopier schedule --session="mssql-to-postgres.uld" --daily=02:30 --install

One-off with no session file: DBCopier copy --from="SQLServer:sa:pw@db.local:1433/sales" --from-table=ORDERS --to="PostgreSQL:postgres:pw@pg.local:5432/sales" --to-table=orders. The full command set is on DBCopier command line.

Which Searches Land Here

This page is the SQL Server → PostgreSQL direction: migrate sql server to postgresql, sql server to postgresql migration, migrate from sql to postgresql, migrate data from sql server to postgresql, sql to postgresql.

  • “migration tool” / “migration challenges” — the mapping table and the pitfalls above are the challenges; the tool is a table copy, not a code converter.
  • “to aurora” / “to azure” — same copy, different target rules; see the managed-target section.
  • “stored procedure” — out of scope, and said so above rather than in small print.
  • the reverse direction — PostgreSQL to SQL Server.

Frequently Asked Questions

Do I need a .bak restore or a CSV file in between?
Neither. DBCopier connects to both servers and writes the rows over the connection — no backup file, no CSV staging, and no intermediate disk copy of the data.
How are identity columns and money handled?
IDENTITY becomes a PostgreSQL generated identity column with the same seed and increment; money becomes numeric(19,4), because PostgreSQL has no money type. Both can be overridden per column.
Can I migrate only the schema, without the data?
Yes — the DDL is generated from the SQL Server definition and the data step is skipped, which is the usual case when the application will fill the tables itself.
Does it work with Aurora and Azure Database for PostgreSQL?
Yes, with the target's own conditions: SSL on, an account without superuser rights writing into an existing schema, and the client IP allowed by the security group or firewall.
Are stored procedures and views migrated?
No. Tables and query results are copied; T-SQL procedures, functions and triggers need a code translation tool. A view can be recreated on PostgreSQL as a query.
Can I schedule a sync instead of a one-off migration?
Yes — save the session, then let Task Scheduler, cron or launchd run it, or use DBCopier schedule --daily=02:30 --install. Incremental sync upserts on the key you name; full sync replaces the target contents.
Why did the column names come out in lower case?
PostgreSQL folds unquoted identifiers to lower case, so CustomerID becomes customerid. An application that quotes its identifiers needs the target column created with quotes to match.
Can I copy many tables at once?
Yes — a whole schema, a list of tables, or a folder of similar tables merged into one target, in a single session.

Start Transfer SQL Server Data to PostgreSQL Now

Get the full version of DBCopier for your operating system — $129 one-time, volume discounts to $99, 30-day money-back.

$75 one-time · volume discounts to $55 · 30-day money-back · pricing & licence terms

Download DBCopier Free Trial