Skip to content
Arijit Das
DatabasePostgreSQLMigration

Migrating SQL Server to PostgreSQL Without Downtime: Lessons from the Field

8 min read

The first time I migrated a production SQL Server database to PostgreSQL, I expected the hard part to be data types. It wasn't. The hard part was trust — getting a team to believe the new database would behave exactly like the old one, under load, on the first try.

Here's what actually mattered, in the order it mattered.

Dry-run everything before it's real

Every migration run in our tool starts in dry-run mode. It connects to the source schema, builds a full type-mapping plan against the target, and reports every conflict before a single row moves. varchar(max) becoming text, identity columns becoming sequences, case-sensitive collations quietly changing behavior — all of it surfaces on paper first.

This sounds obvious. It's still the step most migrations skip under deadline pressure, and it's the step that catches almost everything expensive.

Archive before you migrate, not after

We treated archival as a precondition, not a follow-up task. Cutting years of cold, rarely-queried history out of the working set before migration meant:

  • A smaller, faster migration window with less that could go wrong mid-transfer
  • A cleaner target schema, unburdened by legacy columns nobody remembered the purpose of
  • An archival pipeline that had already been tested and trusted by the time migration day arrived
The safest migration is the one moving the least amount of data possible — everything else is a separate problem you've already solved.

Chunk it, log it, make it resumable

Nobody wants to restart a six-hour migration from zero because row 4.2 million hit a constraint violation. Every batch is sized, logged with a checkpoint, and safe to resume:

MIGRATE TABLE orders
  BATCH_SIZE 5000
  CHECKPOINT orders_migration_log
  ON_CONFLICT log_and_skip

Failures become a short list to review afterward, not a full-stop incident.

The type conflicts that actually bite

A short list of the specific SQL Server → PostgreSQL differences that caused real issues, not textbook ones:

  • Identity columns: mapping IDENTITY(1,1) to a PostgreSQL SERIAL/sequence correctly, including resetting the sequence's current value after a bulk load
  • Collation and case sensitivity: SQL Server's default collation is often case-insensitive; PostgreSQL's isn't. Search and uniqueness logic that relied on that silently broke
  • Datetime precision: rounding differences between datetime and timestamp that only showed up in reports doing date-range comparisons

What "done" actually looked like

The migration was considered successful only after running both databases in parallel for a defined window, comparing row counts and checksums on critical tables, and confirming report outputs matched exactly. Boring, unglamorous, and exactly the point — a migration nobody notices happened is the best possible outcome.

DatabasePostgreSQLMigration
Arijit Das
Arijit Das
Full Stack Web Developer — writes about web development, backend systems & databases

Facing something similar?

I take on freelance and collaborative web development projects around exactly this kind of work.