Class NpgsqlDbConfiguration
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/UNLISTENsubscriptionssearch_pathchanges viaSET 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
configurationIConfigurationConfiguration root containing an
Npgsqlsection.enableLoggingboolWhether to enable sensitive data logging support in dependent components.
commandTimeoutOverrideint?Optional command timeout override in seconds.
Exceptions
- ArgumentNullException
Thrown when
configurationis 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
ConnectionString
Gets the finalized PostgreSQL connection string.
public string ConnectionString { get; }
Property Value
Database
Gets the configured database name.
public string Database { get; }
Property Value
EnableLogging
Gets a value indicating whether sensitive EF Core logging is enabled.
public bool EnableLogging { get; }
Property Value
MaxPoolSize
Gets the configured maximum connection pool size.
public int MaxPoolSize { get; }
Property Value
PerformanceConfiguration
Gets query performance tracking configuration mapped to monitoring diagnostics format.
public QueryPerformanceConfiguration PerformanceConfiguration { get; }
Property Value
RetryPolicy
Gets retry policy settings used by services.
public RetryPolicyConfiguration RetryPolicy { get; }
Property Value
Schema
Gets the configured schema name.
public string Schema { get; }
Property Value
Settings
Gets the bound raw Npgsql settings.
public NpgsqlSettings Settings { get; }
Property Value
Username
Gets the resolved database username (from env vars or secrets file).
public string? Username { get; }