# Class LogicalReplicationConnectionExtensions

Namespace
  Npgsql.Replication.Internal

Assembly
  Npgsql.dll

This API is for internal use and for implementing logical replication plugins. It is not meant to be consumed in common Npgsql usage scenarios.

    public static class LogicalReplicationConnectionExtensions

Inheritance
  object
  LogicalReplicationConnectionExtensions

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

## Methods

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

This API is for internal use and for implementing logical replication plugins. It is not meant to be consumed in common Npgsql usage scenarios.

    public static Task<ReplicationSlotOptions> CreateLogicalReplicationSlot(this LogicalReplicationConnection connection, string slotName, string outputPlugin, bool isTemporary = 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).

`outputPlugin` string

  The name of the output plugin used for logical decoding (see https://www.postgresql.org/docs/current/logicaldecoding-output-plugin.html).

`isTemporary` 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<ReplicationSlotOptions>

  A Task<TResult> representing a ReplicationSlotOptions class that can be used to initialize instances of ReplicationSlot subclasses.

#### Remarks

Creates a new replication slot and returns information about the newly-created slot.

### StartLogicalReplication(LogicalReplicationConnection, LogicalReplicationSlot, CancellationToken, NpgsqlLogSequenceNumber?, IEnumerable<KeyValuePair<string, string?>>?, bool)

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.

    public static IAsyncEnumerable<XLogDataMessage> StartLogicalReplication(this LogicalReplicationConnection connection, LogicalReplicationSlot slot, CancellationToken cancellationToken, NpgsqlLogSequenceNumber? walLocation = null, IEnumerable<KeyValuePair<string, string?>>? options = null, bool bypassingStream = false)

#### Parameters

`connection` LogicalReplicationConnection

  The LogicalReplicationConnection to use for starting replication

`slot` LogicalReplicationSlot

  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.

`walLocation` NpgsqlLogSequenceNumber?

  The WAL location to begin streaming at.

`options` IEnumerable<KeyValuePair<string, string>>

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

`bypassingStream` bool

  Whether the plugin will be bypassing Data and reading directly from the buffer.

#### Returns

IAsyncEnumerable<XLogDataMessage>

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