AspNetCore.HealthChecks.NpgSql 8.0.2

dotnet add package AspNetCore.HealthChecks.NpgSql --version 8.0.2                
NuGet\Install-Package AspNetCore.HealthChecks.NpgSql -Version 8.0.2                
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.2" />                
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.2                
#r "nuget: AspNetCore.HealthChecks.NpgSql, 8.0.2"                
#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.2

// Install AspNetCore.HealthChecks.NpgSql as a Cake Tool
#tool nuget:?package=AspNetCore.HealthChecks.NpgSql&version=8.0.2                

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 (57)

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 (18)

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
dotnetcore/osharp
OSharp是一个基于.Net6.0的快速开发框架,框架对 AspNetCore 的配置、依赖注入、日志、缓存、实体框架、Mvc(WebApi)、身份认证、功能权限、数据权限等模块进行更高一级的自动化封装,并规范了一套业务实现的代码结构与操作流程,使 .Net 框架更易于应用到实际项目开发中。
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
Version Downloads Last updated
8.0.2 869,270 8/29/2024
8.0.1 2,477,467 4/2/2024
8.0.0 1,361,077 12/15/2023
7.1.0 1,225,841 10/3/2023
7.0.0 854,615 7/30/2023
7.0.0-rc2.7 65,064 3/13/2023
7.0.0-rc2.6 38,754 1/14/2023
7.0.0-rc2.5 23,868 12/27/2022
7.0.0-rc2.4 432 12/27/2022
6.0.2 9,840,693 2/28/2022
6.0.1 935,914 12/29/2021
6.0.1-rc2.3 35,569 11/10/2021
6.0.1-rc1.2 2,338 11/5/2021
6.0.0 92,094 12/29/2021
5.0.2 3,201,881 3/8/2021
5.0.1 471,223 1/5/2021
5.0.0 31,981 12/29/2020
5.0.0-preview1 9,281 11/22/2020
3.1.1 3,144,661 4/17/2020
3.1.0 368,728 4/9/2020
3.0.0 868,857 9/24/2019
2.2.1 492,195 6/6/2019
2.2.0 378,011 11/14/2018