Skip to content

About

Postgres embedded server equivalent including extensions for .Net applications

Topics

Resources

Stars

169 stars

Watchers

4 watching

Forks

Repository files navigation

MysticMind.PostgresEmbed icon: an elephant standing on a window of code

MysticMind.PostgresEmbed Postgres embedded database equivalent for .Net applications Build status NuGet Version

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!

GitHub Sponsor

Requirements

  • .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)

Getting started

dotnet add package MysticMind.PostgresEmbed
await 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.

What it does

  • 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.

Good to know

  • postgres is 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.

Acknowledgements

License

MysticMind.PostgresEmbed is licensed under the MIT License. Refer to the License file for more information.

Copyright © 2023-2026 Babu Annamalai

About

Postgres embedded server equivalent including extensions for .Net applications

Topics

Resources

Stars

169 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages