开发者

.NET connector for PostgreSQL

开发者 https://www.devze.com 2023-01-04 11:05 出处:网络
Last time I used Npgsql, i.e., version 1.0, it worked very slow. Is there any开发者_运维问答 other alternative to Npgsql? Version 1.0 is three years old. Try to use the newest one.Npgsql is an excelle

Last time I used Npgsql, i.e., version 1.0, it worked very slow. Is there any开发者_运维问答 other alternative to Npgsql?


Version 1.0 is three years old. Try to use the newest one.


Npgsql is an excellent connector. Just upgrade to the new one. Make sure you take a look at the documentation it is really good. That will solve the speed issue.

You asked about an alternative, so I also have to recommend an another good connector: dotConnect for PostgreSQL. It is made by Devart. There is a simple free one as well as a fully robust pay connector. The pay one has Linq and entity framework support. http://www.devart.com/dotconnect/postgresql/


I have experience with the .NET MySQL connector. What you are describing seems to be a DNS issue. If you are using a URL in your connection string and are able to change it to an IP address, try that and see if your delay goes away.


npgsql is still the choice for .NET when connecting to PostgreSQL.

Since version 1.0, the connector has improved drastically, check out this presentation from Shay Rojansky; it is not the latest, still the boost was already quite impressive in 2018/11.

If you are upgrading from an old version, read the release notes of the latest carefully, you might break functionality in your code.

Also, I strongly recommend considering optimizing PostgreSQL as well. I work with it daily in a distributed enterprise environment, with massive workloads; it can be tuned and tweaked with a dramatic impact on the overall performance.


  1. As @yojimbo87 told upgrade to newer connector version. Try that.
  2. Use entity core framework. Npgsql has an Entity Framework (EF) Core provider.
  3. Use Postgres 11
  4. Check connection pool setting Like most ADO.NET providers, Npgsql uses connection pooling by default. When you Close() the NpgsqlConnection object, an internal object representing the actual underlying connection that Npgsql uses goes into a pool to be re-used, saving the overhead of creating another unnecessarily.

This suits most applications well, as it's common to want to use a connection several times in the space of a second.

It doesn't suit you at all, but if you include the option Pooling=false in your connection string, it will override this default, and Close() will indeed close the actual connection.

Npgsql has an Entity Framework (EF) Core provider. It behaves like other EF Core providers (e.g. SQL Server), so the general EF Core docs apply here as well. If you're just getting started with EF Core, those docs are the best place to start.

Development happens in the Npgsql.EntityFrameworkCore.PostgreSQL repository, all issues should be reported there. https://www.npgsql.org/efcore/index.html

0

精彩评论

暂无评论...
验证码 换一张
取 消