PostgreSQL vs SQL Server for .NET Developers

databasedotnetpostgresqlsql-server
PostgreSQL vs SQL Server for .NET Developers

For two decades, .NET shops picked SQL Server by default. The license was already paid for, the tooling was great, and everything Microsoft published assumed it.

That default no longer holds. Microsoft's own eShop reference app runs on PostgreSQL, and Aspire ships a PostgreSQL hosting integration, even though the dotnet new templates with Individual auth still default to SQLite (or SQL Server LocalDB with --use-local-db). This comparison covers what changes in your code, operations, and costs when you move.

The Bill Comes First

Cost is usually the main driver.

  • SQL Server Standard is licensed per core in two-core packs. Microsoft's estimated retail price for SQL Server 2025 is $3,945 per pack for a perpetual license (Software Assurance is extra), or $1,418 per pack per year as a subscription. A modest 8-core production server is a five-figure line item, and that's before your standby replica.
  • SQL Server in the cloud carries the license inside the hourly rate. An Azure SQL or RDS SQL Server instance costs a multiple of the same-sized PostgreSQL instance.
  • PostgreSQL is free to self-host, and managed Postgres (RDS, Azure Database for PostgreSQL, Cloud SQL, Neon, Supabase) costs less than managed SQL Server on the same hardware, because no license is built into the rate. The exception is the smallest tier: Azure SQL Database Basic costs less per month than the smallest Azure Database for PostgreSQL flexible server.

There are legitimate reasons to pay for SQL Server. But if you're paying it out of inertia, that's a per-core license purchase (plus Software Assurance) or a subscription bill every year, for features you may not use.

Express Edition is free, but SQL Server 2025 limits it to 50 GB per database, 4 cores, and about 1.4 GB of buffer pool memory, which rules it out for most production workloads.

Provider and Ecosystem: A Tie

The fear used to be that Postgres was a second-class citizen in .NET. That hasn't been true for years.

Npgsql is one of the best ADO.NET providers, and Npgsql.EntityFrameworkCore.PostgreSQL tracks EF Core releases closely, often shipping provider support for new EF features before other third-party providers.

dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseNpgsql(builder.Configuration.GetConnectionString("Database")));

Dapper, ADO.NET, health checks, OpenTelemetry instrumentation, Testcontainers, Aspire integrations: everything you use with SQL Server exists for Postgres, at the same quality. If you're starting fresh, I have a full walkthrough in EF Core with PostgreSQL: getting started.

What Changes in Your Code

Switching providers takes more than a connection string change, and the differences show up in specific, predictable places.

UTC timestamps are enforced. Npgsql maps DateTime to timestamptz and throws if you write a DateTime whose Kind isn't Utc. This is the most common migration error, and the exception keeps ambiguous timestamps out of the database. I broke down the fix in the EF Core PostgreSQL DateTime UTC error.

Concurrency tokens work differently. SQL Server uses a rowversion column. Postgres has a built-in system column, xmin, that changes on every update, so you don't add a column at all:

modelBuilder.Entity<Order>()
    .Property<uint>("xmin")
    .IsRowVersion();

The mechanics are in EF Core optimistic concurrency with xmin.

Identifier casing. Postgres folds unquoted identifiers to lowercase, and the usual convention is snake_case. The EFCore.NamingConventions package handles it in one line:

options.UseNpgsql(connectionString).UseSnakeCaseNamingConvention();

SQL dialect differences. If you have raw SQL, expect to translate: TOP becomes LIMIT, GETUTCDATE() becomes now(), NEWID() becomes gen_random_uuid(), string concatenation with + becomes ||, and MERGE exists in both but with different syntax and semantics. Stored procedures move from T-SQL to PL/pgSQL, which is a real porting effort if you have hundreds of them; I show the Postgres side in using stored procedures and functions with EF Core and PostgreSQL.

