AspNetCore.HealthChecks.NpgSql
9.0.0
dotnet add package AspNetCore.HealthChecks.NpgSql --version 9.0.0
NuGet\Install-Package AspNetCore.HealthChecks.NpgSql -Version 9.0.0
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="9.0.0" />
paket add AspNetCore.HealthChecks.NpgSql --version 9.0.0
#r "nuget: AspNetCore.HealthChecks.NpgSql, 9.0.0"
// Install AspNetCore.HealthChecks.NpgSql as a Cake Addin #addin nuget:?package=AspNetCore.HealthChecks.NpgSql&version=9.0.0 // Install AspNetCore.HealthChecks.NpgSql as a Cake Tool #tool nuget:?package=AspNetCore.HealthChecks.NpgSql&version=9.0.0
PostgreSQL Health Check
This health check verifies the ability to communicate with PostgreSQL. It uses the Npgsql library.
NpgsqlDataSource
Starting with Npgsql 7.0 (and .NET 7), the starting point for any database operation is NpgsqlDataSource. The data source represents your PostgreSQL database, and can hand out connections to it, or support direct execution of SQL against it. The data source encapsulates the various Npgsql configuration needed to connect to PostgreSQL, as well as the connection pooling which makes Npgsql efficient.
Npgsql's data source supports additional configuration beyond the connection string, such as logging, advanced authentication options, type mapping management, and more.
Recommended approach
To take advantage of the performance NpgsqlDataSource
has to offer, it should be used as a singleton. Otherwise, the app might end up with having multiple data source instances, all of which would have their own connection pools. This can lead to resources exhaustion and major performance issues (Example: #1993).
We encourage you to use Npgsql.DependencyInjection package for registering a singleton factory for NpgsqlDataSource
. It allows easy configuration of your Npgsql connections and registers the appropriate services in your DI container.
To make the shift to NpgsqlDataSource
as easy as possible, the Npgsql.DependencyInjection
package registers not just a factory for the data source, but also factory for NpgsqlConnection
(and even DbConnection
). So, your app does not need to suddenly start using NpgsqlDataSource
everywhere.
void Configure(IServiceCollection services)
{
services.AddNpgsqlDataSource("Host=pg_server;Username=test;Password=test;Database=test");
services.AddHealthChecks().AddNpgSql();
}
By default, the NpgsqlDataSource
instance is resolved from service provider. If you need to access more than one PostgreSQL database, you can use keyed DI services to achieve that:
void Configure(IServiceCollection services)
{
services.AddNpgsqlDataSource("Host=pg_server;Username=test;Password=test;Database=first", serviceKey: "first");
services.AddHealthChecks().AddNpgSql(sp => sp.GetRequiredKeyedService<NpgsqlDataSource>("first"));
services.AddNpgsqlDataSource("Host=pg_server;Username=test;Password=test;Database=second", serviceKey: "second");
services.AddHealthChecks().AddNpgSql(sp => sp.GetRequiredKeyedService<NpgsqlDataSource>("second"));
}
Connection String
Raw connection string is of course still supported:
services.AddHealthChecks().AddNpgSql("Host=pg_server;Username=test;Password=test;Database=test");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- Npgsql (>= 8.0.3)
-
net8.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- Npgsql (>= 8.0.3)
NuGet packages (58)
Showing the top 5 NuGet packages that depend on AspNetCore.HealthChecks.NpgSql:
Package | Downloads |
---|---|
Reo.Core.Database
Package Description |
|
Reo.Core.Testing
Package Description |
|
Reo.Core.IntegrationTesting
Package Description |
|
Aspire.Hosting.PostgreSQL
PostgreSQL® support for .NET Aspire. |
|
Aspire.Npgsql
A PostgreSQL® client that integrates with Aspire, including health checks, metrics, logging, and telemetry. |
GitHub repositories (20)
Showing the top 5 popular GitHub repositories that depend on AspNetCore.HealthChecks.NpgSql:
Repository | Stars |
---|---|
dotnet/aspire
Tools, templates, and packages to accelerate building observable, production-ready apps
|
|
Ombi-app/Ombi
Want a Movie or TV Show on Plex/Emby/Jellyfin? Use Ombi!
|
|
skoruba/IdentityServer4.Admin
The administration for the IdentityServer4 and Asp.Net Core Identity
|
|
aspnetrun/run-aspnetcore-microservices
Microservices on .NET platforms used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
|
|
dotnetcore/osharp
OSharp是一个基于.Net6.0的快速开发框架,框架对 AspNetCore 的配置、依赖注入、日志、缓存、实体框架、Mvc(WebApi)、身份认证、功能权限、数据权限等模块进行更高一级的自动化封装,并规范了一套业务实现的代码结构与操作流程,使 .Net 框架更易于应用到实际项目开发中。
|
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 3,570 | 12/19/2024 |
8.0.2 | 1,424,915 | 8/29/2024 |
8.0.1 | 2,745,358 | 4/2/2024 |
8.0.0 | 1,448,836 | 12/15/2023 |
7.1.0 | 1,281,588 | 10/3/2023 |
7.0.0 | 871,670 | 7/30/2023 |
7.0.0-rc2.7 | 65,629 | 3/13/2023 |
7.0.0-rc2.6 | 38,914 | 1/14/2023 |
7.0.0-rc2.5 | 23,874 | 12/27/2022 |
7.0.0-rc2.4 | 435 | 12/27/2022 |
6.0.2 | 10,114,706 | 2/28/2022 |
6.0.1 | 948,582 | 12/29/2021 |
6.0.1-rc2.3 | 35,961 | 11/10/2021 |
6.0.1-rc1.2 | 2,341 | 11/5/2021 |
6.0.0 | 96,363 | 12/29/2021 |
5.0.2 | 3,239,997 | 3/8/2021 |
5.0.1 | 472,550 | 1/5/2021 |
5.0.0 | 32,162 | 12/29/2020 |
5.0.0-preview1 | 9,288 | 11/22/2020 |
3.1.1 | 3,171,529 | 4/17/2020 |
3.1.0 | 369,023 | 4/9/2020 |
3.0.0 | 873,890 | 9/24/2019 |
2.2.1 | 496,064 | 6/6/2019 |
2.2.0 | 380,093 | 11/14/2018 |