Class NpgsqlMultiHostDataSource
An NpgsqlDataSource which manages connections for multiple hosts, is aware of their states (primary, secondary, offline...) and can perform failover and load balancing across them.
Implements
Inherited Members
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlMultiHostDataSource : NpgsqlDataSource, IAsyncDisposable
Remarks
Methods
| Improve this Doc View SourceClearDatabaseStates()
Clears the database state (primary, secondary, offline...) for all data sources managed by this multi-host data source. Can be useful to make Npgsql retry a PostgreSQL instance which was previously detected to be offline.
Declaration
public void ClearDatabaseStates()
Remarks
| Improve this Doc View SourceCreateConnection(TargetSessionAttributes)
Returns a new, unopened connection from this data source.
Declaration
public NpgsqlConnection CreateConnection(TargetSessionAttributes targetSessionAttributes)
Parameters
Type | Name | Description |
---|---|---|
TargetSessionAttributes | targetSessionAttributes | Specifies the server type (e.g. primary, standby). |
Returns
Type | Description |
---|---|
NpgsqlConnection |
Remarks
| Improve this Doc View SourceOpenConnection(TargetSessionAttributes)
Returns a new, opened connection from this data source.
Declaration
public NpgsqlConnection OpenConnection(TargetSessionAttributes targetSessionAttributes)
Parameters
Type | Name | Description |
---|---|---|
TargetSessionAttributes | targetSessionAttributes | Specifies the server type (e.g. primary, standby). |
Returns
Type | Description |
---|---|
NpgsqlConnection |
Remarks
| Improve this Doc View SourceOpenConnectionAsync(TargetSessionAttributes, CancellationToken)
Returns a new, opened connection from this data source.
Declaration
public ValueTask<NpgsqlConnection> OpenConnectionAsync(TargetSessionAttributes targetSessionAttributes, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TargetSessionAttributes | targetSessionAttributes | Specifies the server type (e.g. primary, standby). |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
ValueTask<><NpgsqlConnection> |
Remarks
| Improve this Doc View SourceWithTargetSession(TargetSessionAttributes)
Returns an NpgsqlDataSource that wraps this multi-host one with the given server type.
Declaration
public NpgsqlDataSource WithTargetSession(TargetSessionAttributes targetSessionAttributes)
Parameters
Type | Name | Description |
---|---|---|
TargetSessionAttributes | targetSessionAttributes | Specifies the server type (e.g. primary, standby). |
Returns
Type | Description |
---|---|
NpgsqlDataSource |