Migrations must be regenerated. EF Core migrations encode provider-specific SQL, so you delete and re-scaffold them against the new provider rather than reusing them.

Where PostgreSQL Is Ahead

A few capabilities are stronger or more mature in Postgres, and they change how you design:

  • jsonb. Real binary JSON with indexing and containment operators, integrated with EF Core's JSON column mapping. SQL Server 2025 added a native json type and JSON indexes, while Postgres has had jsonb with GIN indexing since version 9.4 (2014).
  • Rich types. Arrays, ranges, inet, composite types, and enums map directly to .NET types through Npgsql. An int[] column with a contains query replaces an entire join table in the right situation.
  • Extensions. pgvector turns your database into a vector store for AI features (pgvector in .NET), PostGIS is the industry-standard geospatial engine, and pg_partman automates partition lifecycle.

Full-text search is not on this list, because SQL Server ships Full-Text Search in every edition too. The Postgres version is good enough to skip Elasticsearch for many workloads (PostgreSQL full-text search with EF Core), but it's no reason to switch on its own.

Where SQL Server Still Wins

  • Tooling. SSMS plus Query Store is still the best "why is this slow" experience. Postgres gives you pg_stat_statements and EXPLAIN, which do the job but are rawer.
  • Columnstore indexes. For heavy analytics inside the operational database, clustered columnstore is excellent. Postgres needs an extension or a separate analytical store for the same job.
  • Enterprise security features. Always Encrypted, Dynamic Data Masking, and mature Transparent Data Encryption ship in the box. Postgres covers encryption at rest through the platform, which is usually fine but less granular.
  • In-house expertise. If your team has 15 years of SQL Server operational experience (backups, DMVs, execution plans), that knowledge has real value and Postgres resets part of it.
  • The Microsoft stack. SSIS, on-premises reporting (SSRS, folded into Power BI Report Server as of SQL Server 2025), and deep Active Directory integration matter in enterprises that already run on them.

One difference that cuts both ways: both databases default to read committed isolation, but SQL Server's default implementation is lock-based (readers and writers block each other unless RCSI is enabled), while Postgres is MVCC throughout. Workloads that felt deadlock-prone on SQL Server often just work on Postgres, but code that accidentally relied on blocking behavior can surface race conditions you now have to handle explicitly.

How to Choose

The differences side by side:

ConcernPostgreSQLSQL Server
LicenseFree to self-hostStandard: $3,945 per two-core pack, or $1,418 per pack per year
Managed cloud priceNo license in the hourly rateLicense included in the hourly rate
Concurrency tokenxmin system columnrowversion column
Read committedMVCC, readers and writers do not blockLock-based unless RCSI is enabled
JSONjsonb with GIN indexing since 9.4Native json type and JSON indexes in SQL Server 2025
Analytics on operational dataNeeds an extension or a separate storeColumnstore indexes
Security featuresEncryption at rest through the platformAlways Encrypted, Dynamic Data Masking, TDE
Toolingpg_stat_statements and EXPLAINSSMS and Query Store

Rules of thumb for the decision:

  • New project, no constraints: PostgreSQL. Lower cost, richer type system, and extensions give you options (vectors, geo, partitioning) you don't know you need yet.
  • Existing SQL Server system that works: stay. A migration is a project, and "save on licensing" alone rarely justifies rewriting hundreds of stored procedures.
  • Heavy analytical queries on operational data: SQL Server's columnstore is a legitimate reason to pay.
  • AI features on the roadmap: Postgres with pgvector keeps vector search in the same database as the rest of your data. SQL Server 2025 added a native vector type too, but its DiskANN vector index still requires preview features.
  • Regulated enterprise with SQL Server-specific security requirements: the Enterprise Edition features may be non-negotiable.

If you do migrate, treat it as a real project: regenerate migrations, audit every raw SQL string, fix the UTC DateTime issues, port stored procedures, and run both databases side by side behind an interface until the numbers match. If the application is embedded, single-node, and mostly single-writer, SQLite with EF Core may be a better fit than either server database.

