Rask.Postgres 0.24.1-alpha.0.586

This is a prerelease version of Rask.Postgres.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Rask.Postgres --version 0.24.1-alpha.0.586
                    
NuGet\Install-Package Rask.Postgres -Version 0.24.1-alpha.0.586
                    
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="Rask.Postgres" Version="0.24.1-alpha.0.586" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rask.Postgres" Version="0.24.1-alpha.0.586" />
                    
Directory.Packages.props
<PackageReference Include="Rask.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rask.Postgres --version 0.24.1-alpha.0.586
                    
#r "nuget: Rask.Postgres, 0.24.1-alpha.0.586"
                    
#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.
#:package Rask.Postgres@0.24.1-alpha.0.586
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rask.Postgres&version=0.24.1-alpha.0.586&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rask.Postgres&version=0.24.1-alpha.0.586&prerelease
                    
Install as a Cake Tool

Rask.Postgres

PostgreSQL for .NET apps on Entity Framework Core. UseRaskPostgres(...) is a drop-in replacement for UseNpgsql that gives every session the production timeouts — statement_timeout, lock_timeout, idle_in_transaction_session_timeout — and turns on Npgsql's transient-failure retrying.

SQLite remains Rask's default, and for most single-developer products it is the right answer for a long time. This package is the door out of one box: a managed database, a read replica, or more app instances than one file can serve.

Install

dotnet add package Rask.Postgres

A release candidate while Npgsql's EF Core 11 provider is one (11.0.0-rc.3): that provider pins EF Core to exactly its own rc build and Rask is on EF Core 11.0.0, so the app restores with NU1608 — add <NoWarn>$(NoWarn);NU1608</NoWarn> under warnings-as-errors. With Rask:Database:Provider set to postgres, Rask.Server finds this package by name; it becomes stable, and part of Rask.Server again, with Npgsql's stable provider.

Use

builder.Services.AddDbContextFactory<AppDbContext>((sp, o) => o
    .UseRaskPostgres(sp)
    .AddInterceptors(sp.GetServices<ISaveChangesInterceptor>()));

The connection string is Rask:ConnectionStrings:App in configuration — in production usually the whole string, password included, as Rask__ConnectionStrings__App in the environment — and a missing one is an error naming that key.

Override any default in the Rask:Postgres section:

{ "Rask": { "Postgres": { "StatementTimeout": "00:00:10", "LockTimeout": "00:00:03", "Retry": { "MaxCount": 3 } } } }

or through the optional configure delegate, which runs after the section and wins:

o.UseRaskPostgres(sp, p =>
{
    p.StatementTimeout = 10.Seconds;
    p.LockTimeout = 3.Seconds;
    p.Retry.MaxCount = 3;
});

HasFullTextSearch, Search(text), FullText.Highlight and FullText.Snippet from Rask.Data work here as they do on SQLite:

builder.HasFullTextSearch(p => new { p.Title, p.Body });                 // in the entity's configuration

var hits = await db.Posts.Search("postgres sqli")                         // every word, the last as a prefix
    .Select(p => new { p.Id, Title = FullText.Highlight(p.Title) })       // matches between U+E000 and U+E001
    .ToListAsync();                                                       // best match first

The index is a stored generated tsvector column with a GIN index, created by your migration and kept current by PostgreSQL itself. FullTextTokenizer.Unicode folds accents (keres finds kérés) through a rask_unicode text search configuration built on unaccent, which the first migration that needs it creates.

What the defaults do

Setting Default Why
StatementTimeout 30s A runaway query otherwise runs until the client disconnects.
LockTimeout 10s The analogue of SQLite's busy_timeout. Without it, a statement stuck behind a lock reports as a slow query, which sends you debugging the wrong thing. Must be below StatementTimeout.
IdleInTransactionSessionTimeout 1m An idle-in-transaction session keeps its locks and blocks VACUUM from reclaiming dead rows — the usual way a healthy database quietly bloats.
Retry.Enabled / MaxCount / MaxDelay on / 6 / 30s Npgsql's own EnableRetryOnFailure, which already knows which PostgreSQL error codes are transient.

Set a timeout to TimeSpan.Zero to leave it to the server, so a server-level or role-level setting wins instead of being overwritten.

The timeouts travel as startup parameters in the connection string (Options=-c statement_timeout=…), so they are the session's defaults: they survive the pool resetting a returned connection, cost no round trip per query, and reach code that opens the DbConnection itself. A -c your connection string already carries wins. Behind PgBouncer in transaction mode, add options to its ignore_startup_parameters, or set the timeouts to TimeSpan.Zero and configure them on the database role.

Retrying is an execution strategy, and like every EF Core retrying strategy it refuses a transaction you opened yourself outside it: wrap a hand-written BeginTransaction in context.Database.CreateExecutionStrategy().ExecuteAsync(...), or set Rask:Postgres:Retry:Enabled to false. SaveChanges, and Rask's jobs, mail, outbox and cache, need nothing.

Moments

A Moment value object holds a wall-clock time (Kind = Unspecified), which Npgsql refuses to write to a timestamptz column. UseRaskPostgres stores each one as the UTC instant it is in Clock.Zone and reads it back onto the wall clock, so the same moment is saved, compared and ordered as on SQL Server and SQLite — to the microsecond, which is what PostgreSQL keeps.

What stays behind

Litestream continuous backup and file snapshots (Rask.SQLite.Litestream, Rask.SQLite.Snapshots) are SQLite-only by definition — they replicate and copy a file. On PostgreSQL, backup is your provider's snapshots or pg_dump. Migrations are unchanged: dotnet ef (and rask db) are provider-agnostic.

Full documentation: https://github.com/pal-tamas/rask/blob/main/docs/data.md#postgresql

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.24.1-alpha.0.775 0 11/27/2026
0.24.1-alpha.0.774 0 11/27/2026
0.24.1-alpha.0.770 0 11/27/2026
0.24.1-alpha.0.769 0 11/26/2026
0.24.1-alpha.0.767 0 11/26/2026
0.24.1-alpha.0.766 0 11/26/2026
0.24.1-alpha.0.760 0 11/26/2026
0.24.1-alpha.0.759 0 11/26/2026
0.24.1-alpha.0.757 0 11/26/2026
0.24.1-alpha.0.754 9 11/26/2026
0.24.1-alpha.0.753 27 11/26/2026
0.24.1-alpha.0.752 36 11/26/2026
0.24.1-alpha.0.748 32 11/26/2026
0.24.1-alpha.0.738 41 11/25/2026
0.24.1-alpha.0.659 39 11/25/2026
0.24.1-alpha.0.606 37 11/25/2026
0.24.1-alpha.0.604 42 11/25/2026
0.24.1-alpha.0.586 42 11/25/2026
0.24.1-alpha.0.521 38 11/24/2026
0.23.0 179 9/18/2026
Loading failed