AspNetCore.HealthChecks.NpgSql 8.0.0

dotnet add package AspNetCore.HealthChecks.NpgSql --version 8.0.0
NuGet\Install-Package AspNetCore.HealthChecks.NpgSql -Version 8.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.HealthChecks.NpgSql --version 8.0.0
#r "nuget: AspNetCore.HealthChecks.NpgSql, 8.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AspNetCore.HealthChecks.NpgSql as a Cake Addin
#addin nuget:?package=AspNetCore.HealthChecks.NpgSql&version=8.0.0

// Install AspNetCore.HealthChecks.NpgSql as a Cake Tool
#tool nuget:?package=AspNetCore.HealthChecks.NpgSql&version=8.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.

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 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (40)

Showing the top 5 NuGet packages that depend on AspNetCore.HealthChecks.NpgSql:

Package Downloads
Reo.Core.Database

Package Description

Skoruba.IdentityServer4.Admin.UI The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

The package with UI for the administration of the IdentityServer4

Skoruba.Duende.IdentityServer.Admin.UI The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

The package with UI for the administration of the Duende IdentityServer

Newguys.Sport

Package Description

EaCloud.AspNetCore.Diagnostics

EaCloud AspNetCore 性能诊断组件,提供 AspNetCore 性能诊断功能的封装。

GitHub repositories (12)

Showing the top 5 popular GitHub repositories that depend on AspNetCore.HealthChecks.NpgSql:

Repository Stars
skoruba/IdentityServer4.Admin
The administration for the IdentityServer4 and Asp.Net Core Identity
dotnet/aspire
An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
dotnetcore/osharp
OSharp是一个基于.Net6.0的快速开发框架,框架对 AspNetCore 的配置、依赖注入、日志、缓存、实体框架、Mvc(WebApi)、身份认证、功能权限、数据权限等模块进行更高一级的自动化封装,并规范了一套业务实现的代码结构与操作流程,使 .Net 框架更易于应用到实际项目开发中。
aspnetrun/run-aspnetcore-microservices
Microservices on .Net platforms which 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
desenvolvedor-io/dev-store
A microservices e-commerce reference application built with ASP.NET 6
Version Downloads Last updated
8.0.0 410,582 12/15/2023
7.1.0 732,177 10/3/2023
7.0.0 565,566 7/30/2023
7.0.0-rc2.7 58,659 3/13/2023
7.0.0-rc2.6 34,866 1/14/2023
7.0.0-rc2.5 22,989 12/27/2022
7.0.0-rc2.4 382 12/27/2022
6.0.2 7,541,021 2/28/2022
6.0.1 816,865 12/29/2021
6.0.1-rc2.3 33,510 11/10/2021
6.0.1-rc1.2 2,297 11/5/2021
6.0.0 60,601 12/29/2021
5.0.2 2,881,117 3/8/2021
5.0.1 460,384 1/5/2021
5.0.0 29,500 12/29/2020
5.0.0-preview1 9,203 11/22/2020
3.1.1 2,904,373 4/17/2020
3.1.0 367,023 4/9/2020
3.0.0 839,976 9/24/2019
2.2.1 470,598 6/6/2019
2.2.0 362,510 11/14/2018