Verbara.Sdk.Cluster.Postgres 2.2.1

dotnet add package Verbara.Sdk.Cluster.Postgres --version 2.2.1
                    
NuGet\Install-Package Verbara.Sdk.Cluster.Postgres -Version 2.2.1
                    
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="Verbara.Sdk.Cluster.Postgres" Version="2.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Verbara.Sdk.Cluster.Postgres" Version="2.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Verbara.Sdk.Cluster.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 Verbara.Sdk.Cluster.Postgres --version 2.2.1
                    
#r "nuget: Verbara.Sdk.Cluster.Postgres, 2.2.1"
                    
#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 Verbara.Sdk.Cluster.Postgres@2.2.1
                    
#: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=Verbara.Sdk.Cluster.Postgres&version=2.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Verbara.Sdk.Cluster.Postgres&version=2.2.1
                    
Install as a Cake Tool

Verbara.Sdk.Cluster.Postgres

MIT-licensed Postgres-backed implementation of IDistributedLock from Verbara.Sdk.Cluster.Primitives. AOT-safe (raw Npgsql via the Verbara.Sdk.Data.Npgsql facade; no reflection).

What it does

Implements cluster-wide mutual exclusion against a single Postgres table (cluster_distributed_lock) using atomic upserts with TTL. Ships an idempotent migration that creates the table on demand.

Type Role
PostgresDistributedLock (internal) IDistributedLock implementation. Registered via the DI extension below.
ClusterPostgresServiceCollectionExtensions.AddPostgresDistributedLock(...) DI registration entry point.
Migrations.MigrationRunner.EnsureSchemaAsync(...) One-shot idempotent migration runner.

The lock semantics match IDistributedLock: TryAcquire returns true if the caller now holds the lock; re-acquisition by the same owner refreshes the expiry; Release is a no-op when not currently owned by the supplied owner.

Why a separate package

The lock is a generic primitive — both Verbara.Sdk.Pro.Cluster (leader election) and any future SDK consumer can depend on it independently of the Pro commercial license. Placing the implementation in the MIT SDK avoids fragmenting cluster-wide locking by deployment tier.

Install

dotnet add package Verbara.Sdk.Cluster.Postgres

Quick start

using Microsoft.Extensions.DependencyInjection;
using Npgsql;
using Verbara.Sdk.Cluster.Postgres.DependencyInjection;
using Verbara.Sdk.Cluster.Postgres.Migrations;

services.AddKeyedSingleton<NpgsqlDataSource>("Cluster", (_, _) =>
    NpgsqlDataSource.Create(configuration.GetConnectionString("Cluster")!));

services.AddPostgresDistributedLock(connectionStringName: "Cluster");

// At startup, once:
await MigrationRunner.EnsureSchemaAsync(dataSource, logger, ct);

Schema

CREATE TABLE IF NOT EXISTS cluster_distributed_lock (
    resource TEXT PRIMARY KEY,
    owner    TEXT NOT NULL,
    expires_at TIMESTAMPTZ NOT NULL
);

AOT

Trimming/AOT-safe. No reflection, no dynamic code generation. The migration runner reads its embedded V001__DistributedLockSchema.sql resource via typeof(MigrationRunner).Assembly.GetManifestResourceStream(...) — the constant-name lookup is AOT-friendly.

License

MIT. See repository root.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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
2.2.1 109 5/23/2026