Table of Contents

Class NpgsqlDbConfiguration

Namespace
FishMMO.Database.Npgsql
Assembly
FishMMO-DB.dll

Encapsulates validated Npgsql database configuration. Responsibility is limited to binding and validating a provided IConfiguration instance.

public sealed class NpgsqlDbConfiguration
Inheritance
NpgsqlDbConfiguration
Inherited Members

Remarks

WARNING — NoResetOnClose = true. This configuration sets NoResetOnClose = true on the Npgsql connection string, which skips DISCARD ALL / RESET ALL when returning connections to the pool. This is a deliberate performance optimization, but it means the following session-level state will NOT be automatically reset:

  • SET LOCAL / SET SESSION / SET ROLE
  • Temporary tables created with CREATE TEMP TABLE
  • Prepared statements via PREPARE / DEALLOCATE
  • Advisory locks acquired at session scope
  • LISTEN / UNLISTEN subscriptions
  • search_path changes via SET search_path

If any future code introduces session-level state, it MUST manually reset that state before returning the connection to the pool, or change NoResetOnClose to false. See the comment on the NoResetOnClose = true line in BuildConnectionString(NpgsqlSettings, string, string) for details on the performance trade-off.

Constructors

NpgsqlDbConfiguration(IConfiguration, bool, int?)

Initializes configuration from a pre-built IConfiguration instance.

public NpgsqlDbConfiguration(IConfiguration configuration, bool enableLogging = false, int? commandTimeoutOverride = null)

Parameters

configuration IConfiguration

Configuration root containing an Npgsql section.

enableLogging bool

Whether to enable sensitive data logging support in dependent components.

commandTimeoutOverride int?

Optional command timeout override in seconds.

Exceptions

ArgumentNullException

Thrown when configuration is null.

DatabaseException

Thrown when required identifiers or numeric settings are invalid.

Properties

CommandTimeout

Gets the configured command timeout in seconds.

public int CommandTimeout { get; }

Property Value

int

ConnectionString

Gets the finalized PostgreSQL connection string.

public string ConnectionString { get; }

Property Value

string

Database

Gets the configured database name.

public string Database { get; }

Property Value

string

EnableLogging

Gets a value indicating whether sensitive EF Core logging is enabled.

public bool EnableLogging { get; }

Property Value

bool

MaxPoolSize

Gets the configured maximum connection pool size.

public int MaxPoolSize { get; }

Property Value

int

PerformanceConfiguration

Gets query performance tracking configuration mapped to monitoring diagnostics format.

public QueryPerformanceConfiguration PerformanceConfiguration { get; }

Property Value

QueryPerformanceConfiguration

RetryPolicy

Gets retry policy settings used by services.

public RetryPolicyConfiguration RetryPolicy { get; }

Property Value

RetryPolicyConfiguration

Schema

Gets the configured schema name.

public string Schema { get; }

Property Value

string

Settings

Gets the bound raw Npgsql settings.

public NpgsqlSettings Settings { get; }

Property Value

NpgsqlSettings

Username

Gets the resolved database username (from env vars or secrets file).

public string? Username { get; }

Property Value

string