InitializeNL.PgPartitionSmith.Auto.Hosting 1.0.0

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

InitializeNL.PgPartitionSmith

A PostgreSQL table partitioning toolkit for .NET 10+. Automatically creates and manages partitions at runtime.

Features

  • On-demand partition creation with concurrency-safe locking
  • Range partitioning (daily, weekly, monthly, quarterly, yearly)
  • List partitioning with static or dynamic auto-created partitions
  • Nested sub-partitioning (e.g., list by status, then range by date)
  • Optional default/remainder partitions
  • CLI tool for migrating existing tables to partitioned tables
  • In-memory partition cache for fast lookups
  • ASP.NET hosted service integration via Microsoft.Extensions.Hosting
  • Advisory lock or table-based distributed locking
  • Hashed partition names with COMMENT ON TABLE metadata

Packages

Package Description
InitializeNL.PgPartitionSmith.Core Core library: models, DDL generation, catalog queries, naming, and locking
InitializeNL.PgPartitionSmith.Auto Runtime auto-partitioning for on-demand partition creation
InitializeNL.PgPartitionSmith.Auto.Hosting Microsoft.Extensions.Hosting integration with dependency injection
InitializeNL.PgPartitionSmith.Cli CLI tool for migrating unpartitioned tables

Quick Start

As a library

IPartitionManager manager = new PartitionManagerBuilder()
    .UseConnectionString("Host=localhost;Database=mydb")
    .UseAdvisoryLocks()
    .ForTable("events", t => t
        .RangeBy("created_at")
        .Monthly()
        .WithSchema("public"))
    .Build();

await manager.InitializeAsync();

await manager.EnsurePartitionAsync("events", new Dictionary<string, object>
{
    ["created_at"] = DateTime.UtcNow
});

With ASP.NET hosting

services.AddPgPartitionSmith(builder => builder
    .UseConnectionString(connectionString)
    .UseAdvisoryLocks()
    .ForTable("events", t => t
        .RangeBy("created_at")
        .Monthly()));

With entity mapping

var manager = new PartitionManagerBuilder()
    .UseConnectionString(connectionString)
    .ForTable("events", t => t
        .RangeBy("created_at")
        .Monthly()
        .MappedFrom<Event>(e => e.CreatedAt))
    .Build();

await manager.EnsurePartitionAsync(myEvent);

List partitioning with sub-partitions

var manager = new PartitionManagerBuilder()
    .UseConnectionString(connectionString)
    .ForTable("situations", t => t
        .ListBy("status")
        .WithPartition("active", ["active"], child => child
            .RangeBy("period_start").Monthly())
        .WithPartition("finished", ["finished"], child => child
            .RangeBy("period_start").Monthly()))
    .Build();

Pre-creating partitions

await manager.PreCreatePartitionsAsync("events",
    DateTime.UtcNow,
    DateTime.UtcNow.AddMonths(6));

As a CLI

dotnet run --project InitializeNL.PgPartitionSmith.Cli -- \
    --connection-string "Host=localhost;Database=mydb;Username=postgres;Password=secret" \
    --table-name events \
    --query "SELECT json_build_object('partition', json_build_object('type', 'range', ...))::text" \
    --execute

CLI Options

Option Description
--connection-string PostgreSQL connection string
--table-name Name of the table to partition
--query SQL query that returns a JSON partition schema
--schema PostgreSQL schema name (default: public)
--dry-run Print SQL statements without executing them
--partitioned-name Name suffix for the partitioned table (default: part)
--unpartitioned-name Name suffix for the unpartitioned table (default: unpart)
--hashed-names Use short hashed names with COMMENT ON TABLE for context

Configuration Options

Method Description
UseConnectionString(string) PostgreSQL connection string
UseAdvisoryLocks() Use pg_advisory_lock for concurrency (default)
UseTableLock(name, schema) Use table-based locking
UseHashedNames() Use SHA256-hashed partition names
ForTable(name, config) Configure partitioning for a table
RangeBy(column) Range partition by column
ListBy(column) List partition by column
Daily() / Weekly() / Monthly() / Quarterly() / Yearly() Range interval
WithPartition(name, values, child?) Named list partition with optional sub-partition
AutoCreateForNewValues() Auto-create list partitions for unknown values
WithRemainderPartition() Add a DEFAULT catch-all partition
SubPartition(config) Nested sub-partitioning
PreCreate(TimeSpan) Pre-create partitions ahead of time on startup
CreateIfNotExists(columns) Auto-create the partitioned table if it doesn't exist
MappedFrom<T>(expression) Map entity property for EnsurePartitionAsync<T>()
WithSchema(string) PostgreSQL schema (default: public)

License

MIT

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
1.0.0 64 3/23/2026