### Basic OpenTelemetry Setup for Npgsql Source: https://www.npgsql.org/doc/diagnostics/tracing.html Reference the Npgsql.OpenTelemetry NuGet package and configure the TracerProvider to activate Npgsql tracing. This example also includes a console exporter for viewing trace data. ```csharp using var tracerProvider = Sdk.CreateTracerProviderBuilder() .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("npgsql-tester")) .SetSampler(new AlwaysOnSampler()) // This optional activates tracing for your application, if you trace your own activities: .AddSource("MyApp") // This activates up Npgsql's tracing: .AddNpgsql() // This prints tracing data to the console: .AddConsoleExporter() .Build(); ``` -------------------------------- ### StartReplication Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutputConnectionExtensions.html Instructs the server to start the Logical Streaming Replication Protocol (pgoutput logical decoding plugin), starting at WAL location `walLocation` or at the slot's consistent point if `walLocation` isn't specified. The server can reply with an error, for example if the requested section of the WAL has already been recycled. ```APIDOC ## StartReplication ### Description Instructs the server to start the Logical Streaming Replication Protocol (pgoutput logical decoding plugin), starting at WAL location `walLocation` or at the slot's consistent point if `walLocation` isn't specified. The server can reply with an error, for example if the requested section of the WAL has already been recycled. ### Method Signature ```csharp public static IAsyncEnumerable StartReplication(this LogicalReplicationConnection connection, PgOutputReplicationSlot slot, PgOutputReplicationOptions options, CancellationToken cancellationToken, NpgsqlLogSequenceNumber? walLocation = null) ``` ### Parameters #### Path Parameters * **connection** (LogicalReplicationConnection) - The LogicalReplicationConnection to use for starting replication. * **slot** (PgOutputReplicationSlot) - The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby. * **options** (PgOutputReplicationOptions) - The collection of options passed to the slot's logical decoding plugin. * **cancellationToken** (CancellationToken) - The token to monitor for stopping the replication. * **walLocation** (NpgsqlLogSequenceNumber?) - Optional. The WAL location to begin streaming at. ### Returns IAsyncEnumerable A Task representing an IAsyncEnumerable that can be used to stream WAL entries in form of PgOutputReplicationMessage instances. ``` -------------------------------- ### Start Replication with TestDecodingReplicationSlot Source: https://www.npgsql.org/doc/replication.html Connect to PostgreSQL, open a replication connection, and start consuming messages using the TestDecodingReplicationSlot. Ensure to call SetReplicationStatus to inform the server about processed WAL files. ```csharp await using var conn = new LogicalReplicationConnection("Host=localhost;Username=test;Password=test"); await conn.Open(); var slot = new TestDecodingReplicationSlot("blog_slot"); // The following will loop until the cancellation token is triggered, and will print message types coming from PostgreSQL: var cancellationTokenSource = new CancellationTokenSource(); await foreach (var message in conn.StartReplication(slot, cancellationTokenSource.Token)) { Console.WriteLine($"Message: {message.Data}"); // Always call SetReplicationStatus() or assign LastAppliedLsn and LastFlushedLsn individually // so that Npgsql can inform the server which WAL files can be removed/recycled. conn.SetReplicationStatus(message.WalEnd); } ``` -------------------------------- ### Example Console Log Output Source: https://www.npgsql.org/doc/diagnostics/logging.html This is an example of the console output generated by Npgsql when logging command executions at the Information level. ```text info: Npgsql.Command[2001] Command execution completed (duration=16ms): SELECT 1 ``` -------------------------------- ### Start PgOutput Replication Stream Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutputConnectionExtensions.html Starts streaming logical replication using the pgoutput plugin. Can begin at a specific WAL location or the slot's consistent point. Handles potential server errors like recycled WAL. ```csharp public static IAsyncEnumerable StartReplication(this LogicalReplicationConnection connection, PgOutputReplicationSlot slot, PgOutputReplicationOptions options, CancellationToken cancellationToken, NpgsqlLogSequenceNumber? walLocation = null) ``` -------------------------------- ### NpgsqlLSeg Start Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlLSeg.html Gets or sets the start NpgsqlPoint of the line segment. ```csharp public NpgsqlPoint Start { readonly get; set; } ``` -------------------------------- ### Example Npgsql Metrics Output Source: https://www.npgsql.org/doc/diagnostics/metrics.html This is an example of the output you might see when monitoring Npgsql metrics using `dotnet-counters`. It shows various metrics like bytes read/written, operation duration, and connection counts with dimensions. ```text [Npgsql] db.client.operation.npgsql.bytes_read (By / 1 sec) db.client.connection.pool.name=CustomersDB 1,020 db.client.operation.npgsql.bytes_written (By / 1 sec) db.client.connection.pool.name=CustomersDB 710 db.client.operation.duration (s) db.client.connection.pool.name=CustomersDB,Percentile=50 0.001 db.client.connection.pool.name=CustomersDB,Percentile=95 0.001 db.client.connection.pool.name=CustomersDB,Percentile=99 0.001 db.client.operation.npgsql.executing ({command}) db.client.connection.pool.name=CustomersDB 2 db.client.operation.npgsql.prepared_ratio db.client.connection.pool.name=CustomersDB 0 db.client.connection.max ({connection}) db.client.connection.pool.name=CustomersDB 100 db.client.connection.count ({connection}) db.client.connection.pool.name=CustomersDB,state=idle 3 db.client.connection.pool.name=CustomersDB,state=used 2 ``` -------------------------------- ### NpgsqlCube ToSubset Method Example Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlCube.html Demonstrates how to create a new cube from a subset of dimensions of an existing cube using specified dimension indexes. This can be used to extract single dimensions, remove dimensions, or reorder them. ```csharp var cube = new NpgsqlCube(new[] { 1, 3, 5 }, new[] { 6, 7, 8 }); // '(1,3,5),(6,7,8)' cube.ToSubset(1); // '(3),(7)' cube.ToSubset(2, 1, 0, 0); // '(5,3,1,1),(8,7,6,6)' ``` -------------------------------- ### LogicalReplicationSlot ConsistentPoint Property Source: https://www.npgsql.org/doc/api/Npgsql.Replication.Internal.LogicalReplicationSlot.html Gets the WAL location at which the slot became consistent. This is the earliest location from which streaming can start. ```csharp public NpgsqlLogSequenceNumber ConsistentPoint { get; } ``` -------------------------------- ### StartingRawCopy Event ID Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlEventId.html Represents the event of starting a raw copy operation. ```csharp public const int StartingRawCopy = 40004 ``` -------------------------------- ### BeginPrepareMessage Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutput.Messages.html Represents a Logical Replication Protocol begin prepare message. ```APIDOC ## BeginPrepareMessage ### Description Logical Replication Protocol begin prepare message. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Begin Binary Import Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Begins a binary COPY FROM STDIN operation for high-performance data import. Use this to import data into a PostgreSQL table. ```csharp public NpgsqlBinaryImporter BeginBinaryImport(string copyFromCommand)__ ``` -------------------------------- ### NpgsqlDatabaseInfo Constructor (Protected) Source: https://www.npgsql.org/doc/api/Npgsql.Internal.NpgsqlDatabaseInfo.html Initializes a new instance of the NpgsqlDatabaseInfo class with host, port, database name, and version. ```csharp protected NpgsqlDatabaseInfo(string host, int port, string databaseName, Version version) ``` -------------------------------- ### this[string] Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnectionStringBuilder.html Gets or sets the value associated with the specified key. The keyword parameter is the key of the item to get or set. ```APIDOC ## this[string keyword] ### Description Gets or sets the value associated with the specified key. ### Parameters `keyword` string The key of the item to get or set. ### Property Value object The value associated with the specified key. ``` -------------------------------- ### Start Writing a Row (Synchronous) Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBinaryImporter.html Starts writing a single row. This method must be invoked before writing any columns for the row. ```csharp public void StartRow() ``` -------------------------------- ### Prepare a Command with Multiple Statements Source: https://www.npgsql.org/doc/prepare.html This example shows how to prepare a command containing multiple SQL statements. If the statements are identical, Npgsql will use a single prepared statement for all of them. ```csharp var cmd = new NpgsqlCommand("UPDATE foo SET bar=@bar WHERE baz=@baz; UPDATE foo SET bar=@bar WHERE baz=@baz"); // set parameters. await cmd.PrepareAsync(); ``` -------------------------------- ### Initialize NpgsqlBatchCommand Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatchCommand.html Initializes a new instance of the NpgsqlBatchCommand class with no command text. ```csharp public NpgsqlBatchCommand() ``` -------------------------------- ### Start Writing a Row (Asynchronous) Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBinaryImporter.html Asynchronously starts writing a single row. This method must be invoked before writing any columns for the row. ```csharp public Task StartRowAsync(CancellationToken cancellationToken = default) ``` -------------------------------- ### CopyTo DbBatchCommand Array Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatchCommandCollection.html Copies the elements of the collection to a DbBatchCommand array, starting at a specified index. Requires the destination array and starting index. ```csharp public override void CopyTo(DbBatchCommand[] array, int arrayIndex) ``` -------------------------------- ### Begin Binary Import Async Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Asynchronously begins a binary COPY FROM STDIN operation for high-performance data import. Use this to import data into a PostgreSQL table. ```csharp public Task BeginBinaryImportAsync(string copyFromCommand, CancellationToken cancellationToken = default)__ ``` -------------------------------- ### CopyTo NpgsqlBatchCommand Array Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatchCommandCollection.html Copies the elements of the collection to an NpgsqlBatchCommand array, starting at a specified index. Requires the destination array and starting index. ```csharp public void CopyTo(NpgsqlBatchCommand[] array, int arrayIndex) ``` -------------------------------- ### NpgsqlDataAdapter Constructor with Command Text and Connection String Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataAdapter.html Initializes a new instance of the NpgsqlDataAdapter class with a command text and a connection string. ```csharp public NpgsqlDataAdapter(string selectCommandText, string selectConnectionString)__ ``` -------------------------------- ### Prepare and Execute a Command Source: https://www.npgsql.org/doc/prepare.html This snippet demonstrates the basic usage of preparing a command before execution. Ensure parameter types are set before calling PrepareAsync() if no values are provided initially. ```csharp var cmd = new NpgsqlCommand(...); cmd.Parameters.Add("param", NpgsqlDbType.Integer); await cmd.PrepareAsync(); // Set parameters await cmd.ExecuteNonQueryAsync(); // And so on ``` -------------------------------- ### Get Converter for Writing Value Source: https://www.npgsql.org/doc/api/Npgsql.Internal.PgConverterResolver-1.html Abstract method to get the appropriate converter for writing a value of type T. Implementations should cache returned converters. ```csharp public abstract PgConverterResolution? Get(T? value, PgTypeId? expectedPgTypeId)__ ``` -------------------------------- ### NpgsqlBatchCommand Constructors Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatchCommand.html Initializes a new instance of the NpgsqlBatchCommand class. ```APIDOC ## NpgsqlBatchCommand() ### Description Initializes a new NpgsqlBatchCommand. ### Method Constructor ### Parameters None ``` ```APIDOC ## NpgsqlBatchCommand(string commandText) ### Description Initializes a new NpgsqlBatchCommand. ### Method Constructor ### Parameters #### Path Parameters - **commandText** (string) - Required - The text of the NpgsqlBatchCommand. ``` -------------------------------- ### NpgsqlDatabaseInfo Constructor with Server Version (Protected) Source: https://www.npgsql.org/doc/api/Npgsql.Internal.NpgsqlDatabaseInfo.html Initializes a new instance of the NpgsqlDatabaseInfo class with host, port, database name, version, and server version string. ```csharp protected NpgsqlDatabaseInfo(string host, int port, string databaseName, Version version, string serverVersion) ``` -------------------------------- ### Value Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlParameter.html Gets or sets the value of the parameter. ```APIDOC ## Value ### Description Gets or sets the value of the parameter. ### Property Value object - An object that is the value of the parameter. The default value is null. ``` -------------------------------- ### Initialize NpgsqlCommand with Command Text and Connection Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlCommand.html Initializes a new instance of the NpgsqlCommand class with the text of the query and a NpgsqlConnection. ```csharp public NpgsqlCommand(string? cmdText, NpgsqlConnection? connection) ``` -------------------------------- ### BeginBinaryImport Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Begins a binary COPY FROM STDIN operation for high-performance data import to a PostgreSQL table. ```APIDOC ## BeginBinaryImport(string) ### Description Begins a binary COPY FROM STDIN operation, a high-performance data import mechanism to a PostgreSQL table. ### Method Signature ```csharp public NpgsqlBinaryImporter BeginBinaryImport(string copyFromCommand) ``` ### Parameters #### Path Parameters * `copyFromCommand` (string) - Required - A COPY FROM STDIN SQL command ### Returns * `NpgsqlBinaryImporter` - A NpgsqlBinaryImporter which can be used to write rows and columns ### Remarks See https://www.postgresql.org/docs/current/static/sql-copy.html. ``` -------------------------------- ### Name Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.NpgsqlDatabaseInfo.html Gets the name of the database. ```csharp public string Name { get; } ``` -------------------------------- ### EnableNetworkTypes Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlSlimDataSourceBuilder.html Sets up network mappings for PhysicalAddress, IPAddress, NpgsqlInet, and NpgsqlCidr types to PostgreSQL macaddr, macaddr8, inet, and cidr types. Returns the builder instance for chaining. ```csharp public NpgsqlSlimDataSourceBuilder EnableNetworkTypes() ``` -------------------------------- ### PgTypeId Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.Postgres.Field.html Gets the PgTypeId of the field. ```csharp public PgTypeId PgTypeId { get; init; }__ ``` -------------------------------- ### Show Source: https://www.npgsql.org/doc/api/Npgsql.Replication.ReplicationConnection.html Requests the server to send the current setting of a run-time parameter, similar to the SQL command SHOW. ```APIDOC ## Show(string, CancellationToken) ### Description Requests the server to send the current setting of a run-time parameter. This is similar to the SQL command SHOW. ### Method ```csharp public Task Show(string parameterName, CancellationToken cancellationToken = default) ``` ### Parameters #### Parameters - `parameterName` string - The name of a run-time parameter. Available parameters are documented in https://www.postgresql.org/docs/current/runtime-config.html. - `cancellationToken` CancellationToken - An optional token to cancel the asynchronous operation. The default value is None. ### Returns Task - The current setting of the run-time parameter specified in `parameterName` as string. ``` -------------------------------- ### Name Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.Postgres.Field.html Gets the name of the field. ```csharp public string Name { get; init; }__ ``` -------------------------------- ### Initialize NpgsqlCommand with Command Text Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlCommand.html Initializes a new instance of the NpgsqlCommand class with the text of the query. ```csharp public NpgsqlCommand(string? cmdText) ``` -------------------------------- ### TableOID Source: https://www.npgsql.org/doc/api/Npgsql.Schema.NpgsqlDbColumn.html Gets the OID of the PostgreSQL table of this column. ```APIDOC ## TableOID ### Description The OID of the PostgreSQL table of this column. ### Property Value `uint` ``` -------------------------------- ### Build Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataSourceBuilder.html Builds and returns an NpgsqlDataSource instance that is ready for use. ```csharp public NpgsqlDataSource Build() ``` -------------------------------- ### Initialize NpgsqlBatchCommand with Command Text Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatchCommand.html Initializes a new instance of the NpgsqlBatchCommand class with the specified command text. ```csharp public NpgsqlBatchCommand(string commandText) ``` -------------------------------- ### PostgresType Source: https://www.npgsql.org/doc/api/Npgsql.Schema.NpgsqlDbColumn.html Gets the PostgresType describing the type of this column. ```APIDOC ## PostgresType ### Description The PostgresType describing the type of this column. ### Property Value `PostgresType` ``` -------------------------------- ### NpgsqlTsQuery.Kind Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlTsQuery.html Gets the node kind of the tsquery. ```csharp public NpgsqlTsQuery.NodeKind Kind { get; } ``` -------------------------------- ### NpgsqlDataAdapter Constructor with Command Text and Connection Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataAdapter.html Initializes a new instance of the NpgsqlDataAdapter class with a command text and an NpgsqlConnection. ```csharp public NpgsqlDataAdapter(string selectCommandText, NpgsqlConnection selectConnection)__ ``` -------------------------------- ### Basic Transaction Management Source: https://www.npgsql.org/doc/basic-usage.html Demonstrates how to initiate, execute commands within, and commit a basic transaction using Npgsql. Ensure all commands are executed before committing or rolling back. ```csharp await using var connection = await dataSource.OpenConnectionAsync(); await using var transaction = await connection.BeginTransactionAsync(); await using var command1 = new NpgsqlCommand("...", connection, transaction); await command1.ExecuteNonQueryAsync(); await using var command2 = new NpgsqlCommand("...", connection, transaction); await command2.ExecuteNonQueryAsync(); await transaction.CommitAsync(); ``` -------------------------------- ### Port Property Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Gets the backend server port. ```csharp [Browsable(true)] public int Port { get; } ``` -------------------------------- ### Initialize NpgsqlCommand with Command Text, Connection, and Transaction Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlCommand.html Initializes a new instance of the NpgsqlCommand class with the text of the query, a NpgsqlConnection, and the NpgsqlTransaction. ```csharp public NpgsqlCommand(string? cmdText, NpgsqlConnection? connection, NpgsqlTransaction? transaction) ``` -------------------------------- ### Keys Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnectionStringBuilder.html Gets an ICollection containing the keys of the NpgsqlConnectionStringBuilder. ```APIDOC ## Keys ### Description Gets an ICollection containing the keys of the NpgsqlConnectionStringBuilder. ### Property Value ICollection ``` -------------------------------- ### TypeModifier Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.Postgres.Field.html Gets the type modifier of the field. ```csharp public int TypeModifier { get; init; }__ ``` -------------------------------- ### StartReplication(NpgsqlLogSequenceNumber, CancellationToken, uint) Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationConnection.html Starts streaming WAL for logical replication from a specified WAL location. The server can return errors if the WAL segment has already been recycled. An optional timeline can be specified. ```APIDOC ## StartReplication(NpgsqlLogSequenceNumber, CancellationToken, uint) ### Description Instructs the server to start streaming the WAL for logical replication, starting at WAL location `walLocation`. The server can reply with an error, for example if the requested section of WAL has already been recycled. ### Method `public IAsyncEnumerable StartReplication(NpgsqlLogSequenceNumber walLocation, CancellationToken cancellationToken, uint timeline = 0)` ### Parameters #### Path Parameters - **walLocation** (NpgsqlLogSequenceNumber) - Required - The WAL location to begin streaming at. - **cancellationToken** (CancellationToken) - Required - The token to be used for stopping the replication. - **timeline** (uint) - Optional - Streaming starts on timeline tli. ### Returns #### Success Response - **IAsyncEnumerable** - A Task representing an IAsyncEnumerable that can be used to stream WAL entries in form of XLogDataMessage instances. ### Remarks If the client requests a timeline that's not the latest but is part of the history of the server, the server will stream all the WAL on that timeline starting from the requested start point up to the point where the server switched to another timeline. ``` -------------------------------- ### BeginBinaryImportAsync Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Asynchronously begins a binary COPY FROM STDIN operation for high-performance data import to a PostgreSQL table. ```APIDOC ## BeginBinaryImportAsync(string, CancellationToken) ### Description Begins a binary COPY FROM STDIN operation, a high-performance data import mechanism to a PostgreSQL table. ### Method Signature ```csharp public Task BeginBinaryImportAsync(string copyFromCommand, CancellationToken cancellationToken = default) ``` ### Parameters #### Path Parameters * `copyFromCommand` (string) - Required - A COPY FROM STDIN SQL command * `cancellationToken` (CancellationToken) - Optional - An optional token to cancel the asynchronous operation. The default value is None. ### Returns * `Task` - A NpgsqlBinaryImporter which can be used to write rows and columns ### Remarks See https://www.postgresql.org/docs/current/static/sql-copy.html. ``` -------------------------------- ### PgTypeId Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.PgConverterResolution.html Gets the PgTypeId associated with this resolution. ```APIDOC ## PgTypeId Property ### Description Gets the PgTypeId associated with this resolution. ### Property Value (PgTypeId) - The PgTypeId instance. ``` -------------------------------- ### Converter Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.PgConverterResolution.html Gets the PgConverter associated with this resolution. ```APIDOC ## Converter Property ### Description Gets the PgConverter associated with this resolution. ### Property Value (PgConverter) - The PgConverter instance. ``` -------------------------------- ### Begin Binary Export Async Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Begins a binary COPY TO STDOUT operation for high-performance data export. Use this to export data from a PostgreSQL table. ```csharp public Task BeginBinaryExportAsync(string copyToCommand, CancellationToken cancellationToken = default)__ ``` -------------------------------- ### Start Test Decoding Replication Stream Source: https://www.npgsql.org/doc/api/Npgsql.Replication.TestDecodingConnectionExtensions.html Starts streaming WAL entries for logical replication using the test_decoding plugin. Can begin at a specific WAL location or the slot's consistent point. Handles potential server errors if WAL data has been recycled. ```csharp public static IAsyncEnumerable StartReplication(this LogicalReplicationConnection connection, TestDecodingReplicationSlot slot, CancellationToken cancellationToken, TestDecodingOptions? options = null, NpgsqlLogSequenceNumber? walLocation = null) ``` -------------------------------- ### NpgsqlDataSource.CreateCommand(string?) Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataSource.html Creates a command ready for use against this NpgsqlDataSource. ```APIDOC ## Methods ### CreateCommand(string?) Creates a command ready for use against this NpgsqlDataSource. ```csharp public NpgsqlCommand CreateCommand(string? commandText = null) ``` #### Parameters `commandText` string - An optional SQL for the command. #### Returns NpgsqlCommand ``` -------------------------------- ### StartedTransaction Event ID Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlEventId.html Represents the event of starting a transaction. ```csharp public const int StartedTransaction = 30000 ``` -------------------------------- ### EnableLTree Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlSlimDataSourceBuilder.html Sets up mappings for the PostgreSQL ltree extension types. Returns the builder instance for chaining. ```csharp public NpgsqlSlimDataSourceBuilder EnableLTree() ``` -------------------------------- ### Start Logical Replication with Npgsql Source: https://www.npgsql.org/doc/replication.html Initiate logical replication using Npgsql, consuming messages from a specified slot and publication. ```csharp await using var conn = new LogicalReplicationConnection(""); await conn.Open(); var slot = new PgOutputReplicationSlot("blog_slot"); // The following will loop until the cancellation token is triggered, and will print message types coming from PostgreSQL: var cancellationTokenSource = new CancellationTokenSource(); await foreach (var message in conn.StartReplication( slot, new PgOutputReplicationOptions("blog_pub", 1), cancellationTokenSource.Token)) { Console.WriteLine($"Received message type: {message.GetType().Name}"); // Always call SetReplicationStatus() or assign LastAppliedLsn and LastFlushedLsn individually // so that Npgsql can inform the server which WAL files can be removed/recycled. conn.SetReplicationStatus(message.WalEnd); } ``` -------------------------------- ### NpgsqlTid BlockNumber Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlTid.html Gets the block number of the NpgsqlTid. ```csharp public uint BlockNumber { get; } ``` -------------------------------- ### NpgsqlCircle Radius Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlCircle.html Gets or sets the radius of the circle. ```csharp public double Radius { readonly get; set; } ``` -------------------------------- ### StartReplication(PhysicalReplicationSlot, CancellationToken) Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationConnection.html Starts streaming WAL for physical replication using a specified replication slot. The server streams WAL from the location and timeline ID in the slot. It can return errors if the WAL segment has already been recycled. ```APIDOC ## StartReplication(PhysicalReplicationSlot, CancellationToken) ### Description Instructs the server to start streaming the WAL for physical replication, starting at the WAL location and timeline id specified in `slot`. The server can reply with an error, for example if the requested section of the WAL has already been recycled. ### Method `public IAsyncEnumerable StartReplication(PhysicalReplicationSlot slot, CancellationToken cancellationToken)` ### Parameters #### Path Parameters - **slot** (PhysicalReplicationSlot) - Required - The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby. The `slot` must contain a valid RestartLsn to be used for this overload. - **cancellationToken** (CancellationToken) - Required - The token to be used for stopping the replication. ### Returns #### Success Response - **IAsyncEnumerable** - A Task representing an IAsyncEnumerable that can be used to stream WAL entries in form of XLogDataMessage instances. ### Remarks If the client requests a timeline that's not the latest but is part of the history of the server, the server will stream all the WAL on that timeline starting from the requested start point up to the point where the server switched to another timeline. ``` -------------------------------- ### NpgsqlCidr Address Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlCidr.html Gets the IPAddress component of the NpgsqlCidr. ```csharp public IPAddress Address { get; } ``` -------------------------------- ### StartReplication Source: https://www.npgsql.org/doc/api/Npgsql.Replication.TestDecodingConnectionExtensions.html Starts streaming WAL for logical replication using the test_decoding plugin. This method can begin streaming from a specific WAL location or the slot's consistent point and returns an asynchronous stream of decoded data. ```APIDOC ## StartReplication ### Description Instructs the server to start streaming the WAL for logical replication using the test_decoding logical decoding plugin, starting at WAL location `walLocation` or at the slot's consistent point if `walLocation` isn't specified. ### Method `public static IAsyncEnumerable StartReplication(this LogicalReplicationConnection connection, TestDecodingReplicationSlot slot, CancellationToken cancellationToken, TestDecodingOptions? options = null, NpgsqlLogSequenceNumber? walLocation = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * `connection` (LogicalReplicationConnection) - The LogicalReplicationConnection to use for starting replication. * `slot` (TestDecodingReplicationSlot) - The replication slot that will be updated as replication progresses. * `cancellationToken` (CancellationToken) - The token to monitor for stopping the replication. * `options` (TestDecodingOptions?) - Optional. The collection of options passed to the slot's logical decoding plugin. * `walLocation` (NpgsqlLogSequenceNumber?) - Optional. The WAL location to begin streaming at. ### Returns IAsyncEnumerable - A Task representing an IAsyncEnumerable that can be used to stream WAL entries in form of TestDecodingData instances. ### Remarks See https://www.postgresql.org/docs/current/test-decoding.html for more information. ``` -------------------------------- ### Get Column Name Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutput.ReplicationValue.html Retrieves the name of the specified column. ```csharp public string GetFieldName() ``` -------------------------------- ### NpgsqlDatabaseInfo Constructors Source: https://www.npgsql.org/doc/api/Npgsql.Internal.NpgsqlDatabaseInfo.html Initializes a new instance of the NpgsqlDatabaseInfo class with provided connection details and version information. ```APIDOC ## NpgsqlDatabaseInfo(string, int, string, Version) ### Description Initializes the instance of NpgsqlDatabaseInfo. ### Parameters - **host** (string) - The hostname or IP address of the database. - **port** (int) - The TCP port of the database. - **databaseName** (string) - The database name. - **version** (Version) - The version of the PostgreSQL database. ## NpgsqlDatabaseInfo(string, int, string, Version, string) ### Description Initializes the instance of NpgsqlDatabaseInfo. ### Parameters - **host** (string) - The hostname or IP address of the database. - **port** (int) - The TCP port of the database. - **databaseName** (string) - The database name. - **version** (Version) - The version of the PostgreSQL database. - **serverVersion** (string) - The PostgreSQL version string as returned by the server_version option. ``` -------------------------------- ### RestartLsn Property Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationSlot.html Gets the replication slot's `restart_lsn`. ```APIDOC ## RestartLsn ### Description The replication slot's `restart_lsn`. ### Property Value NpgsqlLogSequenceNumber? ``` -------------------------------- ### PhysicalReplicationSlot RestartLsn Property Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationSlot.html Gets the restart_lsn of the replication slot. ```csharp public NpgsqlLogSequenceNumber? RestartLsn { get; } ``` -------------------------------- ### Prepare Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatch.html Synchronously creates a prepared version of the batch or its commands on the data source. Use to optimize repeated execution of the same batch. ```csharp public override void Prepare()__ ``` -------------------------------- ### Get Schema (No Parameters) Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Returns the supported schema collections. ```csharp public override DataTable GetSchema()__ ``` -------------------------------- ### Begin Raw Binary Copy Async Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Asynchronously begins a raw binary COPY operation (TO STDOUT or FROM STDIN). This method does not implement encoding/decoding and is unsuitable for structured import/export. ```csharp public Task BeginRawBinaryCopyAsync(string copyCommand, CancellationToken cancellationToken = default)__ ``` -------------------------------- ### Initialize PhysicalReplicationConnection with Connection String Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationConnection.html Initializes a new instance of the PhysicalReplicationConnection class with a specified connection string. This allows configuring the connection to the PostgreSQL database. ```csharp public PhysicalReplicationConnection(string? connectionString) ``` -------------------------------- ### RelationMessage RelationId Property Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutput.Messages.RelationMessage.html Gets the unique identifier for the relation. ```csharp public uint RelationId { get; } ``` -------------------------------- ### Host Property Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Gets the backend server host name. ```csharp [Browsable(true)] public string? Host { get; } ``` -------------------------------- ### Begin Raw Binary Copy Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Begins a raw binary COPY operation (TO STDOUT or FROM STDIN). This method does not implement encoding/decoding and is unsuitable for structured import/export. ```csharp public NpgsqlRawCopyStream BeginRawBinaryCopy(string copyCommand)__ ``` -------------------------------- ### SourceVersion Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlParameter.html Gets or sets the DataRowVersion to use when you load Value. ```APIDOC ## SourceVersion ### Description Gets or sets the DataRowVersion to use when you load Value. ### Property Value DataRowVersion - One of the DataRowVersion values. The default is `Current`. ### Exceptions ArgumentException - The property is not set to one of the DataRowVersion values. ``` -------------------------------- ### Initialize NpgsqlCommand Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlCommand.html Initializes a new instance of the NpgsqlCommand class. ```csharp public NpgsqlCommand() ``` -------------------------------- ### PostgresEnumType.Labels Property Source: https://www.npgsql.org/doc/api/Npgsql.PostgresTypes.PostgresEnumType.html Gets the enum's fields (labels). ```APIDOC ## Labels Property ### Description The enum's fields. ### Property Value IReadOnlyList ``` -------------------------------- ### NpgsqlCommand Constructors Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlCommand.html Initializes a new instance of the NpgsqlCommand class with different configurations. ```APIDOC ## NpgsqlCommand() ### Description Initializes a new instance of the NpgsqlCommand class. ### Method Constructor ### Parameters None ## NpgsqlCommand(string? cmdText) ### Description Initializes a new instance of the NpgsqlCommand class with the text of the query. ### Method Constructor ### Parameters #### Path Parameters * **cmdText** (string) - Required - The text of the query. ## NpgsqlCommand(string? cmdText, NpgsqlConnection? connection) ### Description Initializes a new instance of the NpgsqlCommand class with the text of the query and a NpgsqlConnection. ### Method Constructor ### Parameters #### Path Parameters * **cmdText** (string) - Required - The text of the query. * **connection** (NpgsqlConnection) - Required - A NpgsqlConnection that represents the connection to a PostgreSQL server. ## NpgsqlCommand(string? cmdText, NpgsqlConnection? connection, NpgsqlTransaction? transaction) ### Description Initializes a new instance of the NpgsqlCommand class with the text of the query, a NpgsqlConnection, and the NpgsqlTransaction. ### Method Constructor ### Parameters #### Path Parameters * **cmdText** (string) - Required - The text of the query. * **connection** (NpgsqlConnection) - Required - A NpgsqlConnection that represents the connection to a PostgreSQL server. * **transaction** (NpgsqlTransaction) - Required - The NpgsqlTransaction in which the NpgsqlCommand executes. ``` -------------------------------- ### GetValue Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataReader.html Gets the value of the specified column as an instance of object. ```APIDOC ## GetValue(int) ### Description Gets the value of the specified column as an instance of object. ### Method `object GetValue(int ordinal)` ### Parameters #### Path Parameters - **ordinal** (int) - Required - The zero-based column ordinal. ### Returns #### Success Response - **object** - The value of the specified column. ``` -------------------------------- ### NpgsqlBatch Constructors Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatch.html Initializes a new NpgsqlBatch. You can optionally provide a connection and transaction to associate with the batch. ```APIDOC ## NpgsqlBatch(NpgsqlConnection?, NpgsqlTransaction?) ### Description Initializes a new NpgsqlBatch. ### Parameters - **connection** (NpgsqlConnection) - A NpgsqlConnection that represents the connection to a PostgreSQL server. - **transaction** (NpgsqlTransaction) - The NpgsqlTransaction in which the NpgsqlCommand executes. ``` -------------------------------- ### GetString Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataReader.html Gets the value of the specified column as an instance of string. ```APIDOC ## GetString(int) ### Description Gets the value of the specified column as an instance of string. ### Method `string GetString(int ordinal)` ### Parameters #### Path Parameters - **ordinal** (int) - Required - The zero-based column ordinal. ### Returns #### Success Response - **string** - The value of the specified column. ``` -------------------------------- ### Explicitly Prepare and Execute SQL Source: https://www.npgsql.org/doc/prepare.html Demonstrates preparing a SQL statement on a physical connection. Subsequent calls with the same SQL on the same physical connection will reuse the prepared statement. ```csharp await using (var conn = await dataSource.OpenConnectionAsync()) await using (var cmd = new NpgsqlCommand("", conn)) { await cmd.PrepareAsync(); // First time on this physical connection, Npgsql prepares with PostgreSQL await cmd.ExecuteNonQueryAsync(); } await using (var conn = await dataSource.OpenConnectionAsync()) await using (var cmd = new NpgsqlCommand("", conn)) { // We assume the internal connection pool returned the same physical connection used above await cmd.PrepareAsync(); // The connection already has a prepared statement for , this doesn't need to do anything await cmd.ExecuteNonQueryAsync(); } ``` -------------------------------- ### Set Client Encoding Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnectionStringBuilder.html Gets or sets the client_encoding parameter. ```csharp public string? ClientEncoding { get; set; } ``` -------------------------------- ### NpgsqlDataSource.ConnectionString Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataSource.html Gets the connection string of the database represented by this DbDataSource. ```APIDOC ## Properties ### ConnectionString Gets the connection string of the database represented by this DbDataSource. The exact contents of the connection string depend on the specific data source for this connection. ```csharp public override string ConnectionString { get; } ``` #### Property Value string - The connection string of the database represented by this DbDataSource. The exact contents of the connection string depend on the specific data source for this connection. ``` -------------------------------- ### EnableGeometricTypes Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlSlimDataSourceBuilder.html Sets up network mappings for types like NpgsqlPoint and NpgsqlPath to PostgreSQL point, path, etc. Returns the builder instance for chaining. ```csharp public NpgsqlSlimDataSourceBuilder EnableGeometricTypes() ``` -------------------------------- ### NpgsqlDataAdapter Constructor with Select Command Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlDataAdapter.html Initializes a new instance of the NpgsqlDataAdapter class with a specified NpgsqlCommand for selecting data. ```csharp public NpgsqlDataAdapter(NpgsqlCommand selectCommand)__ ``` -------------------------------- ### NpgsqlBatch.Connection Property Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatch.html Gets or sets the NpgsqlConnection used by this DbBatch. ```csharp public NpgsqlConnection? Connection { get; set; } ``` -------------------------------- ### Configure NetTopologySuite with XYM Ordinates and Custom Factory Source: https://www.npgsql.org/doc/types/nts.html Set up GeometryServiceProvider with a custom coordinate sequence factory to handle XYM ordinates globally. Alternatively, specify settings for Npgsql only. ```csharp // Place this at the beginning of your program to use the specified settings everywhere (recommended) GeometryServiceProvider.Instance = new NtsGeometryServices( new DotSpatialAffineCoordinateSequenceFactory(Ordinates.XYM), new PrecisionModel(PrecisionModels.Floating), -1); // Or specify settings for Npgsql only dataSourceBuilder.UseNetTopologySuite.UseNetTopologySuite( new DotSpatialAffineCoordinateSequenceFactory(Ordinates.XYM)); ``` -------------------------------- ### Format Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.SizeContext.html Gets the data format associated with the SizeContext. ```APIDOC ## Format ### Description Gets the data format associated with the SizeContext. ### Property Value DataFormat - The data format. ``` -------------------------------- ### Initialize LogicalReplicationConnection with Connection String Source: https://www.npgsql.org/doc/api/Npgsql.Replication.LogicalReplicationConnection.html Initializes a new instance of the LogicalReplicationConnection class using a provided connection string. ```csharp public LogicalReplicationConnection(string? connectionString) ``` -------------------------------- ### BufferRequirement Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.SizeContext.html Gets the required buffer size for the SizeContext. ```APIDOC ## BufferRequirement ### Description Gets the required buffer size for the SizeContext. ### Property Value Size - The required buffer size. ``` -------------------------------- ### PgConverterResolution PgTypeId Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.PgConverterResolution.html Gets the PgTypeId associated with this resolution. ```csharp public PgTypeId PgTypeId { get; } ``` -------------------------------- ### NpgsqlBatch Constructor Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatch.html Initializes a new instance of the NpgsqlBatch class, optionally with a connection and transaction. ```csharp public NpgsqlBatch(NpgsqlConnection? connection = null, NpgsqlTransaction? transaction = null) ``` -------------------------------- ### PgConverterResolution Converter Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.PgConverterResolution.html Gets the PgConverter associated with this resolution. ```csharp public PgConverter Converter { get; } ``` -------------------------------- ### NpgsqlCube Constructor with Coordinates Array Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlCube.html Creates a zero-volume cube using the provided coordinates. The input array defines the values for all dimensions. ```csharp public NpgsqlCube(IEnumerable coords) ``` -------------------------------- ### BufferRequirements.Write Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.BufferRequirements.html Gets the required size for writing data. ```csharp public Size Write { get; } ``` -------------------------------- ### Prepare() Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlCommand.html Creates a server-side prepared statement on the PostgreSQL server to optimize future executions of this command. ```APIDOC ## Prepare() ### Description Creates a server-side prepared statement on the PostgreSQL server. This will make repeated future executions of this command much faster. ### Method Signature ```csharp public override void Prepare() ``` ``` -------------------------------- ### Initialize NpgsqlParameter with Full Details Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlParameter.html Initializes a new instance of the NpgsqlParameter with comprehensive details including name, type, size, source column, direction, nullability, precision, scale, source version, and value. ```csharp public NpgsqlParameter(string parameterName, NpgsqlDbType parameterType, int size, string? sourceColumn, ParameterDirection direction, bool isNullable, byte precision, byte scale, DataRowVersion sourceVersion, object value) ``` -------------------------------- ### BufferRequirements.Read Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.BufferRequirements.html Gets the required size for reading data. ```csharp public Size Read { get; } ``` -------------------------------- ### StreamStartMessage Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutput.Messages.html Represents a Logical Replication Protocol stream start message. ```APIDOC ## StreamStartMessage ### Description Logical Replication Protocol stream start message. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Setup NodaTime with NpgsqlDataSource Source: https://www.npgsql.org/doc/types/nodatime.html Configure NodaTime support when building an NpgsqlDataSource. This is the recommended approach for Npgsql 7.0 and later. ```csharp var dataSourceBuilder = new NpgsqlDataSourceBuilder(...); dataSourceBuilder.UseNodaTime(); await using var dataSource = dataSourceBuilder.Build(); ``` -------------------------------- ### StartingWait Event ID Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlEventId.html Represents the event of starting a wait period. ```csharp public const int StartingWait = 1300 ``` -------------------------------- ### StartingPhysicalReplication Event ID Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlEventId.html Represents the event of starting physical replication. ```csharp public const int StartingPhysicalReplication = 50003 ``` -------------------------------- ### Example Replication Message Output Source: https://www.npgsql.org/doc/replication.html Illustrates the expected output when receiving different message types during logical replication. ```text Received message type: BeginMessage Received message type: RelationMessage Received message type: InsertMessage Received message type: CommitMessage ``` -------------------------------- ### StartingLogicalReplication Event ID Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlEventId.html Represents the event of starting logical replication. ```csharp public const int StartingLogicalReplication = 50002 ``` -------------------------------- ### NpgsqlPolygon Capacity Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlPolygon.html Gets the initial capacity of the NpgsqlPolygon instance. ```csharp public int Capacity { get; } ``` -------------------------------- ### StartLogicalReplication Source: https://www.npgsql.org/doc/api/Npgsql.Replication.Internal.LogicalReplicationConnectionExtensions.html Starts streaming the Write-Ahead Log (WAL) for logical replication from a specified point or the slot's consistent point. This method is primarily for internal use and plugin development. ```APIDOC ## StartLogicalReplication ### Description Instructs the server to start streaming the WAL for logical replication, starting at WAL location `walLocation` or at the slot's consistent point if `walLocation` isn't specified. The server can reply with an error, for example if the requested section of the WAL has already been recycled. This API is for internal use and for implementing logical replication plugins. ### Method Signature ```csharp public static IAsyncEnumerable StartLogicalReplication(this LogicalReplicationConnection connection, LogicalReplicationSlot slot, CancellationToken cancellationToken, NpgsqlLogSequenceNumber? walLocation = null, IEnumerable>? options = null, bool bypassingStream = false) ``` ### Parameters #### Path Parameters * **connection** (LogicalReplicationConnection) - Required - The LogicalReplicationConnection to use for starting replication. * **slot** (LogicalReplicationSlot) - Required - The replication slot that will be updated as replication progresses. * **cancellationToken** (CancellationToken) - Required - The token to monitor for stopping the replication. * **walLocation** (NpgsqlLogSequenceNumber?) - Optional - The WAL location to begin streaming at. * **options** (IEnumerable>?) - Optional - The collection of options passed to the slot's logical decoding plugin. * **bypassingStream** (bool) - Optional - Whether the plugin will be bypassing Data and reading directly from the buffer. ### Returns IAsyncEnumerable An asynchronous stream of XLogDataMessage objects representing the logical replication data. ``` -------------------------------- ### EnableRecords Method Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlSlimDataSourceBuilder.html Sets up mappings for the PostgreSQL record type as a .NET object[]. Returns the builder instance for chaining. ```csharp public NpgsqlSlimDataSourceBuilder EnableRecords() ``` -------------------------------- ### NpgsqlCircle Y Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlCircle.html Gets or sets the Y-coordinate of the circle's center. ```csharp public double Y { readonly get; set; } ``` -------------------------------- ### BeginRawBinaryCopyAsync Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Asynchronously begins a raw binary COPY operation (TO STDOUT or FROM STDIN) for high-performance data export/import. ```APIDOC ## BeginRawBinaryCopyAsync(string, CancellationToken) ### Description Begins a raw binary COPY operation (TO STDOUT or FROM STDIN), a high-performance data export/import mechanism to a PostgreSQL table. Note that unlike the other COPY API methods, BeginRawBinaryCopyAsync(string, CancellationToken) doesn't implement any encoding/decoding and is unsuitable for structured import/export operation. It is useful mainly for exporting a table as an opaque blob, for the purpose of importing it back later. ### Method Signature ```csharp public Task BeginRawBinaryCopyAsync(string copyCommand, CancellationToken cancellationToken = default) ``` ### Parameters #### Path Parameters * `copyCommand` (string) - Required - A COPY TO STDOUT or COPY FROM STDIN SQL command * `cancellationToken` (CancellationToken) - Optional - An optional token to cancel the asynchronous operation. The default value is None. ### Returns * `Task` - A NpgsqlRawCopyStream that can be used to read or write raw binary data. ### Remarks See https://www.postgresql.org/docs/current/static/sql-copy.html. ``` -------------------------------- ### NpgsqlCidr Netmask Property Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlCidr.html Gets the netmask byte component of the NpgsqlCidr. ```csharp public byte Netmask { get; } ``` -------------------------------- ### PhysicalReplicationSlot RestartTimeline Property Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationSlot.html Gets the timeline ID associated with the restart_lsn. ```csharp public uint? RestartTimeline { get; } ``` -------------------------------- ### Database Property Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnectionStringBuilder.html Sets the PostgreSQL database to connect to. ```csharp public string? Database { get; set; }__ ``` -------------------------------- ### BeginRawBinaryCopy Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnection.html Begins a raw binary COPY operation (TO STDOUT or FROM STDIN) for high-performance data export/import. ```APIDOC ## BeginRawBinaryCopy(string) ### Description Begins a raw binary COPY operation (TO STDOUT or FROM STDIN), a high-performance data export/import mechanism to a PostgreSQL table. Note that unlike the other COPY API methods, BeginRawBinaryCopy(string) doesn't implement any encoding/decoding and is unsuitable for structured import/export operation. It is useful mainly for exporting a table as an opaque blob, for the purpose of importing it back later. ### Method Signature ```csharp public NpgsqlRawCopyStream BeginRawBinaryCopy(string copyCommand) ``` ### Parameters #### Path Parameters * `copyCommand` (string) - Required - A COPY TO STDOUT or COPY FROM STDIN SQL command ### Returns * `NpgsqlRawCopyStream` - A NpgsqlRawCopyStream that can be used to read or write raw binary data. ### Remarks See https://www.postgresql.org/docs/current/static/sql-copy.html. ``` -------------------------------- ### TypeMessage.TypeId Property Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PgOutput.Messages.TypeMessage.html Gets the ID of the data type. This property is read-only. ```csharp public uint TypeId { get; } ``` -------------------------------- ### NpgsqlPath Constructor with Capacity and Open Flag Source: https://www.npgsql.org/doc/api/NpgsqlTypes.NpgsqlPath.html Initializes a new instance of the NpgsqlPath struct with a specified capacity and an open flag. ```csharp public NpgsqlPath(int capacity, bool open) ``` -------------------------------- ### Subrange Property Source: https://www.npgsql.org/doc/api/Npgsql.PostgresTypes.PostgresMultirangeType.html Gets the PostgreSQL data type of the range of this multirange. ```APIDOC ## Subrange ### Description Gets the PostgreSQL data type of the range of this multirange. ### Property Value PostgresRangeType ``` -------------------------------- ### StartReplication Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationConnection.html Initiates WAL streaming for physical replication from a specified WAL location. The server may return an error if the requested WAL section has already been recycled. ```APIDOC ## StartReplication(PhysicalReplicationSlot?, NpgsqlLogSequenceNumber, CancellationToken, uint) Instructs the server to start streaming the WAL for physical replication, starting at WAL location `walLocation`. The server can reply with an error, for example if the requested section of the WAL has already been recycled. ```csharp public IAsyncEnumerable StartReplication(PhysicalReplicationSlot? slot, NpgsqlLogSequenceNumber walLocation, CancellationToken cancellationToken, uint timeline = 0) ``` #### Parameters `slot` PhysicalReplicationSlot The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby. `walLocation` NpgsqlLogSequenceNumber The WAL location to begin streaming at. `cancellationToken` CancellationToken The token to be used for stopping the replication. `timeline` uint Streaming starts on timeline tli. ``` -------------------------------- ### GetService(Type) Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlFactory.html Gets the service object of the specified type from the NpgsqlFactory. ```APIDOC ## Method: GetService(Type serviceType) ### Description Gets the service object of the specified type. ### Parameters #### Path Parameters - **serviceType** (Type) - An object that specifies the type of service object to get. ### Returns object - A service object of type serviceType, or null if there is no service object of type serviceType. ``` -------------------------------- ### Initialize PhysicalReplicationConnection Source: https://www.npgsql.org/doc/api/Npgsql.Replication.PhysicalReplicationConnection.html Initializes a new instance of the PhysicalReplicationConnection class. This constructor does not take any arguments. ```csharp public PhysicalReplicationConnection() ``` -------------------------------- ### NpgsqlBatch.BatchCommands Property Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatch.html Gets the collection of DbBatchCommand objects within the NpgsqlBatch. ```csharp public NpgsqlBatchCommandCollection BatchCommands { get; } ``` -------------------------------- ### Get Stream Source: https://www.npgsql.org/doc/api/Npgsql.Internal.PgReader.html Retrieves a stream for reading a specified number of bytes. ```csharp public Stream GetStream(int? length = null) ``` -------------------------------- ### Prepare Source: https://www.npgsql.org/doc/api/Npgsql.NpgsqlBatch.html Creates a prepared version of the batch or its commands on the data source. ```APIDOC ## Prepare() ### Description Creates a prepared (or compiled) version of the batch, or of each of its commands, on the data source. ### Method Signature ```csharp public override void Prepare() ``` ``` -------------------------------- ### Type Property Source: https://www.npgsql.org/doc/api/Npgsql.Internal.TypeInfoMapping.html Gets or sets the CLR type associated with this mapping. ```csharp public Type Type { get; init; } ```