WalFlow.Stores.Postgres 0.1.0-alpha.alpha.20260708090623

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

WalFlow.Stores.Postgres

PostgreSQL-based store for WalFlow CDC processor. Persists replication state in a PostgreSQL table with automatic schema and table creation.

Features

  • Automatic Table Creation: Automatically creates schema and table on first use
  • JSONB Storage: Stores state as JSONB for flexibility and queryability
  • Singleton Pattern: Thread-safe initialization with double-check locking
  • Upsert Support: Uses ON CONFLICT for atomic state updates
  • Monitoring Support: Includes indexed updated_at column for monitoring queries

Installation

dotnet add package WalFlow.Stores.Postgres

Configuration

appsettings.json

{
  "PostgresStore": {
    "ConnectionString": "Host=localhost;Database=mydb;Username=user;Password=pass",
    "SchemaName": "public",
    "TableName": "walflow_state",
    "AutoCreateTable": true
  }
}

Options

Property Type Default Description
ConnectionString string required PostgreSQL connection string
SchemaName string "public" Schema name for state table
TableName string "walflow_state" Table name for storing state
AutoCreateTable bool true Automatically create table if it doesn't exist

Usage

Basic Registration

services.Configure<PostgresStoreOptions>(
    configuration.GetSection(PostgresStoreOptions.SectionName));

services.AddSingleton<IReplicationStore, PostgresStore>();

Manual Configuration

services.AddSingleton<IReplicationStore>(sp =>
{
    var options = Options.Create(new PostgresStoreOptions
    {
        ConnectionString = "Host=localhost;Database=cdc;Username=user;Password=pass",
        SchemaName = "cdc",
        TableName = "replication_state"
    });
    
    var logger = sp.GetRequiredService<ILogger<PostgresStore>>();
    return new PostgresStore(options, logger);
});

Table Schema

The state table is automatically created with the following schema:

CREATE TABLE IF NOT EXISTS "public"."walflow_state" (
    slot_name TEXT PRIMARY KEY,
    state_json JSONB NOT NULL,
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_walflow_state_updated_at 
ON "public"."walflow_state" (updated_at DESC);

Monitoring

Query current replication state:

-- View all slots
SELECT 
    slot_name,
    state_json->>'LastProcessedLsn' as lsn,
    state_json->>'MessagesProcessed' as messages,
    updated_at
FROM walflow_state
ORDER BY updated_at DESC;

-- Check if snapshot is completed
SELECT 
    slot_name,
    state_json->>'SnapshotCompleted' as snapshot_done,
    state_json->'CompletedSnapshotTables' as completed_tables
FROM walflow_state;

-- Monitor lag (requires joining with pg_replication_slots)
SELECT 
    ws.slot_name,
    (state_json->>'LastProcessedLsn')::pg_lsn as last_processed,
    prs.confirmed_flush_lsn,
    pg_current_wal_lsn() - (state_json->>'LastProcessedLsn')::pg_lsn as lag_bytes
FROM walflow_state ws
JOIN pg_replication_slots prs ON prs.slot_name = ws.slot_name;

Error Handling

  • Connection Failures: Throws connection exceptions on failure
  • JSON Corruption: Logs error and returns null on deserialization failure
  • Schema/Table Creation Failures: Throws exception if AutoCreateTable=true and creation fails
  • Concurrent Updates: Uses PostgreSQL's ON CONFLICT for safe concurrent updates

Thread Safety

The PostgresStore is thread-safe:

  • Singleton initialization uses SemaphoreSlim with double-check locking
  • Each operation uses its own connection (no shared state)
  • Table creation is guarded by initialization lock

Performance

  • Read Operations: Single SELECT query with primary key lookup
  • Write Operations: Single UPSERT with ON CONFLICT
  • Connection Pooling: Leverages Npgsql's built-in connection pooling
  • No Long-Lived Connections: Each operation opens and closes connections

License

See the LICENSE file in the 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 (1)

Showing the top 1 NuGet packages that depend on WalFlow.Stores.Postgres:

Package Downloads
WalFlow

Meta-package that pulls in the full WalFlow CDC stack for consumers who want the default everything-included setup.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha.alpha... 104 7/8/2026
0.1.0-alpha.alpha... 96 3/30/2026