Run a real PostgreSQL server, extensions included, from .NET code and tests on Windows, Linux (glibc and Alpine/musl) and macOS. No Docker and no local Postgres install required. The library downloads minimal, small sized binaries for your platform once, verifies them, and shares them across every project on the machine.
Documentation: mysticmind.github.io/mysticmind-postgresembed
If you have benefitted from this library and it has saved you a bunch of time, please feel free to sponsor my work!
- .NET 8 or later (the package targets .NET 8, 9, 10 and 11)
- Windows x64, Linux x64/arm64 (glibc or musl), macOS x64/arm64. Windows on Arm runs the x64 build under emulation.
- Postgres refuses to run as root/Administrator, so run your tests as a regular user (this matters in Docker containers)
dotnet add package MysticMind.PostgresEmbedawait using var server = new PgServer("17");
await server.StartAsync();
// trust authentication: no password needed
await using var conn = new NpgsqlConnection(server.ConnectionString);
await conn.OpenAsync();
await using var cmd = new NpgsqlCommand("CREATE TABLE books(id int PRIMARY KEY, title text)", conn);
await cmd.ExecuteNonQueryAsync();The first start downloads the binaries; later starts take about a second. Disposing the server stops it. See Getting Started.
- Versions: an exact version
(
17.6.0) or a spec (17,17.6,latest) resolved to the newest one published for your platform. - Named instances: keep a server and its data between runs; another process, or the pgembed CLI, attaches to it in milliseconds.
- Downloads and cache: one shared cache per user, checksum-verified downloads, warming the cache ahead of time, progress reports, mirrors.
- Extensions: the bundled ones, and extension archives the library installs for you.
- Tests and CI: an xUnit fixture that shares one server, and caching the binaries in CI.
Every option is in the Options reference. Upgrading from v4? See Upgrading to v5. Something not working? See Troubleshooting.
postgresis the default database and the default superuser.- The server listens on localhost only and uses trust authentication: it is made for local development and tests.
- If the test process exits without disposing the server, the library makes a best effort to kill the server, so tests do not leave Postgres behind.
- This project uses the minimal Postgres binaries published by zonkyio/embedded-postgres-binaries.
- Yandex Embedded PostgreSQL and OpenTable Embedded PostgreSQL Component were useful references while designing the implementation.
MysticMind.PostgresEmbed is licensed under the MIT License. Refer to the License file for more information.
Copyright © 2023-2026 Babu Annamalai