# Class TestDecodingConnectionExtensions

Namespace
  Npgsql.Replication

Assembly
  Npgsql.dll

Extension methods to use LogicalReplicationConnection with the test_decoding logical decoding plugin. See https://www.postgresql.org/docs/current/test-decoding.html.

    public static class TestDecodingConnectionExtensions

Inheritance
  object
  TestDecodingConnectionExtensions

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

## Methods

### CreateTestDecodingReplicationSlot(LogicalReplicationConnection, string, bool, LogicalSlotSnapshotInitMode?, bool, CancellationToken)

Creates a TestDecodingReplicationSlot class that wraps a replication slot using the test_decoding logical decoding plugin.

    public static Task<TestDecodingReplicationSlot> CreateTestDecodingReplicationSlot(this LogicalReplicationConnection connection, string slotName, bool temporarySlot = false, LogicalSlotSnapshotInitMode? slotSnapshotInitMode = null, bool twoPhase = false, CancellationToken cancellationToken = default)

#### Parameters

`connection` LogicalReplicationConnection

  The LogicalReplicationConnection to use for creating the replication slot

`slotName` string

  The name of the slot to create. Must be a valid replication slot name (see https://www.postgresql.org/docs/current/warm-standby.html#STREAMING-REPLICATION-SLOTS-MANIPULATION).

`temporarySlot` bool

  true if this replication slot shall be temporary one; otherwise false. Temporary slots are not saved to disk and are automatically dropped on error or when the session has finished.

`slotSnapshotInitMode` LogicalSlotSnapshotInitMode?

  A LogicalSlotSnapshotInitMode to specify what to do with the snapshot created during logical slot initialization. Export, which is also the default, will export the snapshot for use in other sessions. This option can't be used inside a transaction. Use will use the snapshot for the current transaction executing the command. This option must be used in a transaction, and Use must be the first command run in that transaction. Finally, NoExport will just use the snapshot for logical decoding as normal but won't do anything else with it.

`twoPhase` bool

  If true, this logical replication slot supports decoding of two-phase transactions. With this option, two-phase commands like PREPARE TRANSACTION, COMMIT PREPARED and ROLLBACK PREPARED are decoded and transmitted. The transaction will be decoded and transmitted at PREPARE TRANSACTION time. The default is false.

`cancellationToken` CancellationToken

  An optional token to cancel the asynchronous operation. The default value is None.

#### Returns

Task<TestDecodingReplicationSlot>

  A TestDecodingReplicationSlot that wraps the newly-created replication slot.

#### Remarks

See https://www.postgresql.org/docs/current/test-decoding.html for more information.

### StartReplication(LogicalReplicationConnection, TestDecodingReplicationSlot, CancellationToken, TestDecodingOptions?, NpgsqlLogSequenceNumber?)

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. The server can reply with an error, for example if the requested section of the WAL has already been recycled.

    public static IAsyncEnumerable<TestDecodingData> StartReplication(this LogicalReplicationConnection connection, TestDecodingReplicationSlot slot, CancellationToken cancellationToken, TestDecodingOptions? options = null, NpgsqlLogSequenceNumber? walLocation = null)

#### Parameters

`connection` LogicalReplicationConnection

  The LogicalReplicationConnection to use for starting replication

`slot` TestDecodingReplicationSlot

  The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby.

`cancellationToken` CancellationToken

  The token to monitor for stopping the replication.

`options` TestDecodingOptions

  The collection of options passed to the slot's logical decoding plugin.

`walLocation` NpgsqlLogSequenceNumber?

  The WAL location to begin streaming at.

#### Returns

IAsyncEnumerable<TestDecodingData>

  A Task<TResult> representing an IAsyncEnumerable<T> that can be used to stream WAL entries in form of TestDecodingData instances.