Search code examples
postgresqlentity-framework.net-corenpgsqlpgbouncer

Is PgBouncer needed for .NET Core applications with Entity Framework (Npgsql)?


EF registers as scoped service, which means it creates many short connections to database. One http request - one connection. PostgreSQL doesn't handle a lot of concurrent connections very well. Like a maximum of 100. Is PgBouncer needed for .NET Core applications with Entity Framework (Npgsql)? PgBouncer manages the connection pool. Or can Npgsql manage the connection pool correctly? Or is this only relevant for Python and PHP? Thanks!


Solution

  • Npgsql includes its own in-process connection pool (as is common with .NET database drivers), so using an external connection pool such as PgBouncer isn't mandatory (though it can still make sense in some scenarios for pooling connections across several client machines, etc.).