Skip to content

Databases Supported by Duende Storage

Duende Storage supports SQL Server, PostgreSQL, Oracle and SQLite. This page compares them, explains how provider registration and schema deployment work the same way across all of them, and links to each provider’s page for connection strings, custom schemas and provider-specific notes.

Database Package Registration method Connection object you register Schema option CLI --provider value Intended use
SQL Server Duende.Storage.MsSql AddMsSql CreateSqlConnection factory SchemaName mssql Production
PostgreSQL Duende.Storage.PostgreSql AddPostgreSql NpgsqlDataSource SchemaName postgresql Production
Oracle Duende.Storage.Oracle AddOracle CreateOracleConnection factory SchemaName oracle Production
SQLite Duende.Storage.Sqlite AddSqlite A connection string None sqlite Automated tests and local development only

Duende Storage doesn’t recommend any particular database. Choose the database that fits your team’s operations and hosting environment. SQL Server, PostgreSQL and Oracle are all production-ready; SQLite is well-suited for automated tests and local development only.

Every provider follows the same registration shape:

  • AddStorage(...) selects exactly one database provider for a storage instance. Calling it with a second provider for the same instance throws an InvalidOperationException.
  • For SQL Server, PostgreSQL and Oracle, your application owns the connection factory or data source: a CreateSqlConnection or CreateOracleConnection delegate, or an NpgsqlDataSource. You control credentials, token providers and pooling settings on it. Duende Storage never disposes an object you registered this way.
  • The default-instance overloads (for example AddMsSql(Action<MsSqlStorageEngineOptions>)) resolve that object unkeyed from dependency injection, and only work for the default storage instance. Named instances must use the resolver overload (for example AddMsSql(Func<IServiceProvider, CreateSqlConnection> resolver, ...)), which resolves the object however you configure it, including from a keyed registration. See Multiple Storage Instances for how to register and migrate more than one storage instance.

Duende Storage separates two kinds of schema change:

  • Document-level changes, such as adding a custom property to a client or resource, need no migration. The data extension schemas validate documents, not database tables.
  • The fixed set of storage tables (entities, indexes, the outbox, and the schema version itself) is created and upgraded by Duende Storage’s own migrations, through the APIs below.

IStorageInstanceSchema gives you those migration operations for a storage instance:

  • MigrateAsync() creates the schema if it doesn’t exist, upgrades it if it’s behind, or does nothing if it’s already current. It then calls VerifySchemaAsync and throws an InvalidOperationException if verification finds errors.

  • CheckVersionAsync() returns a CheckSchemaVersionResult with CurrentVersion, RequiredVersion and IsCompatible, so you can fail fast before MigrateAsync instead of discovering a mismatch at request time:

    Program.cs
    using Duende.Storage.Schema;
    var schema = app.Services.GetRequiredService<IStorageInstanceSchema>();
    var versionCheck = await schema.CheckVersionAsync(CancellationToken.None);
    if (!versionCheck.IsCompatible)
    {
    throw new InvalidOperationException(
    $"Database schema version {versionCheck.CurrentVersion} does not match the " +
    $"required version {versionCheck.RequiredVersion}.");
    }

    IsCompatible is false when CurrentVersion and RequiredVersion differ. An unreachable database throws an exception rather than returning a result with IsCompatible set to false:

    • CurrentVersion of 0 means the database has never been migrated: run the migration.
    • CurrentVersion less than RequiredVersion means the database is behind: run the migration.
    • CurrentVersion greater than RequiredVersion means a newer version of Duende Storage already migrated the database. Upgrade the application to a version that expects the current schema instead of trying to downgrade the schema.
  • VerifySchemaAsync() checks that every table, index and other object the current schema version expects is present, without changing anything.

  • BuildMigrationScript(DatabaseSchemaVersion fromVersion) returns the SQL for the given starting version without opening a database connection. Pass DatabaseSchemaVersion.Zero for the full script from an empty database.

app.Services.GetRequiredService<IStorageInstanceSchema>() resolves the default storage instance only. For a named instance, resolve IStorageInstanceSchemaFactory and call GetStorageInstanceSchema(storageInstanceId, cancellationToken). The returned schema provides the same migration, version-checking, verification, and script-generation operations for that named instance. See Multiple Storage Instances for a complete registration and migration example.

On SQL Server, PostgreSQL and SQLite, each version step runs inside a transaction, so a failed step rolls back and running the migration again resumes from the last completed version. On Oracle, DDL commits automatically, so a failed step can leave some objects already created; the migration scripts skip objects that already exist, so running the migration again is safe there too. This also applies when a migration fails because another process was migrating the same database at the same time. After migrating, Duende Storage verifies the schema and throws if verification finds a mismatch.

In production, migrate the schema with the Duende CLI, as a single deployment step that runs before your application instances start, for example a pipeline step or a single Kubernetes Job that completes before the application rollout:

  • Grant schema-changing permissions only to that step. Your application doesn’t need them.
  • At application startup, call CheckVersionAsync and wait, or fail readiness, until IsCompatible is true.

If several processes do migrate the same database at the same time, what happens depends on the provider:

Provider Concurrent MigrateAsync calls
SQL Server Serialized with an application lock. Instances wait for each other and skip steps that are already applied. An instance that waits longer than 60 seconds for the lock throws.
PostgreSQL, SQLite Not serialized. One instance completes the migration; the others typically throw (for example, a duplicate schema or column error) and their changes are rolled back.
Oracle Not serialized. Instances can throw lock or concurrent-DDL errors such as ORA-00054, ORA-14411 or ORA-00001. Because the migration scripts skip objects that already exist, running the migration again is safe.

On every provider, a migration that fails because another process migrated at the same time leaves the database in a consistent state, and running the migration again completes it. The cost is a failed startup, not a damaged database, but it is still a failed deployment, which the single CLI step above avoids.

Don’t commit connection strings or store them in plain configuration files. Options that keep secrets out of source control and shell history include:

  • Environment variables, for example ConnectionStrings__IdentityServer, which IConfiguration binds automatically.
  • Azure Key Vault or another vault-backed configuration provider.
  • dotnet user-secrets for local development.
  • A passwordless or managed-identity connection, where the driver supports one, so no password needs to be stored at all.

For the Duende CLI, prefer the DUENDE_STORAGE_CONNECTION_STRING environment variable over --connection-string, so the connection string doesn’t appear in shell history or process listings.

The SQL Server, PostgreSQL and Oracle drivers all pool connections by default and expose pool-sizing keywords on the connection string or connection object you register: Min Pool Size/Max Pool Size for SQL Server, Minimum Pool Size/Maximum Pool Size for PostgreSQL, and Min Pool Size/Max Pool Size for Oracle. Tune these on the connection string; see each provider’s page for the keywords it supports. SQLite is for automated tests and local development only, so connection pooling isn’t a concern there.

Duende Storage logs under categories that start with Duende.Storage. Log filters match by prefix, so you can set a level for all of Duende Storage or for one database provider.

Scope Log category prefix
All of Duende Storage Duende.Storage
SQLite Duende.Storage.Sqlite
SQL Server Duende.Storage.MsSql
PostgreSQL Duende.Storage.PostgreSql
Oracle Duende.Storage.Oracle
appsettings.json
{
"Logging": {
"LogLevel": {
"Duende.Storage.PostgreSql": "Debug"
}
}
}

For general logging setup, see Logging.