Summary

The .NET-on-Postgres stack is mainstream. Npgsql and the EF Core provider are excellent, the dialect differences are finite and well-documented, and PostgreSQL removes a per-core license that costs thousands of dollars per server.

SQL Server still earns its license in specific places: columnstore analytics, enterprise security features, and teams whose operational expertise is already there.

Pick based on those specifics.

Frequently Asked Questions

Is PostgreSQL a good choice for .NET applications?

Yes. The Npgsql ADO.NET and EF Core providers are actively maintained and track EF Core releases closely. Microsoft runs its eShop reference application on PostgreSQL, and Aspire ships a PostgreSQL hosting integration.

How much does SQL Server cost compared to PostgreSQL?

SQL Server 2025 Standard is licensed per core in two-core packs, at an estimated retail price of $3,945 per pack (about $1,970 per core) for a perpetual license, or $1,418 per pack per year as a subscription. Managed SQL Server also costs more in the cloud, because the license is part of the hourly rate. PostgreSQL is free to self-host, and managed PostgreSQL is consistently the cheaper tier at the same hardware size.

What changes in EF Core when switching from SQL Server to PostgreSQL?

You swap the provider package, regenerate migrations, and adjust a few behaviors: timestamp columns require UTC DateTime values, identifiers become snake_case by convention if you opt in, and concurrency tokens use the xmin system column instead of rowversion.

Does PostgreSQL have something like SQL Server Management Studio?

pgAdmin is the closest equivalent, and JetBrains DataGrip, DBeaver, and the database tools in Rider and VS Code cover most workflows. SSMS is still more polished for deep engine administration.

  • Using Read Replicas in .NET Applications

    Routing reads to replicas is the standard way to scale a read-heavy database, but replication lag introduces a new class of bugs. Here is how to route queries to replicas in .NET with EF Core, and how to protect read-your-writes consistency while doing it.

  • Distributed Locking With Postgres Advisory Locks in .NET

    You probably do not need Redis, RedLock, or ZooKeeper for distributed locking. If your instances already share a Postgres database, they share a lock manager too. Session-level advisory locks serialize work across every instance and auto-release when the holder's connection closes. TTL-based leases approximate that with expiry times and fencing tokens.

  • Reading PostgreSQL Query Plans With EXPLAIN ANALYZE

    Most developers run EXPLAIN ANALYZE, see "Seq Scan", and start adding indexes. That reflex is often wrong. Here is how to read a PostgreSQL query plan: costs, actual times, row estimates, and buffers, and how to find the node that takes the most time.

Browse all Databases guides →
Loading comments...

Whenever you're ready, there are 5 ways I can help you:

  1. Pragmatic Self-Hosting: Learn to deploy and run your apps on a VPS with Dokploy and Tailscale. Keep administration private, automate releases, and practice restoring backups, with source code and a runbook you can reuse.
  2. Pragmatic Clean Architecture: Join 5,000+ students in this comprehensive course that will teach you the system I use to ship production-ready applications using Clean Architecture. Learn how to apply the best practices of modern software architecture.
  3. Modular Monolith Architecture: Join 2,800+ engineers in this in-depth course that will transform the way you build modern systems. You will learn the best practices for applying the Modular Monolith architecture in a real-world scenario.
  4. Pragmatic REST APIs: Join 1,900+ students in this course that will teach you how to build production-ready REST APIs using the latest ASP.NET Core features and best practices. It includes a fully functional UI application that we'll integrate with the REST API.
  5. Patreon Community: Join a community of 5,000+ engineers and software architects. You will also unlock access to the source code I use in my YouTube videos, early access to future videos, and exclusive discounts for my courses.

The .NET Weekly

One practical .NET tip, every Saturday.

Join 66,000+ engineers who read it. Free, and you can unsubscribe any time.