Akka.Persistence.Sql.Hosting
1.5.73
Prefix Reserved
See the version list below for details.
dotnet add package Akka.Persistence.Sql.Hosting --version 1.5.73
NuGet\Install-Package Akka.Persistence.Sql.Hosting -Version 1.5.73
<PackageReference Include="Akka.Persistence.Sql.Hosting" Version="1.5.73" />
<PackageVersion Include="Akka.Persistence.Sql.Hosting" Version="1.5.73" />
<PackageReference Include="Akka.Persistence.Sql.Hosting" />
paket add Akka.Persistence.Sql.Hosting --version 1.5.73
#r "nuget: Akka.Persistence.Sql.Hosting, 1.5.73"
#:package Akka.Persistence.Sql.Hosting@1.5.73
#addin nuget:?package=Akka.Persistence.Sql.Hosting&version=1.5.73
#tool nuget:?package=Akka.Persistence.Sql.Hosting&version=1.5.73
Akka.Persistence.Sql
A Cross-SQL-DB Engine Akka.Persistence plugin with broad database compatibility thanks to Linq2Db.
This is a port of the amazing akka-persistence-jdbc package from Scala, with a few improvements based on C# as well as our choice of data library.
Please read the documentation carefully. Some features may have specific use case and have trade-offs (namely, compatibility modes).
If you're migrating from legacy Akka.Persistence.Sql.Common based plugins, you can read the migration guide documentation, the migration tutorial, and watch the migration tutorial video.
Table Of Content
- Akka.Persistence.Sql
- Getting Started
- Sql.Common Compatibility modes
- Migration Guide
- Migration Tutorial
- Features/Architecture
- Performance Benchmarks
- Configuration
- DDL Scripts for Database Schema Management
- Database-Side Journal Retention
- Tag-Table Insert Batching
- Tuning Akka.Persistence.Query for Low-Latency Projections
- Building this solution
Getting Started
The Easy Way, Using Akka.Hosting
Assuming a MS SQL Server 2019 setup:
var host = new HostBuilder()
.ConfigureServices((context, services) => {
services.AddAkka("my-system-name", (builder, provider) =>
{
builder.WithSqlPersistence(
connectionString: _myConnectionString,
providerName: ProviderName.SqlServer2019);
});
});
You can also provide your own LinqToDb.DataOptions object for a more advanced configuration.
Assuming a setup with a custom NpgsqlDataSource:
NpgsqlDataSource dataSource = new NpgsqlDataSourceBuilder(_myConnectionString).Build();
DataOptions dataOptions = new DataOptions()
.UseDataProvider(DataConnection.GetDataProvider(ProviderName.PostgreSQL, dataSource.ConnectionString) ?? throw new Exception("Could not get data provider"))
.UseProvider(ProviderName.PostgreSQL)
.UseConnectionFactory((opt) => dataSource.CreateConnection());
var host = new HostBuilder()
.ConfigureServices((context, services) => {
services.AddAkka("my-system-name", (builder, provider) =>
{
builder.WithSqlPersistence(dataOptions);
});
});
If dataOptions are provided, you must supply enough information for linq2db to connect to the database.
This includes setting the connection string and provider name again, if necessary for your use case.
Please consult the Linq2Db documentation for more details on configuring a valid DataOptions object.
Note that MappingSchema and RetryPolicy will always be overridden by Akka.Persistence.Sql.
Health Checks
Starting with Akka.Persistence.Sql v1.5.51 or later, you can add health checks for your persistence plugins. Akka.Persistence.Sql supports two types of health checks that integrate with Microsoft.Extensions.Diagnostics.HealthChecks and can be used with ASP.NET Core health check endpoints.
Standard Health Checks
Standard health checks monitor the persistence plugins themselves and verify that journals and snapshot stores are properly initialized and accessible.
To configure standard health checks, use the journalBuilder and snapshotBuilder parameters with the .WithHealthCheck() method:
var host = new HostBuilder()
.ConfigureServices((context, services) => {
services.AddAkka("my-system-name", (builder, provider) =>
{
builder.WithSqlPersistence(
connectionString: _myConnectionString,
providerName: ProviderName.SqlServer2019,
journalBuilder: journal => journal.WithHealthCheck(HealthStatus.Degraded),
snapshotBuilder: snapshot => snapshot.WithHealthCheck(HealthStatus.Degraded));
});
});
Standard health checks are tagged with akka, persistence, and either journal or snapshot-store for filtering and organization purposes.
Connectivity Health Checks (Akka.Persistence.Sql.Hosting v1.5.X+)
Connectivity health checks proactively verify database connectivity regardless of recent operation activity. This helps detect database outages during idle periods when the standard health checks might not catch issues.
Using Akka.Hosting 1.5.55.1 or later (Simplified API):
services.AddAkka("my-system-name", (builder, provider) =>
{
builder.WithSqlPersistence(
connectionString: connectionString,
providerName: ProviderName.SqlServer2022,
journalBuilder: journal =>
{
journal.WithHealthCheck(); // Monitor plugin status
journal.WithConnectivityCheck(); // Verify database connectivity
},
snapshotBuilder: snapshot =>
{
snapshot.WithHealthCheck(); // Monitor plugin status
snapshot.WithConnectivityCheck(); // Verify database connectivity
});
});
The connectivity checks will automatically:
- Verify connectivity to the underlying SQL database
- Test database responsiveness with a lightweight "SELECT 1" query
- Report
Healthywhen the database is accessible - Report
Unhealthy(configurable) when the database is unreachable or unresponsive
Connectivity checks are tagged with akka, persistence, sql, and either journal or snapshot-store for filtering and organization purposes.
Exposing Health Checks via ASP.NET Core
For ASP.NET Core applications, you can expose these health checks via an endpoint:
var builder = WebApplication.CreateBuilder(args);
// Add health checks service
builder.Services.AddHealthChecks();
builder.Services.AddAkka("my-system-name", (configBuilder, provider) =>
{
configBuilder.WithSqlPersistence(
connectionString: _myConnectionString,
providerName: ProviderName.SqlServer2019,
journalBuilder: journal => journal.WithHealthCheck(),
snapshotBuilder: snapshot => snapshot.WithHealthCheck());
});
var app = builder.Build();
// Map health check endpoint
app.MapHealthChecks("/healthz");
app.Run();
Customizing Health Check Configuration
You can customize the names, tags, and unhealthy status for both standard and connectivity health checks:
services.AddAkka("my-system-name", (builder, provider) =>
{
builder.WithSqlPersistence(
connectionString: connectionString,
providerName: ProviderName.SqlServer2022,
journalBuilder: journal =>
{
// Customize standard health check
journal.WithHealthCheck(
unHealthyStatus: HealthStatus.Degraded,
name: "sql-journal",
tags: new[] { "backend", "database", "sql" });
// Customize connectivity health check
journal.WithConnectivityCheck(
unHealthyStatus: HealthStatus.Unhealthy,
name: "sql-journal-connectivity",
tags: new[] { "backend", "database", "sql", "connectivity" });
},
snapshotBuilder: snapshot =>
{
// Customize standard health check
snapshot.WithHealthCheck(
unHealthyStatus: HealthStatus.Degraded,
name: "sql-snapshot",
tags: new[] { "backend", "database", "sql" });
// Customize connectivity health check
snapshot.WithConnectivityCheck(
unHealthyStatus: HealthStatus.Unhealthy,
name: "sql-snapshot-connectivity",
tags: new[] { "backend", "database", "sql", "connectivity" });
});
});
Default tags when not specified:
- Standard health checks:
["akka", "persistence", "journal"]or["akka", "persistence", "snapshot-store"] - Connectivity health checks:
["akka", "persistence", "sql", "journal", "connectivity"]or["akka", "persistence", "sql", "snapshot-store", "connectivity"]
The Classic Way, Using HOCON
These are the minimum HOCON configuration you need to start using Akka.Persistence.Sql:
akka.persistence {
journal {
plugin = "akka.persistence.journal.sql"
sql {
class = "Akka.Persistence.Sql.Journal.SqlWriteJournal, Akka.Persistence.Sql"
connection-string = "{database-connection-string}"
provider-name = "{provider-name}"
}
}
query.journal.sql {
class = "Akka.Persistence.Sql.Query.SqlReadJournalProvider, Akka.Persistence.Sql"
connection-string = "{database-connection-string}"
provider-name = "{provider-name}"
}
snapshot-store {
plugin = "akka.persistence.snapshot-store.sql"
sql {
class = "Akka.Persistence.Sql.Snapshot.SqlSnapshotStore, Akka.Persistence.Sql"
connection-string = "{database-connection-string}"
provider-name = "{provider-name}"
}
}
}
- database-connection-string: The proper connection string to your database of choice.
- provider-name: A string constant defining the database type to connect to, valid values are defined inside
LinqToDB.ProviderNamestatic class. Refer to the Members ofLinqToDb.ProviderNamefor included providers.
Note: For best performance, one should use the most specific provider name possible. i.e. LinqToDB.ProviderName.SqlServer2012 instead of LinqToDB.ProviderName.SqlServer. Otherwise certain provider detections have to run more frequently which may impair performance slightly.
Supported Database Providers
Tested Database Providers
- Microsoft SQL Server
- MS SQLite
- System.Data.SQLite
- PostgreSQL using binary payload
- MySql
Supported By Linq2Db But Untested In Akka.Persistence
- Firebird
- Microsoft Access OleDB
- Microsoft Access ODBC
- IBM DB2
- Informix
- Oracle
- Sybase
- SAP HANA
- ClickHouse
Sql.Common Compatibility modes
- Delete Compatibility mode is available.
- This mode will utilize a
journal_metadatatable containing the last sequence number - The main table delete is done the same way regardless of delete compatibility mode
- This mode will utilize a
Delete Compatibility mode is expensive.
- Normal Deletes involve first marking the deleted records as deleted, and then deleting them
- Table compatibility mode adds an additional InsertOrUpdate and Delete
- This all happens in a transaction
- In SQL Server this can cause issues because of page locks/etc.
DDL Scripts for Database Schema Management
Pre-generated DDL scripts are available in docs/ddl/ for creating Akka.Persistence.Sql tables through your own migrations instead of relying on automatic table creation at runtime.
Directory Structure:
docs/ddl/default/- For new deployments usingtable-mapping = defaultdocs/ddl/compat/- For migration from legacy plugins (uses provider-specific table mappings)
The initialization SQL files are checked into this repository:
| Provider | Default mapping | Compatibility mapping |
|---|---|---|
| PostgreSQL | Scripts | Scripts |
| SQL Server | Scripts | Scripts |
| MySQL | Scripts | Scripts |
| SQLite | Scripts | Scripts |
Each directory contains SQL scripts for each supported provider (sqlserver, postgresql, mysql, sqlite):
journal.sql- Event journal tablejournal-tags.sql- Tag table forTagMode.TagTablesnapshot.sql- Snapshot store tablemetadata.sql- Metadata table fordelete-compatibility-mode
When to use DDL scripts:
- When using Entity Framework Core or FluentMigrator for schema management
- When you need explicit control over database schema versioning
- When auto-initialization is disabled (
auto-initialize = false)
See the DDL documentation for detailed usage instructions and examples.
Database-Side Journal Retention
Akka.Persistence's DeleteMessagesTo deletes an entity's events and their tag
rows together. If you purge old events with your own SQL instead, delete their
tag rows too, or the tags table grows forever.
See the journal retention guide for the rules and example scripts for PostgreSQL, SQL Server, MySQL, and SQLite.
Optional Tag-Table Foreign Keys
The journal-to-tag foreign key (tags.ordering_id -> journal.ordering ON DELETE CASCADE) is an optional, operator-applied migration for PostgreSQL and SQL
Server. Runtime auto-initialization and the base DDL scripts create tables
without it. With the FK installed, deleting a journal row also removes its tag
rows. Existing databases must clean up orphaned tags with 01 before installing
it.
The FK adds overhead to tagged writes and especially to deletes. Review the measured FK overhead and the maintenance guide before opting in.
Tag-Table Insert Batching
SQL Server, PostgreSQL, and SQLite can batch journal inserts using
INSERT ... OUTPUT/RETURNING when tag-write-mode = TagTable. Parent batching
is off by default. To enable parameterized parent inserts and parameterized tag
SQL:
akka.persistence.journal.sql {
tag-write-mode = TagTable
tagtable-asqueryable-insert-mode = parameterized
prefer-parameters-on-multirow-insert = true
}
The parent mode accepts off, parameterized, or inline. Inline mode embeds
scalar values in SQL while keeping persistence IDs, messages, manifests, and
writer UUIDs parameterized. Other providers and tag modes retain the standard
insert path. Batching does not install an FK or change transaction boundaries.
This backport upgrades LinqToDB to 6.5.1 for all users, including those with batching off. The plugin retains its .NET Standard 2.0/.NET 6 targets and Akka 1.5 dependencies, but advanced LinqToDB integrations need an upgrade review:
- Custom LinqToDB 5
IDataProviderimplementations must be adapted as needed and recompiled against LinqToDB 6; this is not a transparent binary upgrade for those extensions. - Register interceptors through
DataOptions.UseInterceptor/UseInterceptors. The replacement connection clone preserves those registrations, but does not snapshotAddInterceptor/RemoveInterceptormutations made directly on aDataConnectionafter construction.
Tuning Akka.Persistence.Query for Low-Latency Projections
Default polling intervals cause 500-1200ms projection latency. For low-latency CQRS, tune BOTH settings together:
akka.persistence.query.journal.sql {
refresh-interval = 10ms # Query stream polling
max-buffer-size = 50
journal-sequence-retrieval {
query-delay = 10ms # Sequence actor polling - CRITICAL!
}
}
Important: Tuning only refresh-interval does NOT work. The sequence actor polls independently via query-delay.
Performance Guide
| Configuration | Latency | Database Load |
|---|---|---|
| Default (1s/1s) | 500-1200ms | Low |
| Balanced (50ms/50ms) | 50-200ms | Medium |
| Low latency (10ms/10ms) | 20-100ms | High |
Trade-off: Lower = faster but higher DB load. In clusters, each node polls independently.
See persistence.conf for detailed settings documentation.
Building this solution
To run the build script associated with this solution, execute the following:
Windows
c:\> build.cmd all
Linux / OS X
c:\> build.sh all
If you need any information on the supported commands, please execute the build.[cmd|sh] help command.
This build script is powered by FAKE; please see their API documentation should you need to make any changes to the build.fsx file.
Conventions
The attached build script will automatically do the following based on the conventions of the project names added to this project:
- Any project name ending with
.Testswill automatically be treated as a XUnit2 project and will be included during the test stages of this build script; - Any project name ending with
.Testswill automatically be treated as a NBench project and will be included during the test stages of this build script; and - Any project meeting neither of these conventions will be treated as a NuGet packaging target and its
.nupkgfile will automatically be placed in thebin\nugetfolder upon running thebuild.[cmd|sh] allcommand.
Release Notes, Version Numbers, Etc
This project will automatically populate its release notes in all of its modules via the entries written inside RELEASE_NOTES.md and will automatically update the versions of all assemblies and NuGet packages via the metadata included inside Directory.Build.props.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 was computed. 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .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. |
-
.NETStandard 2.0
- Akka.Persistence.Hosting (>= 1.5.73)
- Akka.Persistence.Sql (>= 1.5.73)
-
net6.0
- Akka.Persistence.Hosting (>= 1.5.73)
- Akka.Persistence.Sql (>= 1.5.73)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on Akka.Persistence.Sql.Hosting:
| Repository | Stars |
|---|---|
|
petabridge/akkadotnet-code-samples
Akka.NET professional reference code samples
|
|
|
petabridge/memorizer
Vector-search powered agent memory MCP server
|
|
|
netclaw-dev/netclaw
Simple, secure, reliable agents. Self-hosted. Open source. Built with .NET.
|
|
|
petabridge/DrawTogether.NET
Multi-player MS Paint application. Built with Akka.NET, Blazor, and .NET Aspire.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.6.0-beta5 | 610 | 11/5/2026 |
| 1.6.0-beta4 | 79 | 11/2/2026 |
| 1.6.0-beta3 | 1,601 | 10/7/2026 |
| 1.6.0-beta2 | 113 | 10/6/2026 |
| 1.5.73 | 1,465 | 11/2/2026 |
| 1.5.70 | 88,124 | 7/23/2026 |
| 1.5.70-beta1 | 138 | 6/24/2026 |
| 1.5.67 | 40,642 | 4/28/2026 |
| 1.5.62 | 14,086 | 3/27/2026 |
| 1.5.60.1 | 18,324 | 2/16/2026 |
| 1.5.59 | 14,328 | 1/27/2026 |
| 1.5.55.1 | 25,173 | 10/29/2025 |
| 1.5.55 | 2,022 | 10/27/2025 |
| 1.5.53 | 28,230 | 10/14/2025 |
| 1.5.51.1 | 35,211 | 10/2/2025 |
| 1.5.51 | 1,202 | 10/1/2025 |
| 1.5.44 | 22,214 | 6/23/2025 |
| 1.5.42 | 6,140 | 5/22/2025 |
| 1.5.40.1 | 4,463 | 4/7/2025 |
| 1.5.40 | 11,153 | 3/26/2025 |
**Akka.NET 1.5.73 and Microsoft.Extensions 9.0**
* [Bump Akka.NET to 1.5.73](https://github.com/akkadotnet/akka.net/releases/tag/1.5.73)
* [Bump Akka.Hosting to 1.5.73](https://github.com/akkadotnet/Akka.Hosting/releases/tag/1.5.73) - Akka.Hosting 1.5.73 requires Microsoft.Extensions 9.0 or later (previously 8.0), which applies to `Akka.Persistence.Sql.Hosting` consumers.
**LinqToDB 6 and opt-in tag-table insert batching**
* [Upgrade LinqToDB to 6.5.1 and add opt-in batched journal inserts](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/616) - Backport of [#580](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/580). Upgrades LinqToDB from 5.4 to 6.5.1 and adds optional batched journal inserts for SQL Server, PostgreSQL, and SQLite in `TagTable` mode. Batching remains off by default; FK installation remains a separate operator-applied migration.
* Retain Akka 1.5 and the existing .NET Standard 2.0/.NET 6 library targets. Preserve legacy `MySql.Official` provider selection and select batching from the actual provider supplied through `DataOptions`.
* Preserve independent cloned connections, external-transaction separation, configured retry/provider instances, mapping, command timeout, and query hints.
* **Compatibility:** the LinqToDB upgrade applies to all users, even with batching off. Custom LinqToDB 5 `IDataProvider` implementations must be adapted and recompiled. Configure interceptors through `DataOptions.UseInterceptor(s)`; direct post-construction interceptor additions/removals are not carried over to cloned connections. See the [batching and upgrade notes](https://github.com/akkadotnet/Akka.Persistence.Sql/blob/v1.5/README.md#tag-table-insert-batching).
* [Skip the tag-table fast insert for untagged batches and single tagged rows](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/620) - When batched inserts are enabled, untagged batches use `BulkCopy` and single tagged rows use the regular row insert; batches containing tagged events keep the fast path.
**Bug Fixes**
* [Cancel SQL queries when journal streams stop](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/621) - Cancel in-flight database queries when a read-journal or journal-replay stream stops, including `Offset.FromEnd` and current-query boundary lookups. Preserve the configured scheduler for refresh delays.
* [Complete the journal write queue on actor shutdown](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/608) - Stopping the journal actor now explicitly completes its write queue and cancels pending write-receipt waits instead of leaving buffered writes awaiting promises that never complete.
* [Rate-limit SQL initialization retries](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/602) - Failed journal and snapshot store initialization now waits asynchronously before restarting, controlled by the new `initialization-retry-delay` setting (default `1s`). An unreachable database no longer causes a tight initialization/restart loop.
* [Fix SQL materializer lifetime](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/600) - Journal, snapshot store, and sequence actor materializers are now owned by their actors, so stream supervisors and journal queues no longer accumulate across actor restarts (for example, during repeated initialization failures).
**Operations and Documentation**
* [Add operator-run tag cleanup and opt-in FK migrations](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/611) - PostgreSQL and SQL Server scripts for auditing and cleaning up orphaned tag rows, and for installing or rolling back an optional `ON DELETE CASCADE` foreign key from the tag table to the journal. Schema auto-initialization is unchanged; FK adoption remains optional. Includes [reproducible FK insert/delete benchmarks](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/610).
* [Document database-side journal retention](https://github.com/akkadotnet/Akka.Persistence.Sql/pull/619) - Guidance and example SQL for PostgreSQL, SQL Server, MySQL, and SQLite to purge old journal events with your own SQL without leaving orphaned tag rows behind.